1 |
2 |
kdv |
/*
|
2 |
|
|
* syncgen_intf.v
|
3 |
|
|
*
|
4 |
|
|
* Copyright (c) 2007 Koen De Vleeschauwer.
|
5 |
|
|
*
|
6 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
7 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
8 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
9 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
10 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
11 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
12 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
13 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
14 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
15 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
16 |
|
|
* SUCH DAMAGE.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/*
|
20 |
|
|
* syncgen_intf - interface between decoder clock region and video
|
21 |
|
|
* synchronization generator.
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
`include "timescale.v"
|
25 |
|
|
|
26 |
|
|
`undef DEBUG
|
27 |
|
|
//`define DEBUG 1
|
28 |
|
|
|
29 |
|
|
module syncgen_intf
|
30 |
|
|
(clk, clk_en, rst,
|
31 |
|
|
horizontal_size, vertical_size, display_horizontal_size, display_vertical_size,
|
32 |
|
|
syncgen_rst,
|
33 |
|
|
horizontal_resolution, horizontal_sync_start, horizontal_sync_end, horizontal_length,
|
34 |
|
|
vertical_resolution, vertical_sync_start, vertical_sync_end, horizontal_halfline, vertical_length,
|
35 |
|
|
interlaced, clip_display_size, pixel_repetition,
|
36 |
|
|
h_pos, v_pos, pixel_en, h_sync, v_sync, c_sync, h_blank, v_blank);
|
37 |
|
|
|
38 |
|
|
input clk;
|
39 |
|
|
input clk_en;
|
40 |
|
|
input rst;
|
41 |
|
|
|
42 |
|
|
input [13:0]horizontal_size; /* par. 6.2.2.1, par. 6.3.3 */
|
43 |
|
|
input [13:0]vertical_size; /* par. 6.2.2.1, par. 6.3.3 */
|
44 |
|
|
input [13:0]display_horizontal_size; /* par. 6.2.2.4, par. 6.3.6 */
|
45 |
|
|
input [13:0]display_vertical_size; /* par. 6.2.2.4, par. 6.3.6 */
|
46 |
|
|
|
47 |
|
|
input syncgen_rst; /* reset sync generator whenever modeline parameter is changed */
|
48 |
|
|
input [11:0]horizontal_resolution; /* horizontal resolution. number of dots per line */
|
49 |
|
|
input [11:0]horizontal_sync_start; /* the dot the horizontal sync pulse begins. */
|
50 |
|
|
input [11:0]horizontal_sync_end; /* the dot the horizontal sync pulse ends. */
|
51 |
|
|
input [11:0]horizontal_length; /* total horizontal length */
|
52 |
|
|
input [11:0]vertical_resolution; /* vertical resolution. number of visible lines per frame (progressive) or field (interlaced) */
|
53 |
|
|
input [11:0]vertical_sync_start; /* the line number within the frame (progressive) or field (interlaced) the vertical sync pulse begins. */
|
54 |
|
|
input [11:0]vertical_sync_end; /* the line number within the frame (progressive) or field (interlaced) the vertical sync pulse ends. */
|
55 |
|
|
input [11:0]horizontal_halfline; /* the dot the vertical sync begins on odd frames of interlaced video. Not used in progressive mode. */
|
56 |
|
|
input [11:0]vertical_length; /* total number of lines of a vertical frame (progressive) or field (interlaced) */
|
57 |
|
|
input interlaced; /* asserted if interlaced output required. */
|
58 |
|
|
input pixel_repetition; /* asserted if each pixel drawn twice */
|
59 |
|
|
input clip_display_size; /* assert to clip image to (display_horizontal_size, display_vertical_size) */
|
60 |
|
|
|
61 |
|
|
output [11:0]h_pos; /* horizontal position */
|
62 |
|
|
output [11:0]v_pos; /* vertical position */
|
63 |
|
|
output pixel_en; /* pixel enable, asserted when pixel drawn */
|
64 |
|
|
output h_sync; /* horizontal sync */
|
65 |
|
|
output v_sync; /* vertical sync */
|
66 |
|
|
output c_sync; /* complex sync */
|
67 |
|
|
output h_blank; /* horizontal blanking */
|
68 |
|
|
output v_blank; /* vertical blanking */
|
69 |
|
|
|
70 |
|
|
wire dot_syncgen_rst; /* sync generator reset, synchronized to dot_clk */
|
71 |
|
|
wire [13:0]dot_horizontal_size;
|
72 |
|
|
wire [13:0]dot_vertical_size;
|
73 |
|
|
wire [13:0]dot_display_horizontal_size;
|
74 |
|
|
wire [13:0]dot_display_vertical_size;
|
75 |
|
|
wire [11:0]dot_horizontal_resolution;
|
76 |
|
|
wire [11:0]dot_horizontal_sync_start;
|
77 |
|
|
wire [11:0]dot_horizontal_sync_end;
|
78 |
|
|
wire [11:0]dot_horizontal_length;
|
79 |
|
|
wire [11:0]dot_vertical_resolution;
|
80 |
|
|
wire [11:0]dot_vertical_sync_start;
|
81 |
|
|
wire [11:0]dot_vertical_sync_end;
|
82 |
|
|
wire [11:0]dot_horizontal_halfline;
|
83 |
|
|
wire [11:0]dot_vertical_length;
|
84 |
|
|
wire dot_interlaced;
|
85 |
|
|
wire dot_pixel_repetition;
|
86 |
|
|
wire dot_clip_display_size;
|
87 |
|
|
|
88 |
|
|
/*
|
89 |
|
|
* Synchronize sync generator reset signal with dot clock.
|
90 |
|
|
*/
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
sync_reset syncgen_sreset (
|
94 |
|
|
.clk(clk),
|
95 |
|
|
.asyncrst(syncgen_rst),
|
96 |
|
|
.syncrst(dot_syncgen_rst)
|
97 |
|
|
);
|
98 |
|
|
|
99 |
|
|
/*
|
100 |
|
|
* Synchronize video parameters with dot clock
|
101 |
|
|
*/
|
102 |
|
|
|
103 |
|
|
sync_reg #(.width(14)) sync_horizontal_size (
|
104 |
|
|
.clk(clk),
|
105 |
|
|
.rst(rst),
|
106 |
|
|
.asyncreg(horizontal_size),
|
107 |
|
|
.syncreg(dot_horizontal_size)
|
108 |
|
|
);
|
109 |
|
|
|
110 |
|
|
sync_reg #(.width(14)) sync_vertical_size (
|
111 |
|
|
.clk(clk),
|
112 |
|
|
.rst(rst),
|
113 |
|
|
.asyncreg(vertical_size),
|
114 |
|
|
.syncreg(dot_vertical_size)
|
115 |
|
|
);
|
116 |
|
|
|
117 |
|
|
sync_reg #(.width(14)) sync_display_horizontal_size (
|
118 |
|
|
.clk(clk),
|
119 |
|
|
.rst(rst),
|
120 |
|
|
.asyncreg(display_horizontal_size),
|
121 |
|
|
.syncreg(dot_display_horizontal_size)
|
122 |
|
|
);
|
123 |
|
|
|
124 |
|
|
sync_reg #(.width(14)) sync_display_vertical_size (
|
125 |
|
|
.clk(clk),
|
126 |
|
|
.rst(rst),
|
127 |
|
|
.asyncreg(display_vertical_size),
|
128 |
|
|
.syncreg(dot_display_vertical_size)
|
129 |
|
|
);
|
130 |
|
|
|
131 |
|
|
sync_reg #(.width(12)) sync_horizontal_resolution (
|
132 |
|
|
.clk(clk),
|
133 |
|
|
.rst(rst),
|
134 |
|
|
.asyncreg(horizontal_resolution),
|
135 |
|
|
.syncreg(dot_horizontal_resolution)
|
136 |
|
|
);
|
137 |
|
|
|
138 |
|
|
sync_reg #(.width(12)) sync_horizontal_sync_start (
|
139 |
|
|
.clk(clk),
|
140 |
|
|
.rst(rst),
|
141 |
|
|
.asyncreg(horizontal_sync_start),
|
142 |
|
|
.syncreg(dot_horizontal_sync_start)
|
143 |
|
|
);
|
144 |
|
|
|
145 |
|
|
sync_reg #(.width(12)) sync_horizontal_sync_end (
|
146 |
|
|
.clk(clk),
|
147 |
|
|
.rst(rst),
|
148 |
|
|
.asyncreg(horizontal_sync_end),
|
149 |
|
|
.syncreg(dot_horizontal_sync_end)
|
150 |
|
|
);
|
151 |
|
|
|
152 |
|
|
sync_reg #(.width(12)) sync_horizontal_length (
|
153 |
|
|
.clk(clk),
|
154 |
|
|
.rst(rst),
|
155 |
|
|
.asyncreg(horizontal_length),
|
156 |
|
|
.syncreg(dot_horizontal_length)
|
157 |
|
|
);
|
158 |
|
|
|
159 |
|
|
sync_reg #(.width(12)) sync_vertical_resolution (
|
160 |
|
|
.clk(clk),
|
161 |
|
|
.rst(rst),
|
162 |
|
|
.asyncreg(vertical_resolution),
|
163 |
|
|
.syncreg(dot_vertical_resolution)
|
164 |
|
|
);
|
165 |
|
|
|
166 |
|
|
sync_reg #(.width(12)) sync_vertical_sync_start (
|
167 |
|
|
.clk(clk),
|
168 |
|
|
.rst(rst),
|
169 |
|
|
.asyncreg(vertical_sync_start),
|
170 |
|
|
.syncreg(dot_vertical_sync_start)
|
171 |
|
|
);
|
172 |
|
|
|
173 |
|
|
sync_reg #(.width(12)) sync_vertical_sync_end (
|
174 |
|
|
.clk(clk),
|
175 |
|
|
.rst(rst),
|
176 |
|
|
.asyncreg(vertical_sync_end),
|
177 |
|
|
.syncreg(dot_vertical_sync_end)
|
178 |
|
|
);
|
179 |
|
|
|
180 |
|
|
sync_reg #(.width(12)) sync_horizontal_halfline (
|
181 |
|
|
.clk(clk),
|
182 |
|
|
.rst(rst),
|
183 |
|
|
.asyncreg(horizontal_halfline),
|
184 |
|
|
.syncreg(dot_horizontal_halfline)
|
185 |
|
|
);
|
186 |
|
|
|
187 |
|
|
sync_reg #(.width(12)) sync_vertical_length (
|
188 |
|
|
.clk(clk),
|
189 |
|
|
.rst(rst),
|
190 |
|
|
.asyncreg(vertical_length),
|
191 |
|
|
.syncreg(dot_vertical_length)
|
192 |
|
|
);
|
193 |
|
|
|
194 |
|
|
sync_reg #(.width(1)) sync_interlaced (
|
195 |
|
|
.clk(clk),
|
196 |
|
|
.rst(rst),
|
197 |
|
|
.asyncreg(interlaced),
|
198 |
|
|
.syncreg(dot_interlaced)
|
199 |
|
|
);
|
200 |
|
|
|
201 |
|
|
sync_reg #(.width(1)) sync_pixel_repetition (
|
202 |
|
|
.clk(clk),
|
203 |
|
|
.rst(rst),
|
204 |
|
|
.asyncreg(pixel_repetition),
|
205 |
|
|
.syncreg(dot_pixel_repetition)
|
206 |
|
|
);
|
207 |
|
|
|
208 |
|
|
sync_reg #(.width(1)) sync_clip_display_size (
|
209 |
|
|
.clk(clk),
|
210 |
|
|
.rst(rst),
|
211 |
|
|
.asyncreg(clip_display_size),
|
212 |
|
|
.syncreg(dot_clip_display_size)
|
213 |
|
|
);
|
214 |
|
|
|
215 |
|
|
/*
|
216 |
|
|
* Pixel repetition
|
217 |
|
|
*/
|
218 |
|
|
|
219 |
|
|
reg [13:0]syncgen_horizontal_size;
|
220 |
|
|
reg [13:0]syncgen_display_horizontal_size;
|
221 |
|
|
reg [11:0]syncgen_horizontal_resolution;
|
222 |
|
|
reg [11:0]syncgen_horizontal_sync_start;
|
223 |
|
|
reg [11:0]syncgen_horizontal_sync_end;
|
224 |
|
|
reg [11:0]syncgen_horizontal_length;
|
225 |
|
|
reg [11:0]syncgen_horizontal_halfline;
|
226 |
|
|
|
227 |
|
|
always @(posedge clk)
|
228 |
|
|
if (~rst) syncgen_horizontal_size <= 14'b0;
|
229 |
|
|
else if (clk_en) syncgen_horizontal_size <= dot_pixel_repetition ? {dot_horizontal_size[12:0], 1'b0} : dot_horizontal_size;
|
230 |
|
|
else syncgen_horizontal_size <= syncgen_horizontal_size;
|
231 |
|
|
|
232 |
|
|
always @(posedge clk)
|
233 |
|
|
if (~rst) syncgen_display_horizontal_size <= 14'b0;
|
234 |
|
|
else if (clk_en) syncgen_display_horizontal_size <= (dot_pixel_repetition && (dot_display_horizontal_size != 14'd0)) ? {dot_display_horizontal_size[12:0], 1'b1} : dot_display_horizontal_size;
|
235 |
|
|
else syncgen_display_horizontal_size <= syncgen_display_horizontal_size;
|
236 |
|
|
|
237 |
|
|
always @(posedge clk)
|
238 |
|
|
if (~rst) syncgen_horizontal_resolution <= 12'b0;
|
239 |
|
|
else if (clk_en) syncgen_horizontal_resolution <= dot_pixel_repetition ? {dot_horizontal_resolution[10:0], 1'b1} : dot_horizontal_resolution;
|
240 |
|
|
else syncgen_horizontal_resolution <= syncgen_horizontal_resolution;
|
241 |
|
|
|
242 |
|
|
always @(posedge clk)
|
243 |
|
|
if (~rst) syncgen_horizontal_sync_start <= 12'b0;
|
244 |
|
|
else if (clk_en) syncgen_horizontal_sync_start <= dot_pixel_repetition ? {dot_horizontal_sync_start[10:0], 1'b1} : dot_horizontal_sync_start;
|
245 |
|
|
else syncgen_horizontal_sync_start <= syncgen_horizontal_sync_start;
|
246 |
|
|
|
247 |
|
|
always @(posedge clk)
|
248 |
|
|
if (~rst) syncgen_horizontal_sync_end <= 12'b0;
|
249 |
|
|
else if (clk_en) syncgen_horizontal_sync_end <= dot_pixel_repetition ? {dot_horizontal_sync_end[10:0], 1'b1} : dot_horizontal_sync_end;
|
250 |
|
|
else syncgen_horizontal_sync_end <= syncgen_horizontal_sync_end;
|
251 |
|
|
|
252 |
|
|
always @(posedge clk)
|
253 |
|
|
if (~rst) syncgen_horizontal_length <= 12'b0;
|
254 |
|
|
else if (clk_en) syncgen_horizontal_length <= dot_pixel_repetition ? {dot_horizontal_length[10:0], 1'b1} : dot_horizontal_length;
|
255 |
|
|
else syncgen_horizontal_length <= syncgen_horizontal_length;
|
256 |
|
|
|
257 |
|
|
always @(posedge clk)
|
258 |
|
|
if (~rst) syncgen_horizontal_halfline <= 12'b0;
|
259 |
|
|
else if (clk_en) syncgen_horizontal_halfline <= dot_pixel_repetition ? {dot_horizontal_halfline[10:0], 1'b1} : dot_horizontal_halfline;
|
260 |
|
|
else syncgen_horizontal_halfline <= syncgen_horizontal_halfline;
|
261 |
|
|
|
262 |
|
|
/*
|
263 |
|
|
* Synchronisation generator
|
264 |
|
|
*/
|
265 |
|
|
|
266 |
|
|
sync_gen sync_gen (
|
267 |
|
|
.clk(clk),
|
268 |
|
|
.clk_en(clk_en),
|
269 |
|
|
.rst(dot_syncgen_rst),
|
270 |
|
|
.horizontal_size(syncgen_horizontal_size),
|
271 |
|
|
.vertical_size(dot_vertical_size),
|
272 |
|
|
.display_horizontal_size(syncgen_display_horizontal_size),
|
273 |
|
|
.display_vertical_size(dot_display_vertical_size),
|
274 |
|
|
.horizontal_resolution(syncgen_horizontal_resolution),
|
275 |
|
|
.horizontal_sync_start(syncgen_horizontal_sync_start),
|
276 |
|
|
.horizontal_sync_end(syncgen_horizontal_sync_end),
|
277 |
|
|
.horizontal_length(syncgen_horizontal_length),
|
278 |
|
|
.vertical_resolution(dot_vertical_resolution),
|
279 |
|
|
.vertical_sync_start(dot_vertical_sync_start),
|
280 |
|
|
.vertical_sync_end(dot_vertical_sync_end),
|
281 |
|
|
.horizontal_halfline(syncgen_horizontal_halfline),
|
282 |
|
|
.vertical_length(dot_vertical_length),
|
283 |
|
|
.interlaced(dot_interlaced),
|
284 |
|
|
.clip_display_size(dot_clip_display_size),
|
285 |
|
|
.h_pos(h_pos),
|
286 |
|
|
.v_pos(v_pos),
|
287 |
|
|
.pixel_en(pixel_en),
|
288 |
|
|
.h_sync(h_sync),
|
289 |
|
|
.v_sync(v_sync),
|
290 |
|
|
.c_sync(c_sync),
|
291 |
|
|
.h_blank(h_blank),
|
292 |
|
|
.v_blank(v_blank)
|
293 |
|
|
);
|
294 |
|
|
|
295 |
|
|
endmodule
|
296 |
|
|
/* not truncated */
|