OpenCores
URL https://opencores.org/ocsvn/lcd_to_hdmi_output_ip/lcd_to_hdmi_output_ip/trunk

Subversion Repositories lcd_to_hdmi_output_ip

[/] [lcd_to_hdmi_output_ip/] [trunk/] [trunk/] [rtl/] [hdmi_out.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 morgothcre
/*----------------------------------------------------------------------------/
2
/  This IP is an LCD to HDMI interface adapter.                             /
3
/-----------------------------------------------------------------------------/
4
/
5
/ Copyright (C) 2018 Iulian Gheorghiu (morgoth.creator@gmail.com), all right reserved.
6
/
7
/ This IP file is an open source software. Redistribution and use of this IP in
8
/ source and binary forms, with or without modification, are permitted provided
9
/ that the following condition is met:
10
 
11
/ 1. Redistributions of source code must retain the above copyright notice,
12
/    this condition and the following disclaimer.
13
/
14
/ This software is provided by the copyright holder and contributors "AS IS"
15
/ and any warranties related to this software are DISCLAIMED.
16
/ The copyright owner or contributors be NOT LIABLE for any damages caused
17
/ by use of this software.
18
/----------------------------------------------------------------------------*/
19
 
20
`timescale 1ns / 1ps
21
 
22
module hdmi_out #(
23
        parameter PLATFORM = "XILINX_ARTIX_7"/* At this moment is supported only XILINX Artix7 platform. */
24
        )(
25
        input rst,
26
        input clk,
27
        output hdmi_tx_cec,
28
        output hdmi_tx_clk_n,
29
        output hdmi_tx_clk_p,
30
        input hdmi_tx_hpd,
31
        output hdmi_tx_rscl,
32
        inout hdmi_tx_rsda,
33
        output [2:0]hdmi_tx_n,
34
        output [2:0]hdmi_tx_p,
35
 
36
        output lcd_clk_out,
37
        input lcd_h_synk,
38
        input lcd_v_synk,
39
        input [7:0]lcd_r,
40
        input [7:0]lcd_g,
41
        input [7:0]lcd_b,
42
        input lcd_de
43
        );
44
 
45
reg clk_5;/* This is a reference clock divided by 5 (is used to load the data in to OSERDES and pixel clock for LCD IP */
46
 
47
/* The serial data intermediate wire to go to differential output buffer for channel 0 */
48
wire hdmi_tx_p_0;
49
/* The 8 bit wire that represent the XOR/NXOR color symbol for channel 0 */
50
reg hdmi_tx_symbol_0_D0_;
51
reg hdmi_tx_symbol_0_D1_;
52
reg hdmi_tx_symbol_0_D2_;
53
reg hdmi_tx_symbol_0_D3_;
54
reg hdmi_tx_symbol_0_D4_;
55
reg hdmi_tx_symbol_0_D5_;
56
reg hdmi_tx_symbol_0_D6_;
57
reg hdmi_tx_symbol_0_D7_;
58
/* The 10 bit final symbol to feed the OSERDES device for channel 0 */
59
reg hdmi_tx_symbol_0_D0;
60
reg hdmi_tx_symbol_0_D1;
61
reg hdmi_tx_symbol_0_D2;
62
reg hdmi_tx_symbol_0_D3;
63
reg hdmi_tx_symbol_0_D4;
64
reg hdmi_tx_symbol_0_D5;
65
reg hdmi_tx_symbol_0_D6;
66
reg hdmi_tx_symbol_0_D7;
67
reg hdmi_tx_symbol_0_D8;
68
reg hdmi_tx_symbol_0_D9;
69
 
70
/* The serial data intermediate wire to go to differential output buffer for channel 1 */
71
wire hdmi_tx_p_1;
72
/* The 8 bit wire that represent the XOR/NXOR color symbol for channel 1 */
73
reg hdmi_tx_symbol_1_D0_;
74
reg hdmi_tx_symbol_1_D1_;
75
reg hdmi_tx_symbol_1_D2_;
76
reg hdmi_tx_symbol_1_D3_;
77
reg hdmi_tx_symbol_1_D4_;
78
reg hdmi_tx_symbol_1_D5_;
79
reg hdmi_tx_symbol_1_D6_;
80
reg hdmi_tx_symbol_1_D7_;
81
/* The 10 bit final symbol to feed the OSERDES device for channel 1 */
82
reg hdmi_tx_symbol_1_D0;
83
reg hdmi_tx_symbol_1_D1;
84
reg hdmi_tx_symbol_1_D2;
85
reg hdmi_tx_symbol_1_D3;
86
reg hdmi_tx_symbol_1_D4;
87
reg hdmi_tx_symbol_1_D5;
88
reg hdmi_tx_symbol_1_D6;
89
reg hdmi_tx_symbol_1_D7;
90
reg hdmi_tx_symbol_1_D8;
91
reg hdmi_tx_symbol_1_D9;
92
 
93
/* The serial data intermediate wire to go to differential output buffer for channel 2 */
94
wire hdmi_tx_p_2;
95
/* The 8 bit wire that represent the XOR/NXOR color symbol for channel 2 */
96
reg hdmi_tx_symbol_2_D0_;
97
reg hdmi_tx_symbol_2_D1_;
98
reg hdmi_tx_symbol_2_D2_;
99
reg hdmi_tx_symbol_2_D3_;
100
reg hdmi_tx_symbol_2_D4_;
101
reg hdmi_tx_symbol_2_D5_;
102
reg hdmi_tx_symbol_2_D6_;
103
reg hdmi_tx_symbol_2_D7_;
104
/* The 10 bit final symbol to feed the OSERDES device for channel 2 */
105
reg hdmi_tx_symbol_2_D0;
106
reg hdmi_tx_symbol_2_D1;
107
reg hdmi_tx_symbol_2_D2;
108
reg hdmi_tx_symbol_2_D3;
109
reg hdmi_tx_symbol_2_D4;
110
reg hdmi_tx_symbol_2_D5;
111
reg hdmi_tx_symbol_2_D6;
112
reg hdmi_tx_symbol_2_D7;
113
reg hdmi_tx_symbol_2_D8;
114
reg hdmi_tx_symbol_2_D9;
115
/* These three ounters are the symbol bias counter. */
116
reg [3:0]bias_cnt_0;
117
reg [3:0]bias_cnt_1;
118
reg [3:0]bias_cnt_2;
119
 
120
reg [4:0]dedicated_divider_clk_5;
121
assign lcd_clk_out = clk_5;
122
/* Calculate how many one bits are in each color data. */
123
wire [3:0]nr_of_ones_r = lcd_r[0] + lcd_r[1] + lcd_r[2] + lcd_r[3] + lcd_r[4] + lcd_r[5] + lcd_r[6] + lcd_r[7];
124
wire [3:0]nr_of_ones_g = lcd_g[0] + lcd_g[1] + lcd_g[2] + lcd_g[3] + lcd_g[4] + lcd_g[5] + lcd_g[6] + lcd_g[7];
125
wire [3:0]nr_of_ones_b = lcd_b[0] + lcd_b[1] + lcd_b[2] + lcd_b[3] + lcd_b[4] + lcd_b[5] + lcd_b[6] + lcd_b[7];
126
reg [3:0]nr_of_ones_in_last_symbol_0;
127
reg [3:0]nr_of_ones_in_last_symbol_1;
128
reg [3:0]nr_of_ones_in_last_symbol_2;
129
/* Here we calculate how many one bits including XOR/NXOR bit and excluding inverting bit on each chanel symbol.*/
130
wire [3:0]current_symbol_nr_of_ones_0 = hdmi_tx_symbol_0_D0_ + hdmi_tx_symbol_0_D1_ + hdmi_tx_symbol_0_D2_ + hdmi_tx_symbol_0_D3_ + hdmi_tx_symbol_0_D4_ + hdmi_tx_symbol_0_D5_ + hdmi_tx_symbol_0_D6_ + hdmi_tx_symbol_0_D7_ + hdmi_tx_symbol_0_D8;
131
wire [3:0]current_symbol_nr_of_ones_1 = hdmi_tx_symbol_1_D0_ + hdmi_tx_symbol_1_D1_ + hdmi_tx_symbol_1_D2_ + hdmi_tx_symbol_1_D3_ + hdmi_tx_symbol_1_D4_ + hdmi_tx_symbol_1_D5_ + hdmi_tx_symbol_1_D6_ + hdmi_tx_symbol_1_D7_ + hdmi_tx_symbol_1_D8;
132
wire [3:0]current_symbol_nr_of_ones_2 = hdmi_tx_symbol_2_D0_ + hdmi_tx_symbol_2_D1_ + hdmi_tx_symbol_2_D2_ + hdmi_tx_symbol_2_D3_ + hdmi_tx_symbol_2_D4_ + hdmi_tx_symbol_2_D5_ + hdmi_tx_symbol_2_D6_ + hdmi_tx_symbol_2_D7_ + hdmi_tx_symbol_2_D8;
133
/* Initialize mandatory registers in symulation mode. */
134
initial
135
begin
136
        clk_5 <= 'h0;
137
        dedicated_divider_clk_5 <= 5'b00000;
138
end
139
/* Divide the reference clock by 5, the positive edge of this clock is necessary for the OSERDES data load.  */
140
always @ (posedge clk)
141
begin
142
        if(dedicated_divider_clk_5 == 5'b00000)
143
                dedicated_divider_clk_5 <= 5'b00011;
144
        else
145
                dedicated_divider_clk_5 <= {dedicated_divider_clk_5[0], dedicated_divider_clk_5[4:1]};
146
end
147
always @ (posedge clk) clk_5 = dedicated_divider_clk_5[0];
148
/* Here we do XOR,NXOR of bits and inverse of the symbol to do the bias neutral signal.*/
149
always @ (clk)
150
begin
151
        if(nr_of_ones_r < 4 || (nr_of_ones_r == 4 && lcd_r[0] == 1'b0))
152
        begin /* Do the XOR operation of red color bits. */
153
                hdmi_tx_symbol_0_D0_ = lcd_r[0];
154
                hdmi_tx_symbol_0_D1_ = lcd_r[1] ^ hdmi_tx_symbol_0_D0_;
155
                hdmi_tx_symbol_0_D2_ = lcd_r[2] ^ hdmi_tx_symbol_0_D1_;
156
                hdmi_tx_symbol_0_D3_ = lcd_r[3] ^ hdmi_tx_symbol_0_D2_;
157
                hdmi_tx_symbol_0_D4_ = lcd_r[4] ^ hdmi_tx_symbol_0_D3_;
158
                hdmi_tx_symbol_0_D5_ = lcd_r[5] ^ hdmi_tx_symbol_0_D4_;
159
                hdmi_tx_symbol_0_D6_ = lcd_r[6] ^ hdmi_tx_symbol_0_D5_;
160
                hdmi_tx_symbol_0_D7_ = lcd_r[7] ^ hdmi_tx_symbol_0_D6_;
161
                hdmi_tx_symbol_0_D8 = 1'b1; /* Set the eight bit to tell to receiver that this will be an XOR encoded red color symbol. */
162
        end
163
        else if(nr_of_ones_r > 4 || (nr_of_ones_r == 4 && lcd_r[0] == 1'b1))
164
        begin /* Do the NXOR operation of red color bits. */
165
                hdmi_tx_symbol_0_D0_ = lcd_r[0];
166
                hdmi_tx_symbol_0_D1_ = ~(lcd_r[1] ^ hdmi_tx_symbol_0_D0_);
167
                hdmi_tx_symbol_0_D2_ = ~(lcd_r[2] ^ hdmi_tx_symbol_0_D1_);
168
                hdmi_tx_symbol_0_D3_ = ~(lcd_r[3] ^ hdmi_tx_symbol_0_D2_);
169
                hdmi_tx_symbol_0_D4_ = ~(lcd_r[4] ^ hdmi_tx_symbol_0_D3_);
170
                hdmi_tx_symbol_0_D5_ = ~(lcd_r[5] ^ hdmi_tx_symbol_0_D4_);
171
                hdmi_tx_symbol_0_D6_ = ~(lcd_r[6] ^ hdmi_tx_symbol_0_D5_);
172
                hdmi_tx_symbol_0_D7_ = ~(lcd_r[7] ^ hdmi_tx_symbol_0_D6_);
173
                hdmi_tx_symbol_0_D8 = 1'b0; /* Clear the eight bit to tell to receiver that this will be an XOR encoded red color symbol. */
174
        end
175
 
176
        if(nr_of_ones_g < 4 || (nr_of_ones_g == 4 && lcd_g[0] == 1'b0))
177
        begin /* Do the XOR operation of green color bits. */
178
                hdmi_tx_symbol_1_D0_ = lcd_g[0];
179
                hdmi_tx_symbol_1_D1_ = lcd_g[1] ^ hdmi_tx_symbol_1_D0_;
180
                hdmi_tx_symbol_1_D2_ = lcd_g[2] ^ hdmi_tx_symbol_1_D1_;
181
                hdmi_tx_symbol_1_D3_ = lcd_g[3] ^ hdmi_tx_symbol_1_D2_;
182
                hdmi_tx_symbol_1_D4_ = lcd_g[4] ^ hdmi_tx_symbol_1_D3_;
183
                hdmi_tx_symbol_1_D5_ = lcd_g[5] ^ hdmi_tx_symbol_1_D4_;
184
                hdmi_tx_symbol_1_D6_ = lcd_g[6] ^ hdmi_tx_symbol_1_D5_;
185
                hdmi_tx_symbol_1_D7_ = lcd_g[7] ^ hdmi_tx_symbol_1_D6_;
186
                hdmi_tx_symbol_1_D8 = 1'b1; /* Set the eight bit to tell to receiver that this will be an XOR encoded green color symbol. */
187
        end
188
        else if(nr_of_ones_g > 4 || (nr_of_ones_g == 4 && lcd_g[0] == 1'b1))
189
        begin /* Do the NXOR operation of green color bits. */
190
                hdmi_tx_symbol_1_D0_ = lcd_r[0];
191
                hdmi_tx_symbol_1_D1_ = ~(lcd_g[1] ^ hdmi_tx_symbol_1_D0_);
192
                hdmi_tx_symbol_1_D2_ = ~(lcd_g[2] ^ hdmi_tx_symbol_1_D1_);
193
                hdmi_tx_symbol_1_D3_ = ~(lcd_g[3] ^ hdmi_tx_symbol_1_D2_);
194
                hdmi_tx_symbol_1_D4_ = ~(lcd_g[4] ^ hdmi_tx_symbol_1_D3_);
195
                hdmi_tx_symbol_1_D5_ = ~(lcd_g[5] ^ hdmi_tx_symbol_1_D4_);
196
                hdmi_tx_symbol_1_D6_ = ~(lcd_g[6] ^ hdmi_tx_symbol_1_D5_);
197
                hdmi_tx_symbol_1_D7_ = ~(lcd_g[7] ^ hdmi_tx_symbol_1_D6_);
198
                hdmi_tx_symbol_1_D8 = 1'b0; /* Clear the eight bit to tell to receiver that this will be an XOR encoded green color symbol. */
199
        end
200
 
201
        if(nr_of_ones_b < 4 || (nr_of_ones_b == 4 && lcd_b[0] == 1'b0))
202
        begin /* Do the XOR operation of blur color bits. */
203
                hdmi_tx_symbol_2_D0_ = lcd_b[0];
204
                hdmi_tx_symbol_2_D1_ = lcd_b[1] ^ hdmi_tx_symbol_2_D0_;
205
                hdmi_tx_symbol_2_D2_ = lcd_b[2] ^ hdmi_tx_symbol_2_D1_;
206
                hdmi_tx_symbol_2_D3_ = lcd_b[3] ^ hdmi_tx_symbol_2_D2_;
207
                hdmi_tx_symbol_2_D4_ = lcd_b[4] ^ hdmi_tx_symbol_2_D3_;
208
                hdmi_tx_symbol_2_D5_ = lcd_b[5] ^ hdmi_tx_symbol_2_D4_;
209
                hdmi_tx_symbol_2_D6_ = lcd_b[6] ^ hdmi_tx_symbol_2_D5_;
210
                hdmi_tx_symbol_2_D7_ = lcd_b[7] ^ hdmi_tx_symbol_2_D6_;
211
                hdmi_tx_symbol_2_D8 = 1'b1; /* Set the eight bit to tell to receiver that this will be an XOR encoded blue color symbol. */
212
        end
213
        else if(nr_of_ones_b > 4 || (nr_of_ones_b == 4 && lcd_b[0] == 1'b1))
214
        begin /* Do the NXOR operation of blur color bits. */
215
                hdmi_tx_symbol_2_D0_ = lcd_b[0];
216
                hdmi_tx_symbol_2_D1_ = ~(lcd_b[1] ^ hdmi_tx_symbol_2_D0_);
217
                hdmi_tx_symbol_2_D2_ = ~(lcd_b[2] ^ hdmi_tx_symbol_2_D1_);
218
                hdmi_tx_symbol_2_D3_ = ~(lcd_b[3] ^ hdmi_tx_symbol_2_D2_);
219
                hdmi_tx_symbol_2_D4_ = ~(lcd_b[4] ^ hdmi_tx_symbol_2_D3_);
220
                hdmi_tx_symbol_2_D5_ = ~(lcd_b[5] ^ hdmi_tx_symbol_2_D4_);
221
                hdmi_tx_symbol_2_D6_ = ~(lcd_b[6] ^ hdmi_tx_symbol_2_D5_);
222
                hdmi_tx_symbol_2_D7_ = ~(lcd_b[7] ^ hdmi_tx_symbol_2_D6_);
223
                hdmi_tx_symbol_2_D8 = 1'b0; /* Clear the eight bit to tell to receiver that this will be an XOR encoded blue color symbol. */
224
        end
225
        if(lcd_de)
226
        begin /* Here we encode 8 bit colors to 10 bit symbols taking in account the bias value of the last symbol and number of ones in current symbol. */
227
                if((bias_cnt_0[3] == 1'b0 && bias_cnt_0[2:0] && current_symbol_nr_of_ones_0 > 4) || (bias_cnt_0[3] == 1'b1 && current_symbol_nr_of_ones_0 <= 4))
228
                begin
229
                        hdmi_tx_symbol_0_D9 <= 1'b1;/* Send that this symbol is an inverted one on channel 0 setting the nineth bit in the symbol. */
230
                        {hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= ~{hdmi_tx_symbol_0_D7_, hdmi_tx_symbol_0_D6_, hdmi_tx_symbol_0_D5_, hdmi_tx_symbol_0_D4_, hdmi_tx_symbol_0_D3_, hdmi_tx_symbol_0_D2_, hdmi_tx_symbol_0_D1_, hdmi_tx_symbol_0_D0_};
231
                end
232
                else
233
                begin
234
                        hdmi_tx_symbol_0_D9 <= 1'b0;/* Senjd that this symbol is an non inverted one on channel 0 clearing the nineth bit in the symbol. */
235
                        {hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= {hdmi_tx_symbol_0_D7_, hdmi_tx_symbol_0_D6_, hdmi_tx_symbol_0_D5_, hdmi_tx_symbol_0_D4_, hdmi_tx_symbol_0_D3_, hdmi_tx_symbol_0_D2_, hdmi_tx_symbol_0_D1_, hdmi_tx_symbol_0_D0_};
236
                end
237
 
238
                if((bias_cnt_1[3] == 1'b0 && bias_cnt_1[2:0] && current_symbol_nr_of_ones_1 > 4) || (bias_cnt_1[3] == 1'b1 && current_symbol_nr_of_ones_1 <= 4))
239
                begin
240
                        hdmi_tx_symbol_1_D9 <= 1'b1;/* Send that this symbol is an inverted one on channel 1 setting the nineth bit in the symbol. */
241
                        {hdmi_tx_symbol_1_D7, hdmi_tx_symbol_1_D6, hdmi_tx_symbol_1_D5, hdmi_tx_symbol_1_D4, hdmi_tx_symbol_1_D3, hdmi_tx_symbol_1_D2, hdmi_tx_symbol_1_D1, hdmi_tx_symbol_1_D0} <= ~{hdmi_tx_symbol_1_D7_, hdmi_tx_symbol_1_D6_, hdmi_tx_symbol_1_D5_, hdmi_tx_symbol_1_D4_, hdmi_tx_symbol_1_D3_, hdmi_tx_symbol_1_D2_, hdmi_tx_symbol_1_D1_, hdmi_tx_symbol_1_D0_};
242
                end
243
                else
244
                begin
245
                        hdmi_tx_symbol_1_D9 <= 1'b0;/* Senjd that this symbol is an non inverted one on channel 1 clearing the nineth bit in the symbol. */
246
                        {hdmi_tx_symbol_1_D7, hdmi_tx_symbol_1_D6, hdmi_tx_symbol_1_D5, hdmi_tx_symbol_1_D4, hdmi_tx_symbol_1_D3, hdmi_tx_symbol_1_D2, hdmi_tx_symbol_1_D1, hdmi_tx_symbol_1_D0} <= {hdmi_tx_symbol_1_D7_, hdmi_tx_symbol_1_D6_, hdmi_tx_symbol_1_D5_, hdmi_tx_symbol_1_D4_, hdmi_tx_symbol_1_D3_, hdmi_tx_symbol_1_D2_, hdmi_tx_symbol_1_D1_, hdmi_tx_symbol_1_D0_};
247
                end
248
 
249
                if((bias_cnt_2[3] == 1'b0 && bias_cnt_2[2:0] && current_symbol_nr_of_ones_2 > 4) || (bias_cnt_2[3] == 1'b1 && current_symbol_nr_of_ones_2 <= 4))
250
                begin
251
                        hdmi_tx_symbol_2_D9 <= 1'b1;/* Send that this symbol is an inverted one on channel 2 setting the nineth bit in the symbol. */
252
                        {hdmi_tx_symbol_2_D7, hdmi_tx_symbol_2_D6, hdmi_tx_symbol_2_D5, hdmi_tx_symbol_2_D4, hdmi_tx_symbol_2_D3, hdmi_tx_symbol_2_D2, hdmi_tx_symbol_2_D1, hdmi_tx_symbol_2_D0} <= ~{hdmi_tx_symbol_2_D7_, hdmi_tx_symbol_2_D6_, hdmi_tx_symbol_2_D5_, hdmi_tx_symbol_2_D4_, hdmi_tx_symbol_2_D3_, hdmi_tx_symbol_2_D2_, hdmi_tx_symbol_2_D1_, hdmi_tx_symbol_2_D0_};
253
                end
254
                else
255
                begin
256
                        hdmi_tx_symbol_2_D9 <= 1'b0;/* Senjd that this symbol is an non inverted one on channel 2 clearing the nineth bit in the symbol. */
257
                        {hdmi_tx_symbol_2_D7, hdmi_tx_symbol_2_D6, hdmi_tx_symbol_2_D5, hdmi_tx_symbol_2_D4, hdmi_tx_symbol_2_D3, hdmi_tx_symbol_2_D2, hdmi_tx_symbol_2_D1, hdmi_tx_symbol_2_D0} <= {hdmi_tx_symbol_2_D7_, hdmi_tx_symbol_2_D6_, hdmi_tx_symbol_2_D5_, hdmi_tx_symbol_2_D4_, hdmi_tx_symbol_2_D3_, hdmi_tx_symbol_2_D2_, hdmi_tx_symbol_2_D1_, hdmi_tx_symbol_2_D0_};
258
                end
259
        end
260
        else
261
        begin /* Here we encode from 2 bit data (H & V synchronization signals to 10 bit symbols because we are outside of pixel data panel.*/
262
                case({lcd_v_synk, lcd_h_synk})/* Encode the H & V synchronization  signals in to respective 10 bit symbols and send the on channel 0. */
263
                2'b00: {hdmi_tx_symbol_0_D9, hdmi_tx_symbol_0_D8, hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= 10'b1101010100;
264
                2'b01: {hdmi_tx_symbol_0_D9, hdmi_tx_symbol_0_D8, hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= 10'b0010101011;
265
                2'b10: {hdmi_tx_symbol_0_D9, hdmi_tx_symbol_0_D8, hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= 10'b0101010100;
266
                2'b11: {hdmi_tx_symbol_0_D9, hdmi_tx_symbol_0_D8, hdmi_tx_symbol_0_D7, hdmi_tx_symbol_0_D6, hdmi_tx_symbol_0_D5, hdmi_tx_symbol_0_D4, hdmi_tx_symbol_0_D3, hdmi_tx_symbol_0_D2, hdmi_tx_symbol_0_D1, hdmi_tx_symbol_0_D0} <= 10'b1010101011;
267
                endcase
268
                /* Here we send dummy neutral symbols ( The logic control value 2'b00 ), because in this case we do not send control values, we send this symbols on channel 1 & 2.. */
269
                {hdmi_tx_symbol_1_D9, hdmi_tx_symbol_1_D8, hdmi_tx_symbol_1_D7, hdmi_tx_symbol_1_D6, hdmi_tx_symbol_1_D5, hdmi_tx_symbol_1_D4, hdmi_tx_symbol_1_D3, hdmi_tx_symbol_1_D2, hdmi_tx_symbol_1_D1, hdmi_tx_symbol_1_D0} <= 10'b1101010100;
270
                {hdmi_tx_symbol_2_D9, hdmi_tx_symbol_2_D8, hdmi_tx_symbol_2_D7, hdmi_tx_symbol_2_D6, hdmi_tx_symbol_2_D5, hdmi_tx_symbol_2_D4, hdmi_tx_symbol_2_D3, hdmi_tx_symbol_2_D2, hdmi_tx_symbol_2_D1, hdmi_tx_symbol_2_D0} <= 10'b1101010100;
271
        end
272
end
273
/* Here we count the bias. */
274
always @ (posedge clk_5 or posedge rst)
275
begin
276
        if(rst)
277
        begin
278
                bias_cnt_0 <= 'b0;
279
                bias_cnt_1 <= 'b0;
280
                bias_cnt_2 <= 'b0;
281
                nr_of_ones_in_last_symbol_0 = 'h5;
282
                nr_of_ones_in_last_symbol_1 = 'h5;
283
                nr_of_ones_in_last_symbol_2 = 'h5;
284
        end
285
        else
286
        begin
287
                if(lcd_de)
288
                begin /* Here we count the bias only when transmiting the color symbols. */
289
                        nr_of_ones_in_last_symbol_0 = hdmi_tx_symbol_0_D0 + hdmi_tx_symbol_0_D1 + hdmi_tx_symbol_0_D2 + hdmi_tx_symbol_0_D3 + hdmi_tx_symbol_0_D4 + hdmi_tx_symbol_0_D5 + hdmi_tx_symbol_0_D6 + hdmi_tx_symbol_0_D7 + hdmi_tx_symbol_0_D8 + hdmi_tx_symbol_0_D9;
290
                        nr_of_ones_in_last_symbol_1 = hdmi_tx_symbol_1_D0 + hdmi_tx_symbol_1_D1 + hdmi_tx_symbol_1_D2 + hdmi_tx_symbol_1_D3 + hdmi_tx_symbol_1_D4 + hdmi_tx_symbol_1_D5 + hdmi_tx_symbol_1_D6 + hdmi_tx_symbol_1_D7 + hdmi_tx_symbol_1_D8 + hdmi_tx_symbol_1_D9;
291
                        nr_of_ones_in_last_symbol_2 = hdmi_tx_symbol_2_D0 + hdmi_tx_symbol_2_D1 + hdmi_tx_symbol_2_D2 + hdmi_tx_symbol_2_D3 + hdmi_tx_symbol_2_D4 + hdmi_tx_symbol_2_D5 + hdmi_tx_symbol_2_D6 + hdmi_tx_symbol_2_D7 + hdmi_tx_symbol_2_D8 + hdmi_tx_symbol_2_D9;
292
                        if(nr_of_ones_in_last_symbol_0 < 5)
293
                                bias_cnt_0 <= bias_cnt_0 - nr_of_ones_in_last_symbol_0;
294
                        else if(nr_of_ones_in_last_symbol_0 > 5)
295
                                bias_cnt_0 <= bias_cnt_0 + (nr_of_ones_in_last_symbol_0 - 5);
296
                        if(nr_of_ones_in_last_symbol_1 < 5)
297
                                bias_cnt_1 <= bias_cnt_1 - nr_of_ones_in_last_symbol_1;
298
                        else if(nr_of_ones_in_last_symbol_1 > 5)
299
                                bias_cnt_1 <= bias_cnt_1 + (nr_of_ones_in_last_symbol_1 - 5);
300
                        if(nr_of_ones_in_last_symbol_2 < 5)
301
                                bias_cnt_2 <= bias_cnt_2 - nr_of_ones_in_last_symbol_2;
302
                        else if(nr_of_ones_in_last_symbol_2 > 5)
303
                                bias_cnt_2 <= bias_cnt_2 + (nr_of_ones_in_last_symbol_2 - 5);
304
                end
305
                else
306
                begin /* We do not count the bias if no pixel data is transmited, we reset it to a neutral value, because all control symbols has neutral biases. */
307
                        bias_cnt_0 <= 'b0;
308
                        bias_cnt_1 <= 'b0;
309
                        bias_cnt_2 <= 'b0;
310
                end
311
        end
312
end
313
/* This section is platform dependent, contain only the four channel diferential output buffers and output 10 bit SERDES in DDR mode */
314
generate
315
if(PLATFORM == "XILINX_ARTIX_7")
316
begin
317
/* Clock differential buffer */
318
OBUFDS #(
319
        .IOSTANDARD("TMDS_33"), // Specify the output I/O standard
320
        .SLEW("FAST")           // Specify the output slew rate
321
        ) OBUFDS_clk_inst (
322
        .O(hdmi_tx_clk_p),     // Diff_p output (connect directly to top-level port)
323
        .OB(hdmi_tx_clk_n),   // Diff_n output (connect directly to top-level port)
324
        .I(clk_5)      // Buffer input
325
        );
326
 
327
/* Channel 0 differential buffer */
328
OBUFDS #(
329
        .IOSTANDARD("TMDS_33"), // Specify the output I/O standard
330
        .SLEW("FAST")           // Specify the output slew rate
331
        ) OBUFDS_0_inst (
332
        .O(hdmi_tx_p[0]),     // Diff_p output (connect directly to top-level port)
333
        .OB(hdmi_tx_n[0]),   // Diff_n output (connect directly to top-level port)
334
        .I(hdmi_tx_p_0)      // Buffer input
335
        );
336
 
337
/* Channel 1 differential buffer */
338
OBUFDS #(
339
        .IOSTANDARD("TMDS_33"), // Specify the output I/O standard
340
        .SLEW("FAST")           // Specify the output slew rate
341
        ) OBUFDS_1_inst (
342
        .O(hdmi_tx_p[1]),     // Diff_p output (connect directly to top-level port)
343
        .OB(hdmi_tx_n[1]),   // Diff_n output (connect directly to top-level port)
344
        .I(hdmi_tx_p_1)      // Buffer input
345
        );
346
 
347
/* Channel 2 differential buffer */
348
OBUFDS #(
349
        .IOSTANDARD("TMDS_33"), // Specify the output I/O standard
350
        .SLEW("FAST")           // Specify the output slew rate
351
        ) OBUFDS_2_inst (
352
        .O(hdmi_tx_p[2]),     // Diff_p output (connect directly to top-level port)
353
        .OB(hdmi_tx_n[2]),   // Diff_n output (connect directly to top-level port)
354
        .I(hdmi_tx_p_2)      // Buffer input
355
        );
356
 
357
wire OSERDES_SHIFT1_CH0;
358
wire OSERDES_SHIFT2_CH0;
359
wire OSERDES_SHIFT1_CH1;
360
wire OSERDES_SHIFT2_CH1;
361
wire OSERDES_SHIFT1_CH2;
362
wire OSERDES_SHIFT2_CH2;
363
 
364
 
365
/* Channel 0 OSERDES (two phases of 10 bits each) */
366
OSERDESE2 #(
367
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
368
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
369
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
370
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
371
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
372
        .SERDES_MODE("MASTER"), // MASTER, SLAVE
373
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
374
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
375
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
376
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
377
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
378
        ) OSERDESE2_0_LOW_inst (
379
        .OQ(hdmi_tx_p_0),               // 1-bit output: Data path output
380
        .CLK(clk),             // 1-bit input: High speed clock
381
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
382
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
383
        .D1(hdmi_tx_symbol_0_D0),
384
        .D2(hdmi_tx_symbol_0_D1),
385
        .D3(hdmi_tx_symbol_0_D2),
386
        .D4(hdmi_tx_symbol_0_D3),
387
        .D5(hdmi_tx_symbol_0_D4),
388
        .D6(hdmi_tx_symbol_0_D5),
389
        .D7(hdmi_tx_symbol_0_D6),
390
        .D8(hdmi_tx_symbol_0_D7),
391
        .OCE(1'b1),             // 1-bit input: Output data clock enable
392
        .RST(rst),             // 1-bit input: Reset
393
        .SHIFTIN1(OSERDES_SHIFT1_CH0),
394
        .SHIFTIN2(OSERDES_SHIFT2_CH0)
395
        );
396
 
397
OSERDESE2 #(
398
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
399
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
400
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
401
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
402
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
403
        .SERDES_MODE("SLAVE"), // MASTER, SLAVE
404
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
405
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
406
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
407
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
408
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
409
        ) OSERDESE2_0_HIGH_inst (
410
        .SHIFTOUT1(OSERDES_SHIFT1_CH0),
411
        .SHIFTOUT2(OSERDES_SHIFT2_CH0),
412
        .CLK(clk),             // 1-bit input: High speed clock
413
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
414
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
415
        .D3(hdmi_tx_symbol_0_D8),
416
        .D4(hdmi_tx_symbol_0_D9),
417
        .OCE(1'b1),             // 1-bit input: Output data clock enable
418
        .RST(rst)             // 1-bit input: Reset
419
        );
420
 
421
/* Channel 1 OSERDESE2 (two phases of 10 bits each) */
422
OSERDESE2 #(
423
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
424
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
425
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
426
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
427
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
428
        .SERDES_MODE("MASTER"), // MASTER, SLAVE
429
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
430
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
431
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
432
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
433
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
434
        ) OSERDESE2_1_LOW_inst (
435
        .OQ(hdmi_tx_p_1),               // 1-bit output: Data path output
436
        .CLK(clk),             // 1-bit input: High speed clock
437
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
438
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
439
        .D1(hdmi_tx_symbol_1_D0),
440
        .D2(hdmi_tx_symbol_1_D1),
441
        .D3(hdmi_tx_symbol_1_D2),
442
        .D4(hdmi_tx_symbol_1_D3),
443
        .D5(hdmi_tx_symbol_1_D4),
444
        .D6(hdmi_tx_symbol_1_D5),
445
        .D7(hdmi_tx_symbol_1_D6),
446
        .D8(hdmi_tx_symbol_1_D7),
447
        .OCE(1'b1),             // 1-bit input: Output data clock enable
448
        .RST(rst),             // 1-bit input: Reset
449
        .SHIFTIN1(OSERDES_SHIFT1_CH1),
450
        .SHIFTIN2(OSERDES_SHIFT2_CH1)
451
        );
452
 
453
OSERDESE2 #(
454
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
455
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
456
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
457
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
458
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
459
        .SERDES_MODE("SLAVE"), // MASTER, SLAVE
460
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
461
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
462
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
463
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
464
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
465
        ) OSERDESE2_1_HIGH_inst (
466
        .SHIFTOUT1(OSERDES_SHIFT1_CH1),
467
        .SHIFTOUT2(OSERDES_SHIFT2_CH1),
468
        .CLK(clk),             // 1-bit input: High speed clock
469
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
470
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
471
        .D3(hdmi_tx_symbol_1_D8),
472
        .D4(hdmi_tx_symbol_1_D9),
473
        .OCE(1'b1),             // 1-bit input: Output data clock enable
474
        .RST(rst)             // 1-bit input: Reset
475
        );
476
 
477
/* Channel 2 OSERDESE2 (two phases of 10 bits each) */
478
OSERDESE2 #(
479
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
480
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
481
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
482
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
483
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
484
        .SERDES_MODE("MASTER"), // MASTER, SLAVE
485
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
486
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
487
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
488
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
489
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
490
        ) OSERDESE2_2_LOW_inst (
491
        .OQ(hdmi_tx_p_2),               // 1-bit output: Data path output
492
        .CLK(clk),             // 1-bit input: High speed clock
493
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
494
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
495
        .D1(hdmi_tx_symbol_2_D0),
496
        .D2(hdmi_tx_symbol_2_D1),
497
        .D3(hdmi_tx_symbol_2_D2),
498
        .D4(hdmi_tx_symbol_2_D3),
499
        .D5(hdmi_tx_symbol_2_D4),
500
        .D6(hdmi_tx_symbol_2_D5),
501
        .D7(hdmi_tx_symbol_2_D6),
502
        .D8(hdmi_tx_symbol_2_D7),
503
        .OCE(1'b1),             // 1-bit input: Output data clock enable
504
        .RST(rst),             // 1-bit input: Reset
505
        .SHIFTIN1(OSERDES_SHIFT1_CH2),
506
        .SHIFTIN2(OSERDES_SHIFT2_CH2)
507
        );
508
 
509
OSERDESE2 #(
510
        .DATA_RATE_OQ("DDR"),   // DDR, SDR
511
        .DATA_RATE_TQ("SDR"),   // DDR, BUF, SDR
512
        .DATA_WIDTH(10),         // Parallel data width (2-8,10,14)
513
        .INIT_OQ(1'b0),         // Initial value of OQ output (1'b0,1'b1)
514
        .INIT_TQ(1'b0),         // Initial value of TQ output (1'b0,1'b1)
515
        .SERDES_MODE("SLAVE"), // MASTER, SLAVE
516
        .SRVAL_OQ(1'b0),        // OQ output value when SR is used (1'b0,1'b1)
517
        .SRVAL_TQ(1'b0),        // TQ output value when SR is used (1'b0,1'b1)
518
        .TBYTE_CTL("FALSE"),    // Enable tristate byte operation (FALSE, TRUE)
519
        .TBYTE_SRC("FALSE"),    // Tristate byte source (FALSE, TRUE)
520
        .TRISTATE_WIDTH(1)      // 3-state converter width (1,4)
521
        ) OSERDESE2_2_HIGH_inst (
522
        .SHIFTOUT1(OSERDES_SHIFT1_CH2),
523
        .SHIFTOUT2(OSERDES_SHIFT2_CH2),
524
        .CLK(clk),             // 1-bit input: High speed clock
525
        .CLKDIV(clk_5),       // 1-bit input: Divided clock
526
        // D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
527
        .D3(hdmi_tx_symbol_2_D8),
528
        .D4(hdmi_tx_symbol_2_D9),
529
        .OCE(1'b1),             // 1-bit input: Output data clock enable
530
        .RST(rst)             // 1-bit input: Reset
531
        );
532
 
533
end
534
endgenerate
535
 
536
 
537
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.