-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvi_encoder_top_old.v
304 lines (273 loc) · 9.52 KB
/
dvi_encoder_top_old.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//////////////////////////////////////////////////////////////////////////////
//
// Xilinx, Inc. 2009 www.xilinx.com
//
// XAPP xyz
//
//////////////////////////////////////////////////////////////////////////////
//
// File name : dvi_encoder.v
//
// Description : dvi_encoder
//
// Date - revision : April 2009 - 1.0.0
//
// Author : Bob Feng
//
// Disclaimer: LIMITED WARRANTY AND DISCLAMER. These designs are
// provided to you "as is". Xilinx and its licensors makeand you
// receive no warranties or conditions, express, implied,
// statutory or otherwise, and Xilinx specificallydisclaims any
// implied warranties of merchantability, non-infringement,or
// fitness for a particular purpose. Xilinx does notwarrant that
// the functions contained in these designs will meet your
// requirements, or that the operation of these designswill be
// uninterrupted or error free, or that defects in theDesigns
// will be corrected. Furthermore, Xilinx does not warrantor
// make any representations regarding use or the results ofthe
// use of the designs in terms of correctness, accuracy,
// reliability, or otherwise.
//
// LIMITATION OF LIABILITY. In no event will Xilinx or its
// licensors be liable for any loss of data, lost profits,cost
// or procurement of substitute goods or services, or forany
// special, incidental, consequential, or indirect damages
// arising from the use or operation of the designs or
// accompanying documentation, however caused and on anytheory
// of liability. This limitation will apply even if Xilinx
// has been advised of the possibility of such damage. This
// limitation shall apply not-withstanding the failure ofthe
// essential purpose of any limited remedies herein.
//
// Copyright © 2009 Xilinx, Inc.
// All rights reserved
//
//////////////////////////////////////////////////////////////////////////////
// Modifications copyright (c) 2011, Andrew "bunnie" Huang
// All rights reserved as permitted by law.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
`timescale 1 ns / 1ps
module dvi_encoder_top (
input wire pclk, // pixel clock
input wire pclkx2, // pixel clock x2
input wire pclkx10, // pixel clock x2
input wire serdesstrobe, // OSERDES2 serdesstrobe
input wire rstin, // reset
input wire [7:0] blue_din, // Blue data in
input wire [7:0] green_din, // Green data in
input wire [7:0] red_din, // Red data in
input wire hsync, // hsync data
input wire vsync, // vsync data
input wire de, // data enable
output wire [3:0] TMDS,
output wire [3:0] TMDSB,
input wire vid_pa,
input wire vid_gb,
input wire dat_pa,
input wire dat_gb,
input wire dat_ena,
input wire [9:0] dat_din,
input wire [3:0] ctl_code,
input wire [29:0] bypass_sdata,
input wire bypass_ena,
output reg byp_error
);
wire [9:0] red ;
wire [9:0] green ;
wire [9:0] blue ;
wire [9:0] red_t4 ;
wire [9:0] green_t4 ;
wire [9:0] blue_t4 ;
wire [4:0] tmds_data0, tmds_data1, tmds_data2;
wire [2:0] tmdsint;
//
// Forward TMDS Clock Using OSERDES2 block
//
reg [4:0] tmdsclkint = 5'b00000;
reg toggle = 1'b0;
always @ (posedge pclkx2 or posedge rstin) begin
if (rstin)
toggle <= 1'b0;
else
toggle <= ~toggle;
end
always @ (posedge pclkx2) begin
if (toggle)
tmdsclkint <= 5'b11111;
else
tmdsclkint <= 5'b00000;
end
wire tmdsclk;
serdes_n_to_1 #(
.SF (5))
clkout (
.iob_data_out (tmdsclk),
.ioclk (pclkx10),
.serdesstrobe (serdesstrobe),
.gclk (pclkx2),
.reset (rstin),
.datain (tmdsclkint));
OBUFDS TMDS3 (.I(tmdsclk), .O(TMDS[3]), .OB(TMDSB[3])) ;// clock
//
// Forward TMDS Data: 3 channels
//
serdes_n_to_1 #(.SF(5)) oserdes0 (
.ioclk(pclkx10),
.serdesstrobe(serdesstrobe),
.reset(rstin),
.gclk(pclkx2),
.datain(tmds_data0),
.iob_data_out(tmdsint[0])) ;
serdes_n_to_1 #(.SF(5)) oserdes1 (
.ioclk(pclkx10),
.serdesstrobe(serdesstrobe),
.reset(rstin),
.gclk(pclkx2),
.datain(tmds_data1),
.iob_data_out(tmdsint[1])) ;
serdes_n_to_1 #(.SF(5)) oserdes2 (
.ioclk(pclkx10),
.serdesstrobe(serdesstrobe),
.reset(rstin),
.gclk(pclkx2),
.datain(tmds_data2),
.iob_data_out(tmdsint[2])) ;
OBUFDS TMDS0 (.I(tmdsint[0]), .O(TMDS[0]), .OB(TMDSB[0])) ;
OBUFDS TMDS1 (.I(tmdsint[1]), .O(TMDS[1]), .OB(TMDSB[1])) ;
OBUFDS TMDS2 (.I(tmdsint[2]), .O(TMDS[2]), .OB(TMDSB[2])) ;
encodeb encb (
.clkin (pclk),
.rstin (rstin),
.din (blue_din),
.c0 (hsync),
.c1 (vsync),
.de (de),
.dout (blue),
.vid_gb (vid_gb)) ;
encodeg encg (
.clkin (pclk),
.rstin (rstin),
.din (green_din),
.c0 (ctl_code[0]), // bit 0
.c1 (ctl_code[1]), // bit 1
.de (de),
.dout (green),
.vid_gb (vid_gb)) ;
encoder encr (
.clkin (pclk),
.rstin (rstin),
.din (red_din),
.c0 (ctl_code[2]), // bit 2
.c1 (ctl_code[3]), // bit 3
.de (de),
.dout (red),
.vid_gb (vid_gb)) ;
encode_terc4 engb_t4
( .clkin (pclk),
.rstin (rstin),
.din ( {dat_din[9] | dat_gb, dat_din[8] | dat_gb, vsync, hsync} ),
.dout (blue_t4),
.dat_gb (1'b0) // gb is considered with sync
);
encode_terc4 encg_t4
( .clkin (pclk),
.rstin (rstin),
.din (dat_din[3:0]),
.dout (green_t4),
.dat_gb (dat_gb)
);
encode_terc4 encr_t4
( .clkin (pclk),
.rstin (rstin),
.din (dat_din[7:4]),
.dout (red_t4),
.dat_gb (dat_gb)
);
// pipe alignment
reg dat_ena_q, dat_ena_reg, dat_ena_r2;
reg dat_gb_q, dat_gb_reg, dat_gb_r2;
always @(posedge pclk or posedge rstin) begin
if( rstin ) begin
dat_ena_q <= 1'b0;
dat_ena_reg <= 1'b0;
dat_ena_r2 <= 1'b0;
dat_gb_q <= 1'b0;
dat_gb_reg <= 1'b0;
dat_gb_r2 <= 1'b0;
end else begin
dat_ena_q <= dat_ena;
dat_ena_reg <= dat_ena_q;
dat_ena_r2 <= dat_ena_reg;
dat_gb_q <= dat_gb;
dat_gb_reg <= dat_gb_q;
dat_gb_r2 <= dat_gb_reg;
end
end
// insert four pipe stages to s_data override
reg [29:0] byp_sd1;
reg [29:0] byp_sd2;
reg [29:0] byp_sd3;
reg [29:0] byp_sd4;
reg [29:0] byp_sd5;
always @(posedge pclk or posedge rstin) begin
if( rstin ) begin
byp_sd1 <= 30'b0;
byp_sd2 <= 30'b0;
byp_sd3 <= 30'b0;
byp_sd4 <= 30'b0;
byp_sd5 <= 30'b0;
end else begin
byp_sd1 <= bypass_sdata;
byp_sd2 <= byp_sd1;
byp_sd3 <= byp_sd2;
byp_sd4 <= byp_sd3;
byp_sd5 <= byp_sd4;
end // else: !if( rstin )
end // always @ (posedge pclk or posedge rstin)
// wire [29:0] s_data_x = (dat_ena_r2 | dat_gb_r2) ?
// {red_t4[9:5], green_t4[9:5], blue_t4[9:5],
// red_t4[4:0], green_t4[4:0], blue_t4[4:0]} :
// {red[9:5], green[9:5], blue[9:5],
// red[4:0], green[4:0], blue[4:0]};
// this destroys our ability to bypass sound, but fixes the problem
// where HDMI data of Red = 0x55, Green = 0x55, blue = anything
// causes the stream to flip into TERC4 mode
wire [29:0] s_data_x = {red[9:5], green[9:5], blue[9:5],
red[4:0], green[4:0], blue[4:0]};
// was bypass_ena in here...
wire [29:0] s_data = s_data_x;
always @(posedge pclk or posedge rstin) begin
if( rstin ) begin
byp_error <= 1'b0;
end else begin
byp_error <= byp_sd5 != s_data_x;
end
end
convert_30to15_fifo pixel2x (
.rst (rstin),
.clk (pclk),
.clkx2 (pclkx2),
.datain (s_data),
.dataout ({tmds_data2, tmds_data1, tmds_data0}));
endmodule