OpenCores
URL https://opencores.org/ocsvn/mjpeg-decoder/mjpeg-decoder/trunk

Subversion Repositories mjpeg-decoder

[/] [mjpeg-decoder/] [trunk/] [mjpeg/] [pcores/] [myipif/] [hdl/] [vhdl/] [vga.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 smanz
---------------------------------------------------------------
2
-- This code is a simplified port from the Verilog sources that can be found here:
3
-- http://embedded.olin.edu/xilinx_docs/projects/bitvga-v2p.php
4
-- The Verilog sources are based on code from Xilinx and released under 
5
-- "Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License"
6
-- with the note, that Xilinx claims the following copyright:
7
--  XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
8
--  SOLELY FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR
9
--  XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION
10
--  AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION
11
--  OR STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS
12
--  IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
13
--  AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
14
--  FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY
15
--  WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
16
--  IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
17
--  REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
18
--  INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19
--  FOR A PARTICULAR PURPOSE.  
20
-- 
21
--  (c) Copyright 2004 Xilinx, Inc.
22
--  All rights reserved.
23
---------------------------------------------------------------
24
 
25
 
26
 
27
------------------------------
28
-- Suffix vga for 25MHz-clock-domain 
29
------------------------------
30
 
31
library ieee;
32
use ieee.std_logic_1164.all;
33
use ieee.std_logic_arith.all;
34
use ieee.std_logic_unsigned.all;
35
 
36
 
37
 
38
entity vga is
39
        generic(
40
                MAX_LINE_COUNT : integer := 479
41
        );
42
        port(
43
                Clk                     : in std_logic;
44
                reset_i         : in std_logic;
45
                eoi_i                   : in std_logic;
46
 
47
                red_i           : in STD_LOGIC_VECTOR (7 downto 0);
48
                green_i         : in  STD_LOGIC_VECTOR (7 downto 0);
49
                blue_i          : in  STD_LOGIC_VECTOR (7 downto 0);
50
                width_i         : in  std_logic_vector(15 downto 0);
51
                height_i                : in  std_logic_vector(15 downto 0);
52
                sampling_i      : in  std_logic_vector( 1 downto 0);
53
 
54
                VGA_OUT_PIXEL_CLOCK:    out STD_LOGIC;
55
                VGA_COMP_SYNCH:                         out STD_LOGIC;
56
                VGA_OUT_BLANK_Z:                        out STD_LOGIC;
57
                VGA_HSYNCH:                             out STD_LOGIC;
58
                VGA_VSYNCH:                             out STD_LOGIC;
59
                VGA_OUT_RED:                            out STD_LOGIC_VECTOR (7 downto 0);
60
                VGA_OUT_GREEN:                  out STD_LOGIC_VECTOR (7 downto 0);
61
                VGA_OUT_BLUE:                           out STD_LOGIC_VECTOR (7 downto 0);
62
 
63
--              -- chipscope-debugging
64
--              chipscope_o     : out std_logic_vector(127 downto 0);
65
 
66
                -- flow controll
67
                datavalid_i :  in std_logic;
68
                ready_o         : out std_logic
69
        );
70
end entity vga;
71
 
72
 
73
 
74
 
75
 
76
architecture IMP of vga is
77
 
78
 
79
------------------------------------------------------------
80
-- VGA output
81
------------------------------------------------------------
82
  component vga_signals is
83
        port (
84
                SYSTEM_CLOCK:     in STD_LOGIC;
85
 
86
                VGA_OUT_PIXEL_CLOCK: out STD_LOGIC;
87
                VGA_COMP_SYNCH: out STD_LOGIC;
88
                VGA_OUT_BLANK_Z: out STD_LOGIC;
89
                VGA_HSYNCH: out STD_LOGIC;
90
                VGA_VSYNCH: out STD_LOGIC;
91
 
92
                o_pixel_clock: out STD_LOGIC;
93
                o_pixel_count: out STD_LOGIC_VECTOR (10 downto 0);
94
                o_line_count:  out STD_LOGIC_VECTOR (9 downto 0)
95
        );
96
  end component vga_signals;
97
------------------------------------------------------------ 
98
 
99
 
100
 
101
 
102
 
103
------------------------------------------------------------ 
104
-- VGA Memory Buffer
105
------------------------------------------------------------ 
106
        component vga_memory
107
                port (
108
                clka: IN std_logic;
109
                dina: IN std_logic_VECTOR(7 downto 0);
110
                addra: IN std_logic_VECTOR(14 downto 0);
111
                wea: IN std_logic_VECTOR(0 downto 0);
112
                clkb: IN std_logic;
113
                addrb: IN std_logic_VECTOR(14 downto 0);
114
                doutb: OUT std_logic_VECTOR(7 downto 0));
115
        end component;
116
------------------------------------------------------------ 
117
 
118
 
119
 
120
 
121
 
122
        -- Clock domain crossing
123
        signal eoi, vga_eoi, vga_eoi_D : std_logic :='0';                                                                                                                -- opb-Clk -> vga-clk
124
        signal reset, vga_reset, vga_reset_D : std_logic :='0';                                                                                          -- opb-Clk -> vga-clk
125
        signal reset_hold, reset_hold_D : std_logic_vector(3 downto 0) :=(others=>'0');
126
        signal width, vga_width, vga_width_D : std_logic_vector(15 downto 0) :=(others=>'0');             -- opb-Clk -> vga-clk
127
        signal height, vga_height, vga_height_D : std_logic_vector(15 downto 0) :=(others=>'0');  -- opb-Clk -> vga-clk
128
        signal sampling, vga_sampling, vga_sampling_D : std_logic_vector(1 downto 0) := (others=>'0');                    -- opb-Clk -> vga-clk
129
        signal vga_pixel_count : std_logic_vector(10 downto 0) := (others=>'0');  -- vga-clk -> OPB-clk
130
        signal line_count,  line_count_D,  vga_line_count  : std_logic_vector(9 downto 0) := (others=>'0');       -- vga-clk -> OPB-clk
131
 
132
        signal memory_select, memory_select_D : std_logic :='0';                                                                                         -- vga-clk -> OPB-clk
133
        signal vga_memory_select, vga_memory_select_D : std_logic :='0';
134
 
135
        signal vga_out_of_picture, vga_out_of_picture_D : std_logic :='0';
136
 
137
        signal blocks_per_line, blocks_per_line_D : std_logic_vector(7 downto 0);                                                -- opb-Clk -> vga-clk
138
        signal vga_blocks_per_line, vga_blocks_per_line_D : std_logic_vector(7 downto 0);
139
 
140
        -- OPB-Clk 
141
        signal stop_writing, stop_writing_D : std_logic :='1';
142
        signal ready, ready_D : std_logic :='0';
143
        signal last_memory_select, last_memory_select_D : std_logic :='0';
144
        signal memory_addra, memory_addra_D : std_logic_vector(13 downto 0) :=(others=>'0');
145
        signal memory_addra_final : std_logic_vector(14 downto 0) :=(others=>'0');
146
 
147
        -- vga-clk
148
        signal vga_pixel_clock : std_logic :='0';
149
        signal vga_out_blank_z_intern : std_logic :='0';
150
        signal vga_memory_red, vga_memory_green, vga_memory_blue : std_logic_vector(7 downto 0) :=(others=>'0');
151
        signal vga_memory_addrb, vga_memory_addrb_D : std_logic_vector(13 downto 0) :=(others=>'0');
152
        signal vga_memory_addrb_final : std_logic_vector(14 downto 0) :=(others=>'0');
153
        signal vga_last_line_count, vga_last_line_count_D : std_logic :='0';
154
 
155
 
156
 
157
begin
158
 
159
 
160
 
161
-- **********************************************************************************************
162
-- * Wires
163
-- **********************************************************************************************
164
--chipscope_o   <= red_i & green_i & blue_i & sampling_i & eoi_i & reset_i & datavalid_i & '0' & ready & vga_out_of_picture &
165
--                                      vga_memory_red & vga_memory_green & vga_memory_blue & vga_out_blank_z_intern & (vga_out_blank_z_intern and not vga_out_of_picture and not vga_reset) & "000000" &
166
--                                      X"0" & blocks_per_line & memory_addra_final & vga_memory_addrb_final &
167
--                                      "0" & vga_pixel_count & vga_line_count;
168
 
169
--VGA_OUT_RED   <= vga_memory_red;
170
--VGA_OUT_GREEN <= memory_addra_final(14 downto 7);
171
--VGA_OUT_BLUE  <= vga_memory_addrb(7 downto 0);
172
VGA_OUT_RED     <= vga_memory_red;
173
VGA_OUT_GREEN   <= vga_memory_green;
174
VGA_OUT_BLUE    <= vga_memory_blue;
175
 
176
VGA_OUT_BLANK_Z <= vga_out_blank_z_intern and not vga_out_of_picture and not vga_reset;
177
 
178
eoi             <= eoi_i;
179
width   <= width_i;
180
height  <= height_i;
181
sampling        <= sampling_i;
182
ready_o <= ready;
183
reset           <= reset_i;
184
 
185
 
186
 
187
 
188
 
189
-- **********************************************************************************************
190
-- * OPB-Clk domain (100 MHz)
191
-- **********************************************************************************************
192
-- to control writing
193
process(line_count, eoi, stop_writing, height)
194
begin
195
        stop_writing_D <= stop_writing;
196
        if (line_count=0) then
197
                stop_writing_D <= '0';
198
        end if;
199
        if (line_count= MAX_LINE_COUNT or line_count=height-1) then             -- maybe height-1
200
                stop_writing_D <='1';
201
        end if;
202
end process;
203
process(Clk)
204
begin
205
        if rising_edge(Clk) then
206
                if (reset='1' or eoi='1') then
207
                        stop_writing <= '1';
208
                else
209
                        stop_writing <= stop_writing_D;
210
                end if;
211
        end if;
212
end process;
213
 
214
 
215
--------------------------------------------------------------
216
-- Calc blocks per line - this is necessary because jpeg fills
217
-- the picture on the right (and bottom) side to have a width 
218
-- (and height) that is a multiple of 8
219
--------------------------------------------------------------
220
process(width, sampling)
221
begin
222
        case sampling is
223
 
224
        when "01" | "10" =>                                                                                             -- 4:2:2 and 4:2:0
225
                if width(3 downto 0)="0000" then
226
                        blocks_per_line_D <= width(11 downto 4);
227
                else
228
                        blocks_per_line_D <= width(11 downto 4) + 1;
229
                end if;
230
 
231
        when others =>                                                                                                          -- 4:4:4 and gray
232
                if width(2 downto 0)="000" then
233
                        blocks_per_line_D <= width(10 downto 3);
234
                else
235
                        blocks_per_line_D <= width(10 downto 3) + 1;
236
                end if;
237
 
238
        end case;
239
end process;
240
 
241
process(Clk)
242
begin
243
        if rising_edge(Clk) then
244
                blocks_per_line <= blocks_per_line_D;
245
        end if;
246
end process;
247
--------------------------------------------------------------
248
 
249
 
250
--------------------------------------------------------------
251
-- Calc the write-address for vga_memory
252
--------------------------------------------------------------
253
 
254
process(memory_addra, datavalid_i, ready, memory_select, last_memory_select)
255
begin
256
        last_memory_select_D <= memory_select;
257
        memory_addra_D <= memory_addra;
258
 
259
        if(memory_select /= last_memory_select) then
260
                memory_addra_D <= (others=>'0');
261
        elsif (datavalid_i='1' and ready='1') then
262
                memory_addra_D <= memory_addra + 1;
263
        end if;
264
end process;
265
 
266
process(Clk)
267
begin
268
        if rising_edge(Clk) then
269
                last_memory_select <= last_memory_select_D;
270
                if reset='1' or eoi='1' then
271
                        memory_addra <= (others=>'0');
272
                else
273
                        memory_addra <= memory_addra_D;
274
                end if;
275
        end if;
276
end process;
277
--------------------------------------------------------------
278
 
279
--------------------------------------------------------------
280
-- calc vga-ready
281
--------------------------------------------------------------
282
process(memory_addra, ready, blocks_per_line, sampling, stop_writing)
283
begin
284
        ready_D <= ready;
285
 
286
        case sampling is
287
        when "01" =>
288
                if( (memory_addra = (blocks_per_line & "00000000") ) or
289
                         (stop_writing='1') ) then
290
                        ready_D <= '0';
291
                end if;
292
        when "10" =>
293
                if( (memory_addra = (blocks_per_line & "0000000") ) or
294
                         (stop_writing='1') ) then
295
                        ready_D <= '0';
296
                end if;
297
        when others =>
298
                if( (memory_addra = (blocks_per_line & "000000") ) or
299
                         (stop_writing='1') ) then
300
                        ready_D <= '0';
301
                end if;
302
        end case;
303
 
304
        if(memory_addra = 0 and stop_writing='0') then
305
                ready_D <= '1';
306
        end if;
307
end process;
308
 
309
process(Clk)
310
begin
311
        if rising_edge(Clk) then
312
                if reset='1' or eoi='1'then
313
                        ready <= '0';
314
                else
315
                        ready <= ready_D;
316
                end if;
317
        end if;
318
end process;
319
--------------------------------------------------------------
320
 
321
 
322
 
323
 
324
 
325
 
326
 
327
-- **********************************************************************************************
328
-- * Clock Domain Crossing
329
-- **********************************************************************************************
330
 
331
------------------------------------------------------------
332
-- Dual port bram for data   (opb-clk -> vga-clk)
333
------------------------------------------------------------
334
vga_memory_red_p:vga_memory
335
        port map (
336
                clka    => Clk,
337
                dina    => red_i,
338
                addra   => memory_addra_final,
339
                wea(0)=> datavalid_i,
340
                clkb    => vga_pixel_clock,
341
                addrb   => vga_memory_addrb_final,
342
                doutb   => vga_memory_red
343
        );
344
vga_memory_green_p:vga_memory
345
        port map (
346
                clka    => Clk,
347
                dina    => green_i,
348
                addra   => memory_addra_final,
349
                wea(0)=> datavalid_i,
350
                clkb    => vga_pixel_clock,
351
                addrb   => vga_memory_addrb_final,
352
                doutb   => vga_memory_green
353
        );
354
vga_memory_blue_p:vga_memory
355
        port map (
356
                clka    => Clk,
357
                dina    => blue_i,
358
                addra   => memory_addra_final,
359
                wea(0)=> datavalid_i,
360
                clkb    => vga_pixel_clock,
361
                addrb   => vga_memory_addrb_final,
362
                doutb   => vga_memory_blue
363
        );
364
 
365
memory_addra_final        <=     memory_select          & (memory_addra);
366
vga_memory_addrb_final <= not vga_memory_select & vga_memory_addrb;
367
------------------------------------------------------------
368
 
369
 
370
 
371
------------------------------------------------------------
372
-- vga-clk -> opb-clk
373
------------------------------------------------------------
374
process(Clk)
375
begin
376
        if rising_edge(Clk) then
377
 
378
                line_count_D                    <= vga_line_count;
379
                line_count                              <= line_count_D;
380
 
381
                memory_select_D         <= vga_memory_select;
382
                memory_select                   <= memory_select_D;
383
 
384
        end if;
385
end process;
386
------------------------------------------------------------
387
 
388
 
389
 
390
------------------------------------------------------------
391
-- opb-clk -> vga-clk
392
------------------------------------------------------------
393
process(vga_pixel_clock)
394
begin
395
        if rising_edge(Clk) then
396
 
397
                vga_sampling_D  <= sampling;
398
                vga_sampling    <= vga_sampling_D;
399
 
400
                vga_width_D     <= width;
401
                vga_width       <= vga_width_D;
402
 
403
                vga_height_D<= height;
404
                vga_height      <= vga_height_D;
405
 
406
        end if;
407
end process;
408
------------------------------------------------------------
409
 
410
 
411
 
412
 
413
 
414
 
415
 
416
 
417
-- **********************************************************************************************
418
-- * VGA-Clock-Domain (25 MHz)
419
-- **********************************************************************************************
420
 
421
------------------------------------------------------------
422
-- Generate VGA-Signals and VGA-Clock
423
------------------------------------------------------------
424
vgacard:vga_signals
425
        Port map (
426
                SYSTEM_CLOCK                    => Clk,
427
 
428
                VGA_OUT_PIXEL_CLOCK     => VGA_OUT_PIXEL_CLOCK,
429
                VGA_COMP_SYNCH          => VGA_COMP_SYNCH,
430
                VGA_OUT_BLANK_Z                 => vga_out_blank_z_intern,
431
                VGA_HSYNCH                              => VGA_HSYNCH,
432
                VGA_VSYNCH                              => VGA_VSYNCH,
433
                o_pixel_clock                   => vga_pixel_clock,
434
                o_pixel_count                   => vga_pixel_count,
435
                o_line_count                    => vga_line_count
436
        );
437
------------------------------------------------------------
438
 
439
--------------------------------------------------------------
440
-- is VGA-Coordinate "outside of the picture"?
441
--------------------------------------------------------------
442
process(vga_pixel_count, vga_line_count, vga_height, vga_width)
443
begin
444
        if( (vga_pixel_count-1 >= vga_width) or (vga_line_count-16 >= vga_height) ) then                                        -- TODO
445
                vga_out_of_picture_D <= '1';
446
        else
447
                vga_out_of_picture_D <= '0';
448
        end if;
449
end process;
450
 
451
process(vga_pixel_clock)
452
begin
453
        if rising_edge(vga_pixel_clock) then
454
                vga_out_of_picture <= vga_out_of_picture_D;
455
        end if;
456
end process;
457
--------------------------------------------------------------
458
 
459
 
460
--------------------------------------------------------------
461
-- Calc the read-address for vga_memory 
462
--------------------------------------------------------------
463
process(vga_memory_addrb, vga_memory_select, vga_pixel_count, vga_line_count, vga_sampling)
464
begin
465
 
466
        vga_last_line_count_D <= vga_line_count(0);
467
        vga_memory_select_D <= vga_memory_select;
468
        vga_memory_addrb_D      <= vga_memory_addrb;
469
 
470
        case vga_sampling is
471
        when "01" =>            -- 4:2:0
472
                if ( vga_line_count(3 downto 0) = "0000" and vga_last_line_count /= vga_line_count(0)) then
473
                        vga_memory_select_D     <= not vga_memory_select;
474
                        vga_memory_addrb_D      <= (others=>'0');
475
                elsif (vga_last_line_count /= vga_line_count(0)) then
476
                        vga_memory_addrb_D      <= "000000" & (vga_line_count(3 downto 0)) & "0000";
477
                elsif ( vga_pixel_count(3 downto 0)="0000" ) then
478
                        vga_memory_addrb_D      <= vga_memory_addrb + 241;
479
                else
480
                        vga_memory_addrb_D      <= vga_memory_addrb + 1;
481
                end if;
482
        when "10" =>            -- 4:2:2
483
                if ( vga_line_count(2 downto 0) = "000" and vga_last_line_count /= vga_line_count(0)) then
484
                        vga_memory_select_D     <= not vga_memory_select;
485
                        vga_memory_addrb_D      <= (others=>'0');
486
                elsif (vga_last_line_count /= vga_line_count(0)) then
487
                        vga_memory_addrb_D      <= "0000000" & (vga_line_count(2 downto 0)) & "0000";
488
                elsif ( vga_pixel_count(3 downto 0)="0000" ) then
489
                        vga_memory_addrb_D      <= vga_memory_addrb + 113;
490
                else
491
                        vga_memory_addrb_D      <= vga_memory_addrb + 1;
492
                end if;
493
        when others=>           -- gray or 4:4:4
494
                if ( vga_line_count(2 downto 0) = "000" and vga_last_line_count /= vga_line_count(0)) then
495
                        vga_memory_select_D     <= not vga_memory_select;
496
                        vga_memory_addrb_D      <= (others=>'0');
497
                elsif (vga_last_line_count /= vga_line_count(0)) then
498
                        vga_memory_addrb_D      <= "00000000" & (vga_line_count(2 downto 0)) & "000";
499
                elsif ( vga_pixel_count(2 downto 0)="000" ) then
500
                        vga_memory_addrb_D      <= vga_memory_addrb + 57;
501
                else
502
                        vga_memory_addrb_D      <= vga_memory_addrb + 1;
503
                end if;
504
        end case;
505
 
506
end process;
507
 
508
process(vga_pixel_clock)
509
begin
510
        if rising_edge(vga_pixel_clock) then
511
                        vga_last_line_count <= vga_last_line_count_D;
512
                        vga_memory_select       <= vga_memory_select_D;
513
                        vga_memory_addrb        <= vga_memory_addrb_D;
514
        end if;
515
end process;
516
--------------------------------------------------------------
517
 
518
 
519
 
520
end IMP;

powered by: WebSVN 2.1.0

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