1 |
2 |
dimamali |
------------------------------------------------------------------------------
|
2 |
|
|
-- This file is a part of the GRLIB VHDL IP LIBRARY
|
3 |
|
|
-- Copyright (C) 2003, Gaisler Research
|
4 |
|
|
--
|
5 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
6 |
|
|
-- it under the terms of the GNU General Public License as published by
|
7 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
8 |
|
|
-- (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- This program is distributed in the hope that it will be useful,
|
11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
-- GNU General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU General Public License
|
16 |
|
|
-- along with this program; if not, write to the Free Software
|
17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
-----------------------------------------------------------------------------
|
19 |
|
|
-- Entity: Vga Controller
|
20 |
|
|
-- File: vga_controller.vhd
|
21 |
|
|
-- Author: Hans Soderlund
|
22 |
|
|
-- Description: Vga Controller main file
|
23 |
|
|
-----------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
library ieee;
|
26 |
|
|
use ieee.std_logic_1164.all;
|
27 |
|
|
library grlib;
|
28 |
|
|
use grlib.amba.all;
|
29 |
|
|
use grlib.stdlib.all;
|
30 |
|
|
use grlib.devices.all;
|
31 |
|
|
library techmap;
|
32 |
|
|
use techmap.gencomp.all;
|
33 |
|
|
library gaisler;
|
34 |
|
|
use gaisler.misc.all;
|
35 |
|
|
|
36 |
|
|
entity svgactrl is
|
37 |
|
|
|
38 |
|
|
generic(
|
39 |
|
|
length : integer := 384; -- Fifo-length
|
40 |
|
|
part : integer := 128; -- Fifo-part lenght
|
41 |
|
|
memtech : integer := DEFMEMTECH;
|
42 |
|
|
pindex : integer := 0;
|
43 |
|
|
paddr : integer := 0;
|
44 |
|
|
pmask : integer := 16#fff#;
|
45 |
|
|
hindex : integer := 0;
|
46 |
|
|
hirq : integer := 0;
|
47 |
|
|
clk0 : integer := 40000;
|
48 |
|
|
clk1 : integer := 20000;
|
49 |
|
|
clk2 : integer := 15385;
|
50 |
|
|
clk3 : integer := 0;
|
51 |
|
|
burstlen : integer range 2 to 8 := 8
|
52 |
|
|
);
|
53 |
|
|
|
54 |
|
|
port (
|
55 |
|
|
rst : in std_logic;
|
56 |
|
|
clk : in std_logic;
|
57 |
|
|
vgaclk : in std_logic;
|
58 |
|
|
apbi : in apb_slv_in_type;
|
59 |
|
|
apbo : out apb_slv_out_type;
|
60 |
|
|
vgao : out apbvga_out_type;
|
61 |
|
|
ahbi : in ahb_mst_in_type;
|
62 |
|
|
ahbo : out ahb_mst_out_type;
|
63 |
|
|
clk_sel : out std_logic_vector(1 downto 0)
|
64 |
|
|
);
|
65 |
|
|
|
66 |
|
|
end ;
|
67 |
|
|
|
68 |
|
|
architecture rtl of svgactrl is
|
69 |
|
|
|
70 |
|
|
constant REVISION : amba_version_type := 0;
|
71 |
|
|
constant pconfig : apb_config_type := (
|
72 |
|
|
|
73 |
|
|
1 => apb_iobar(paddr, pmask));
|
74 |
|
|
|
75 |
|
|
type RegisterType is array (1 to 5) of std_logic_vector(31 downto 0);
|
76 |
|
|
type state_type is (running, not_running, reset);
|
77 |
|
|
|
78 |
|
|
type read_type is record
|
79 |
|
|
read_pointer : integer range 0 to length ;
|
80 |
|
|
read_pointer_out : integer range 0 to length ;
|
81 |
|
|
sync : std_logic_vector(2 downto 0);
|
82 |
|
|
data_out : std_logic_vector(23 downto 0);
|
83 |
|
|
lock : std_logic;
|
84 |
|
|
index : std_logic_vector(1 downto 0);
|
85 |
|
|
mem_index : integer;
|
86 |
|
|
read_pointer_clut : std_logic_vector(7 downto 0);
|
87 |
|
|
hcounter : std_logic_vector(15 downto 0);
|
88 |
|
|
vcounter : std_logic_vector(15 downto 0);
|
89 |
|
|
fifo_ren : std_logic;
|
90 |
|
|
fifo_en : std_logic;
|
91 |
|
|
hsync : std_logic ;
|
92 |
|
|
vsync : std_logic ;
|
93 |
|
|
csync : std_logic ;
|
94 |
|
|
blank : std_logic ;
|
95 |
|
|
hsync2 : std_logic ;
|
96 |
|
|
vsync2 : std_logic ;
|
97 |
|
|
csync2 : std_logic ;
|
98 |
|
|
blank2 : std_logic ;
|
99 |
|
|
end record;
|
100 |
|
|
|
101 |
|
|
type control_type is record
|
102 |
|
|
int_reg : RegisterType;
|
103 |
|
|
state : state_type;
|
104 |
|
|
enable : std_logic;
|
105 |
|
|
reset : std_logic;
|
106 |
|
|
sync_c : std_logic_vector(2 downto 0);
|
107 |
|
|
sync_w : std_logic_vector(2 downto 0);
|
108 |
|
|
write_pointer_clut : std_logic_vector(7 downto 0);
|
109 |
|
|
datain_clut : std_logic_vector(23 downto 0);
|
110 |
|
|
write_en_clut : std_logic;
|
111 |
|
|
adress : std_logic_vector(31 downto 0);
|
112 |
|
|
start : std_logic;
|
113 |
|
|
write_pointer : integer range 0 to length;
|
114 |
|
|
ram_address : integer range 0 to length;
|
115 |
|
|
data : std_logic_vector(31 downto 0);
|
116 |
|
|
level : integer range 0 to part + 1;
|
117 |
|
|
status : integer range 0 to 3;
|
118 |
|
|
hpolarity : std_ulogic;
|
119 |
|
|
vpolarity : std_ulogic;
|
120 |
|
|
func : std_logic_vector(1 downto 0);
|
121 |
|
|
clk_sel : std_logic_vector(1 downto 0);
|
122 |
|
|
end record;
|
123 |
|
|
|
124 |
|
|
type sync_regs is record
|
125 |
|
|
s1 : std_logic_vector(2 downto 0);
|
126 |
|
|
s2 : std_logic_vector(2 downto 0);
|
127 |
|
|
s3 : std_logic_vector(2 downto 0);
|
128 |
|
|
end record;
|
129 |
|
|
|
130 |
|
|
signal t,tin : read_type;
|
131 |
|
|
signal r,rin : control_type;
|
132 |
|
|
signal sync_w : sync_regs;
|
133 |
|
|
signal sync_ra : sync_regs;
|
134 |
|
|
signal sync_rb : sync_regs;
|
135 |
|
|
signal sync_c : sync_regs;
|
136 |
|
|
signal read_status : std_logic_vector(2 downto 0);
|
137 |
|
|
signal write_status : std_logic_vector(2 downto 0);
|
138 |
|
|
signal write_en : std_logic;
|
139 |
|
|
signal res_mod :std_logic;
|
140 |
|
|
signal en_mod : std_logic;
|
141 |
|
|
signal fifo_en : std_logic;
|
142 |
|
|
signal dmai : ahb_dma_in_type;
|
143 |
|
|
signal dmao : ahb_dma_out_type;
|
144 |
|
|
signal equal : std_logic;
|
145 |
|
|
signal hmax : std_logic_vector(15 downto 0);
|
146 |
|
|
signal hfporch : std_logic_vector(15 downto 0);
|
147 |
|
|
signal hsyncpulse : std_logic_vector(15 downto 0);
|
148 |
|
|
signal hvideo : std_logic_vector(15 downto 0);
|
149 |
|
|
signal vmax : std_logic_vector(15 downto 0);
|
150 |
|
|
signal vfporch : std_logic_vector(15 downto 0);
|
151 |
|
|
signal vsyncpulse : std_logic_vector(15 downto 0);
|
152 |
|
|
signal vvideo : std_logic_vector(15 downto 0);
|
153 |
|
|
signal write_pointer_clut : std_logic_vector(7 downto 0);
|
154 |
|
|
signal read_pointer_clut : std_logic_vector(7 downto 0);
|
155 |
|
|
signal read_pointer_fifo : std_logic_vector(9 downto 0);
|
156 |
|
|
signal write_pointer_fifo : std_logic_vector(9 downto 0);
|
157 |
|
|
signal datain_clut : std_logic_vector(23 downto 0);
|
158 |
|
|
signal dataout_clut : std_logic_vector(23 downto 0);
|
159 |
|
|
signal dataout_fifo : std_logic_vector(31 downto 0);
|
160 |
|
|
signal datain_fifo : std_logic_vector(31 downto 0);
|
161 |
|
|
signal write_en_clut, read_en_clut : std_logic;
|
162 |
|
|
signal vcc : std_logic;
|
163 |
|
|
signal read_en_fifo, write_en_fifo : std_logic;
|
164 |
|
|
|
165 |
|
|
begin
|
166 |
|
|
|
167 |
|
|
vcc <= '1';
|
168 |
|
|
ram0 : syncram_2p generic map (tech => memtech, abits => 10, dbits => 32,
|
169 |
|
|
sepclk => 1)
|
170 |
|
|
port map (vgaclk, read_en_fifo, read_pointer_fifo, dataout_fifo,clk, write_en_fifo,
|
171 |
|
|
write_pointer_fifo, datain_fifo);
|
172 |
|
|
|
173 |
|
|
clutram : syncram_2p generic map (tech => memtech, abits => 8, dbits => 24,
|
174 |
|
|
sepclk => 1)
|
175 |
|
|
port map (vgaclk, read_en_clut, read_pointer_clut, dataout_clut, clk, write_en_clut,
|
176 |
|
|
write_pointer_clut,datain_clut);
|
177 |
|
|
|
178 |
|
|
ahb_master : ahbmst generic map (hindex, hirq, VENDOR_GAISLER,
|
179 |
|
|
GAISLER_SVGACTRL, 0, 3, 1)
|
180 |
|
|
port map (rst, clk, dmai, dmao, ahbi, ahbo);
|
181 |
|
|
|
182 |
|
|
apbo.pirq <= (others => '0');
|
183 |
|
|
apbo.pindex <= pindex;
|
184 |
|
|
apbo.pconfig <= pconfig;
|
185 |
|
|
|
186 |
|
|
control_proc : process(r,rst,sync_c,apbi,fifo_en,write_en,read_status,dmao,res_mod, sync_w)
|
187 |
|
|
|
188 |
|
|
variable v: control_type;
|
189 |
|
|
variable rdata : std_logic_vector(31 downto 0);
|
190 |
|
|
variable mem_sel : integer;
|
191 |
|
|
variable apbwrite : std_logic;
|
192 |
|
|
variable we_fifo : std_logic;
|
193 |
|
|
|
194 |
|
|
begin
|
195 |
|
|
|
196 |
|
|
v := r; v.write_en_clut := '0'; rdata := (others =>'0');
|
197 |
|
|
mem_sel := conv_integer(apbi.paddr(5 downto 2)); we_fifo := '0';
|
198 |
|
|
|
199 |
|
|
-- Control part. This part handles the apb-accesses and stores the internal registers
|
200 |
|
|
-------------------------------------------------------------------------------
|
201 |
|
|
-------------------------------------------------------------------------------
|
202 |
|
|
apbwrite := apbi.psel(pindex) and apbi.pwrite and apbi.penable;
|
203 |
|
|
case apbi.paddr(5 downto 2) is
|
204 |
|
|
when "0000" =>
|
205 |
|
|
if apbwrite = '1' then
|
206 |
|
|
v.enable := apbi.pwdata(0);
|
207 |
|
|
v.reset := apbi.pwdata(1);
|
208 |
|
|
v.hpolarity := apbi.pwdata(8);
|
209 |
|
|
v.vpolarity := apbi.pwdata(9);
|
210 |
|
|
v.func := apbi.pwdata(5 downto 4);
|
211 |
|
|
v.clk_sel := apbi.pwdata(7 downto 6);
|
212 |
|
|
end if;
|
213 |
|
|
rdata(9 downto 0) := r.vpolarity & r.hpolarity & r.clk_sel &
|
214 |
|
|
r.func & fifo_en & '0' & r.reset & r.enable;
|
215 |
|
|
when "1010" =>
|
216 |
|
|
if apbwrite = '1' then
|
217 |
|
|
v.datain_clut := apbi.pwdata(23 downto 0);
|
218 |
|
|
v.write_pointer_clut := apbi.pwdata(31 downto 24);
|
219 |
|
|
v.write_en_clut := '1';
|
220 |
|
|
end if;
|
221 |
|
|
when "0001" =>
|
222 |
|
|
if apbwrite = '1' then v.int_reg(1) := apbi.pwdata; end if;
|
223 |
|
|
rdata := r.int_reg(1);
|
224 |
|
|
when "0010" =>
|
225 |
|
|
if apbwrite = '1' then v.int_reg(2) := apbi.pwdata; end if;
|
226 |
|
|
rdata := r.int_reg(2);
|
227 |
|
|
when "0011" =>
|
228 |
|
|
if apbwrite = '1' then v.int_reg(3) := apbi.pwdata; end if;
|
229 |
|
|
rdata := r.int_reg(3);
|
230 |
|
|
when "0100" =>
|
231 |
|
|
if apbwrite = '1' then v.int_reg(4) := apbi.pwdata; end if;
|
232 |
|
|
rdata := r.int_reg(4);
|
233 |
|
|
when "0101" =>
|
234 |
|
|
if apbwrite = '1' then v.int_reg(5) := apbi.pwdata; end if;
|
235 |
|
|
rdata := r.int_reg(5);
|
236 |
|
|
when "0110" => rdata := conv_std_logic_vector(clk0,32);
|
237 |
|
|
when "0111" => rdata := conv_std_logic_vector(clk1,32);
|
238 |
|
|
when "1000" => rdata := conv_std_logic_vector(clk2,32);
|
239 |
|
|
when "1001" => rdata := conv_std_logic_vector(clk3,32);
|
240 |
|
|
when others =>
|
241 |
|
|
end case;
|
242 |
|
|
|
243 |
|
|
------------------------------------------
|
244 |
|
|
----------- Control state machine --------
|
245 |
|
|
|
246 |
|
|
case r.state is
|
247 |
|
|
when running =>
|
248 |
|
|
if r.enable = '0' then
|
249 |
|
|
v.sync_c := "011";
|
250 |
|
|
v.state := not_running;
|
251 |
|
|
end if;
|
252 |
|
|
when not_running =>
|
253 |
|
|
if r.enable = '1' then
|
254 |
|
|
v.sync_c := "001";
|
255 |
|
|
v.state := reset;
|
256 |
|
|
end if;
|
257 |
|
|
when reset =>
|
258 |
|
|
if sync_c.s3 = "001" then
|
259 |
|
|
v.sync_c := "010";
|
260 |
|
|
v.state := running;
|
261 |
|
|
end if;
|
262 |
|
|
end case;
|
263 |
|
|
|
264 |
|
|
-----------------------------------------
|
265 |
|
|
----------- Control reset part-----------
|
266 |
|
|
|
267 |
|
|
if r.reset = '1' or rst = '0' then
|
268 |
|
|
v.state := not_running;
|
269 |
|
|
v.enable := '0';
|
270 |
|
|
v.int_reg := (others => (others => '0'));
|
271 |
|
|
v.sync_c := "011";
|
272 |
|
|
v.reset := '0';
|
273 |
|
|
v.clk_sel := "00";
|
274 |
|
|
end if;
|
275 |
|
|
|
276 |
|
|
------------------------------------------------------------------------------
|
277 |
|
|
-- Write part. This part reads from the memory framebuffer and places the data
|
278 |
|
|
-- in the designated fifo specified from the generic.
|
279 |
|
|
-------------------------------------------------------------------------------
|
280 |
|
|
|
281 |
|
|
v.start := '0';
|
282 |
|
|
if write_en = '0' then
|
283 |
|
|
if (r.start or not dmao.active) = '1' then v.start := '1'; end if;
|
284 |
|
|
if dmao.ready = '1' then ------------ AHB access part -----------
|
285 |
|
|
---------- and Fifo write part ---------
|
286 |
|
|
v.data := dmao.rdata(31 downto 0);
|
287 |
|
|
v.ram_address := v.write_pointer;
|
288 |
|
|
v.write_pointer := v.write_pointer +1; we_fifo := '1';
|
289 |
|
|
if v.write_pointer = length then
|
290 |
|
|
v.write_pointer := 0;
|
291 |
|
|
end if;
|
292 |
|
|
v.level := v.level +1;
|
293 |
|
|
|
294 |
|
|
if dmao.haddr = (9 downto 0 => '0') then
|
295 |
|
|
v.adress := (v.adress(31 downto 10) + 1) & dmao.haddr;
|
296 |
|
|
else
|
297 |
|
|
v.adress := v.adress(31 downto 10) & dmao.haddr;
|
298 |
|
|
end if;
|
299 |
|
|
|
300 |
|
|
if (dmao.haddr(burstlen+1 downto 0) = ((burstlen+1 downto 2 => '1') & "00")) then
|
301 |
|
|
v.start := '0';
|
302 |
|
|
end if;
|
303 |
|
|
end if; ----------------------------------------
|
304 |
|
|
|
305 |
|
|
v.sync_w := v.sync_w and read_status; ------------ Fifo sync part ------------
|
306 |
|
|
|
307 |
|
|
if v.level >= (part -1) then
|
308 |
|
|
|
309 |
|
|
if read_status(r.status) = '1' and v.sync_w(r.status) = '0' and v.level = part then
|
310 |
|
|
v.level := 0;
|
311 |
|
|
if r.status = 0 then
|
312 |
|
|
v.sync_w(2) := '1';
|
313 |
|
|
else
|
314 |
|
|
v.sync_w(r.status -1) := '1';
|
315 |
|
|
end if;
|
316 |
|
|
v.status := v.status + 1;
|
317 |
|
|
if v.status = 3 then
|
318 |
|
|
v.status := 0;
|
319 |
|
|
end if;
|
320 |
|
|
else
|
321 |
|
|
v.start := '0';
|
322 |
|
|
end if;
|
323 |
|
|
end if;
|
324 |
|
|
end if; ------------------------------------------
|
325 |
|
|
|
326 |
|
|
------------ Write reset part ------------
|
327 |
|
|
if res_mod = '0' or write_en = '1' then
|
328 |
|
|
if dmao.active = '0' then v.adress := r.int_reg(5); end if;
|
329 |
|
|
v.start := '0';
|
330 |
|
|
v.sync_w := "000";
|
331 |
|
|
v.status := 1;
|
332 |
|
|
v.ram_address := 0;
|
333 |
|
|
v.write_pointer := 0;
|
334 |
|
|
v.level := 0;
|
335 |
|
|
end if; ------------------------------------------
|
336 |
|
|
|
337 |
|
|
if (r.start and dmao.active and not dmao.ready) = '1' then
|
338 |
|
|
v.start := '1';
|
339 |
|
|
end if;
|
340 |
|
|
|
341 |
|
|
-- Assertions
|
342 |
|
|
|
343 |
|
|
rin <= v;
|
344 |
|
|
sync_c.s1 <= v.sync_c;
|
345 |
|
|
sync_w.s1 <= r.sync_w;
|
346 |
|
|
res_mod <= sync_c.s3(1);
|
347 |
|
|
en_mod <= sync_c.s3(0);
|
348 |
|
|
write_status <= sync_w.s3;
|
349 |
|
|
hvideo <= r.int_reg(1)(15 downto 0);
|
350 |
|
|
vvideo <= r.int_reg(1)(31 downto 16);
|
351 |
|
|
hfporch <= r.int_reg(2)(15 downto 0);
|
352 |
|
|
vfporch <= r.int_reg(2)(31 downto 16);
|
353 |
|
|
hsyncpulse <= r.int_reg(3)(15 downto 0);
|
354 |
|
|
vsyncpulse <= r.int_reg(3)(31 downto 16);
|
355 |
|
|
hmax <= r.int_reg(4)(15 downto 0);
|
356 |
|
|
vmax <= r.int_reg(4)(31 downto 16);
|
357 |
|
|
apbo.prdata <= rdata;
|
358 |
|
|
dmai.wdata <= (others => '0');
|
359 |
|
|
dmai.burst <= '1';
|
360 |
|
|
dmai.irq <= '0';
|
361 |
|
|
dmai.size <= "10";
|
362 |
|
|
dmai.write <= '0';
|
363 |
|
|
dmai.busy <= '0';
|
364 |
|
|
dmai.start <= r.start and r.enable;
|
365 |
|
|
dmai.address <= r.adress;
|
366 |
|
|
write_pointer_fifo <= conv_std_logic_vector(v.ram_address,10);
|
367 |
|
|
write_pointer_clut <= r.write_pointer_clut;
|
368 |
|
|
datain_fifo <= v.data;
|
369 |
|
|
datain_clut <= r.datain_clut;
|
370 |
|
|
write_en_clut <= r.write_en_clut;
|
371 |
|
|
clk_sel <= r.clk_sel;
|
372 |
|
|
write_en_fifo <= we_fifo;
|
373 |
|
|
|
374 |
|
|
end process;
|
375 |
|
|
|
376 |
|
|
read_proc : process(t,res_mod,en_mod,write_status,dataout_fifo,sync_rb,dataout_clut,
|
377 |
|
|
vmax, hmax, hvideo, hfporch, hsyncpulse, vvideo, vfporch, vsyncpulse, sync_ra, r)
|
378 |
|
|
|
379 |
|
|
variable v : read_type;
|
380 |
|
|
variable inc_pointer : std_logic;
|
381 |
|
|
|
382 |
|
|
begin
|
383 |
|
|
|
384 |
|
|
v := t;
|
385 |
|
|
v.vsync2 := t.vsync; v.hsync2 := t.hsync; v.csync2 := t.csync;
|
386 |
|
|
v.blank2 := t.blank;
|
387 |
|
|
|
388 |
|
|
-- Syncsignals generation functions.
|
389 |
|
|
-------------------------------------------------------------------------------
|
390 |
|
|
-------------------------------------------------------------------------------
|
391 |
|
|
|
392 |
|
|
if en_mod = '0' then
|
393 |
|
|
|
394 |
|
|
-- vertical counter
|
395 |
|
|
if (t.vcounter = vmax ) and (t.hcounter = hmax ) then
|
396 |
|
|
v.vcounter := (others => '0');
|
397 |
|
|
elsif t.hcounter = hmax then
|
398 |
|
|
v.vcounter := t.vcounter +1;
|
399 |
|
|
end if;
|
400 |
|
|
|
401 |
|
|
-- horizontal counter
|
402 |
|
|
if t.hcounter < hmax then v.hcounter := t.hcounter +1;
|
403 |
|
|
else v.hcounter := (others => '0'); end if;
|
404 |
|
|
|
405 |
|
|
-- generate hsync
|
406 |
|
|
if t.hcounter < (hvideo+hfporch+hsyncpulse) and (t.hcounter > (hvideo+hfporch -1)) then
|
407 |
|
|
v.hsync := r.hpolarity;
|
408 |
|
|
else v.hsync := not r.hpolarity; end if;
|
409 |
|
|
|
410 |
|
|
-- generate vsync
|
411 |
|
|
if t.vcounter <= (vvideo+vfporch+vsyncpulse) and (t.vcounter > (vvideo+vfporch)) then
|
412 |
|
|
v.vsync := r.vpolarity;
|
413 |
|
|
else v.vsync := not r.vpolarity; end if;
|
414 |
|
|
|
415 |
|
|
--generate csync & blank signal
|
416 |
|
|
v.csync := not (v.hsync xor v.vsync);
|
417 |
|
|
v.blank := not t.fifo_ren;
|
418 |
|
|
|
419 |
|
|
--generate fifo_ren -signal
|
420 |
|
|
if (t.hcounter = (hmax -1) and t.vcounter = vmax) or
|
421 |
|
|
(t.hcounter = (hmax -1 ) and t.vcounter < vvideo) then
|
422 |
|
|
v.fifo_ren := '0';
|
423 |
|
|
elsif t.hcounter = (hvideo -1) and t.vcounter <= vvideo then
|
424 |
|
|
v.fifo_ren := '1';
|
425 |
|
|
end if;
|
426 |
|
|
|
427 |
|
|
--generate fifo_en -signal
|
428 |
|
|
if t.vcounter = vmax then
|
429 |
|
|
v.fifo_en := '0';
|
430 |
|
|
elsif t.vcounter = vvideo and t.hcounter = (hvideo -1) then
|
431 |
|
|
v.fifo_en := '1';
|
432 |
|
|
end if;
|
433 |
|
|
|
434 |
|
|
end if;
|
435 |
|
|
|
436 |
|
|
if r.func /= "01" then -- do not delay strobes when not using CLUT
|
437 |
|
|
v.vsync2 := v.vsync; v.hsync2 := v.hsync; v.csync2 := v.csync;
|
438 |
|
|
v.blank2 := v.blank;
|
439 |
|
|
end if;
|
440 |
|
|
|
441 |
|
|
-- Sync reset part ---------
|
442 |
|
|
if res_mod = '0' then
|
443 |
|
|
v.hcounter := hmax;
|
444 |
|
|
v.vcounter := vmax - 1;
|
445 |
|
|
v.hsync := r.hpolarity;
|
446 |
|
|
v.vsync := r.vpolarity;
|
447 |
|
|
v.blank := '0';
|
448 |
|
|
v.fifo_ren := '1';
|
449 |
|
|
v.fifo_en := '1';
|
450 |
|
|
end if;
|
451 |
|
|
|
452 |
|
|
-- Read from fifo.
|
453 |
|
|
-------------------------------------------------------------------------------
|
454 |
|
|
-------------------------------------------------------------------------------
|
455 |
|
|
|
456 |
|
|
inc_pointer := '0';
|
457 |
|
|
|
458 |
|
|
if t.fifo_en = '0' then
|
459 |
|
|
------------ Fifo sync part ------------
|
460 |
|
|
|
461 |
|
|
if (v.read_pointer_out = 0 or v.read_pointer_out = part or
|
462 |
|
|
v.read_pointer_out = (part + part)) and t.fifo_ren = '0'
|
463 |
|
|
and v.index = "00"
|
464 |
|
|
then
|
465 |
|
|
case t.sync is
|
466 |
|
|
when "111" | "011" =>
|
467 |
|
|
if write_status(0) = '1' then
|
468 |
|
|
v.sync := "110"; v.lock := '0';
|
469 |
|
|
else v.lock := '1'; end if;
|
470 |
|
|
when "110" =>
|
471 |
|
|
if write_status(1) = '1' then
|
472 |
|
|
v.sync := "101"; v.lock := '0';
|
473 |
|
|
else v.lock := '1'; end if;
|
474 |
|
|
when "101" =>
|
475 |
|
|
if write_status(2) = '1' then
|
476 |
|
|
v.sync := "011"; v.lock := '0';
|
477 |
|
|
else v.lock := '1'; end if;
|
478 |
|
|
when others => null;
|
479 |
|
|
end case;
|
480 |
|
|
end if;
|
481 |
|
|
|
482 |
|
|
------------------------------------------
|
483 |
|
|
------------ Fifo read part -------------
|
484 |
|
|
------------ and CLUT access -------------
|
485 |
|
|
|
486 |
|
|
if t.fifo_ren = '0' and v.lock = '0' then
|
487 |
|
|
|
488 |
|
|
case r.func is
|
489 |
|
|
when "01" =>
|
490 |
|
|
if t.index = "00" then
|
491 |
|
|
v.read_pointer_clut := dataout_fifo(31 downto 24);
|
492 |
|
|
v.index := "01";
|
493 |
|
|
elsif t.index = "01" then
|
494 |
|
|
v.read_pointer_clut := dataout_fifo(23 downto 16);
|
495 |
|
|
v.index := "10";
|
496 |
|
|
elsif t.index = "10" then
|
497 |
|
|
v.read_pointer_clut := dataout_fifo(15 downto 8);
|
498 |
|
|
v.index := "11";
|
499 |
|
|
else
|
500 |
|
|
v.read_pointer_clut := dataout_fifo(7 downto 0);
|
501 |
|
|
v.index := "00"; inc_pointer := '1';
|
502 |
|
|
end if;
|
503 |
|
|
v.data_out := dataout_clut;
|
504 |
|
|
when "10" =>
|
505 |
|
|
if t.index = "00" then
|
506 |
|
|
v.data_out := dataout_fifo(31 downto 27) & "000" &
|
507 |
|
|
dataout_fifo(26 downto 21) & "00" & dataout_fifo(20 downto 16) & "000";
|
508 |
|
|
v.index := "01";
|
509 |
|
|
else
|
510 |
|
|
v.data_out := dataout_fifo(15 downto 11) & "000" &
|
511 |
|
|
dataout_fifo(10 downto 5) & "00" & dataout_fifo(4 downto 0) & "000";
|
512 |
|
|
v.index := "00"; inc_pointer := '1';
|
513 |
|
|
end if;
|
514 |
|
|
when "11" =>
|
515 |
|
|
v.data_out := dataout_fifo(23 downto 0);
|
516 |
|
|
v.index := "00"; inc_pointer := '1';
|
517 |
|
|
when others =>
|
518 |
|
|
v.data_out := (23 downto 0 => '1');
|
519 |
|
|
v.index := "00"; inc_pointer := '1';
|
520 |
|
|
end case;
|
521 |
|
|
else
|
522 |
|
|
v.data_out := (others => '0');
|
523 |
|
|
end if;
|
524 |
|
|
|
525 |
|
|
if inc_pointer = '1' then
|
526 |
|
|
v.read_pointer_out := t.read_pointer;
|
527 |
|
|
v.read_pointer := t.read_pointer + 1;
|
528 |
|
|
|
529 |
|
|
if v.read_pointer = length then
|
530 |
|
|
v.read_pointer := 0;
|
531 |
|
|
end if;
|
532 |
|
|
if v.read_pointer_out = length then
|
533 |
|
|
v.read_pointer_out := 0;
|
534 |
|
|
end if;
|
535 |
|
|
|
536 |
|
|
end if;
|
537 |
|
|
|
538 |
|
|
else
|
539 |
|
|
v.data_out := (others => '0');
|
540 |
|
|
end if; ------------------------------------------
|
541 |
|
|
------------ Fifo read reset part -------
|
542 |
|
|
if res_mod = '0' or t.fifo_en = '1' then
|
543 |
|
|
v.sync := "111";
|
544 |
|
|
v.read_pointer_out := 0;
|
545 |
|
|
v.read_pointer := 1;
|
546 |
|
|
v.data_out := (others => '0');
|
547 |
|
|
v.lock := '1';
|
548 |
|
|
v.index := "00";
|
549 |
|
|
v.read_pointer_clut := (others => '0');
|
550 |
|
|
end if; ------------------------------------------
|
551 |
|
|
|
552 |
|
|
tin <= v;
|
553 |
|
|
sync_ra.s1 <= t.sync;
|
554 |
|
|
sync_rb.s1 <= t.fifo_en & "00";
|
555 |
|
|
read_status <= sync_ra.s3;
|
556 |
|
|
write_en <= sync_rb.s3(2);
|
557 |
|
|
fifo_en <= t.fifo_en;
|
558 |
|
|
read_pointer_clut <= v.read_pointer_clut;
|
559 |
|
|
read_pointer_fifo <= conv_std_logic_vector(v.read_pointer_out,10);
|
560 |
|
|
read_en_fifo <= not v.fifo_ren;
|
561 |
|
|
read_en_clut <= not v.fifo_ren and not r.func(1) and r.func(0);
|
562 |
|
|
vgao.video_out_r <= t.data_out(23 downto 16);
|
563 |
|
|
vgao.video_out_g <= t.data_out(15 downto 8);
|
564 |
|
|
vgao.video_out_b <= t.data_out(7 downto 0);
|
565 |
|
|
vgao.hsync <= t.hsync2;
|
566 |
|
|
vgao.vsync <= t.vsync2;
|
567 |
|
|
vgao.comp_sync <= t.csync2;
|
568 |
|
|
vgao.blank <= t.blank2;
|
569 |
|
|
|
570 |
|
|
end process;
|
571 |
|
|
|
572 |
|
|
proc_clk : process(clk)
|
573 |
|
|
begin
|
574 |
|
|
if rising_edge(clk) then
|
575 |
|
|
r <= rin; -- Control
|
576 |
|
|
sync_ra.s2 <= sync_ra.s1; -- Write
|
577 |
|
|
sync_ra.s3 <= sync_ra.s2; -- Write
|
578 |
|
|
sync_rb.s2 <= sync_rb.s1; -- Write
|
579 |
|
|
sync_rb.s3 <= sync_rb.s2; -- Write
|
580 |
|
|
end if;
|
581 |
|
|
end process;
|
582 |
|
|
|
583 |
|
|
proc_vgaclk : process(vgaclk)
|
584 |
|
|
begin
|
585 |
|
|
if rising_edge(vgaclk) then
|
586 |
|
|
t <= tin; -- Read
|
587 |
|
|
sync_c.s2 <= sync_c.s1; -- Control
|
588 |
|
|
sync_c.s3 <= sync_c.s2; -- Control
|
589 |
|
|
sync_w.s2 <= sync_w.s1; -- Read
|
590 |
|
|
sync_w.s3 <= sync_w.s2; -- Read
|
591 |
|
|
end if;
|
592 |
|
|
end process;
|
593 |
|
|
|
594 |
|
|
end ;
|
595 |
|
|
|