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

Subversion Repositories wb_vga

[/] [wb_vga/] [trunk/] [vga_core.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tantos
--
2
--  File: vga_core.vhd
3
--
4
--  (c) Copyright Andras Tantos <andras_tantos@yahoo.com> 2001/03/31
5
--  This code is distributed under the terms and conditions of the GNU General Public Lince.
6
--
7
 
8
library IEEE;
9
use IEEE.std_logic_1164.all;
10
 
11 4 tantos
library wb_tk;
12
use wb_tk.all;
13
use wb_tk.technology.all;
14 2 tantos
 
15 4 tantos
library wb_vga;
16
use wb_vga.all;
17
 
18 2 tantos
entity vga_core is
19
        generic (
20 4 tantos
                v_dat_width: positive := 16;
21
                v_adr_width : positive := 20;
22 6 tantos
                cpu_dat_width: positive := 16;
23
                cpu_adr_width: positive := 20;
24
                reg_adr_width: positive := 20;
25 4 tantos
                fifo_size: positive := 256
26 2 tantos
        );
27
        port (
28
                clk_i: in std_logic;
29
                clk_en: in std_logic := '1';
30
                rst_i: in std_logic := '0';
31
 
32 6 tantos
                -- CPU memory bus interface
33
                vmem_cyc_i: in std_logic;
34
                vmem_we_i: in std_logic;
35 4 tantos
                vmem_stb_i: in std_logic;   -- selects video memory
36 6 tantos
                vmem_ack_o: out std_logic;
37
                vmem_ack_oi: in std_logic;
38
                vmem_adr_i: in std_logic_vector (cpu_adr_width-1 downto 0);
39
        vmem_sel_i: in std_logic_vector ((cpu_dat_width/8)-1 downto 0) := (others => '1');
40
                vmem_dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
41
                vmem_dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0);
42
                vmem_dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
43 2 tantos
 
44 6 tantos
                -- CPU register bus interface
45
                reg_cyc_i: in std_logic;
46
                reg_we_i: in std_logic;
47
        reg_stb_i: in std_logic;    -- selects configuration registers
48
                reg_ack_o: out std_logic;
49
                reg_ack_oi: in std_logic;
50
                reg_adr_i: in std_logic_vector (reg_adr_width-1 downto 0);
51
        reg_sel_i: in std_logic_vector ((cpu_dat_width/8)-1 downto 0) := (others => '1');
52
                reg_dat_i: in std_logic_vector (cpu_dat_width-1 downto 0);
53
                reg_dat_oi: in std_logic_vector (cpu_dat_width-1 downto 0);
54
                reg_dat_o: out std_logic_vector (cpu_dat_width-1 downto 0);
55
 
56 4 tantos
                -- video memory interface
57
                v_adr_o: out std_logic_vector (v_adr_width-1 downto 0);
58
                v_sel_o: out std_logic_vector ((v_dat_width/8)-1 downto 0);
59
                v_dat_i: in std_logic_vector (v_dat_width-1 downto 0);
60
                v_dat_o: out std_logic_vector (v_dat_width-1 downto 0);
61
                v_cyc_o: out std_logic;
62
                v_ack_i: in std_logic;
63
                v_we_o: out std_logic;
64
                v_stb_o: out std_logic;
65 2 tantos
 
66
                -- sync blank and video signal outputs
67
                h_sync: out std_logic;
68
                h_blank: out std_logic;
69
                v_sync: out std_logic;
70
                v_blank: out std_logic;
71
                h_tc: out std_logic;
72
                v_tc: out std_logic;
73
                blank: out std_logic;
74 4 tantos
                video_out: out std_logic_vector (7 downto 0)  -- video output binary signal (unused bits are forced to 0)
75 2 tantos
        );
76
end vga_core;
77
 
78
architecture vga_core of vga_core is
79
        component video_engine
80
                generic (
81
                        v_mem_width: positive := 16;
82
                        v_addr_width: positive:= 20;
83
                        fifo_size: positive := 256;
84
                        dual_scan_fifo_size: positive := 256
85
                );
86
                port (
87
                        clk: in std_logic;
88
                        clk_en: in std_logic := '1';
89
                        reset: in std_logic := '0';
90
 
91 6 tantos
                v_mem_end: in std_logic_vector(v_addr_width-1 downto 0);   -- video memory end address in words
92
                v_mem_start: in std_logic_vector(v_addr_width-1 downto 0) := (others => '0'); -- video memory start adderss in words
93 2 tantos
                        fifo_treshold: in std_logic_vector(7 downto 0);        -- priority change threshold
94
                        bpp: in std_logic_vector(1 downto 0);                  -- number of bits makes up a pixel valid values: 1,2,4,8
95
                        multi_scan: in std_logic_vector(1 downto 0);           -- number of repeated scans
96
 
97
                        hbs: in std_logic_vector(7 downto 0);
98
                        hss: in std_logic_vector(7 downto 0);
99
                        hse: in std_logic_vector(7 downto 0);
100
                        htotal: in std_logic_vector(7 downto 0);
101
                        vbs: in std_logic_vector(7 downto 0);
102
                        vss: in std_logic_vector(7 downto 0);
103
                        vse: in std_logic_vector(7 downto 0);
104
                        vtotal: in std_logic_vector(7 downto 0);
105
 
106
                        pps: in std_logic_vector(7 downto 0);
107
 
108
                        high_prior: out std_logic;                      -- signals to the memory arbitrer to give high
109
                                                                        -- priority to the video engine
110
                        v_mem_rd: out std_logic;                        -- video memory read request
111
                        v_mem_rdy: in std_logic;                        -- video memory data ready
112
                        v_mem_addr: out std_logic_vector (v_addr_width-1 downto 0); -- video memory address
113
                        v_mem_data: in std_logic_vector (v_mem_width-1 downto 0);   -- video memory data
114
 
115
                        h_sync: out std_logic;
116
                        h_blank: out std_logic;
117
                        v_sync: out std_logic;
118
                        v_blank: out std_logic;
119
                        h_tc: out std_logic;
120
                        v_tc: out std_logic;
121
                        blank: out std_logic;
122
                        video_out: out std_logic_vector (7 downto 0)    -- video output binary signal (unused bits are forced to 0)
123
                );
124
        end component video_engine;
125
 
126
        component wb_arbiter
127
        port (
128
--              clk: in std_logic;
129
                rst_i: in std_logic := '0';
130
 
131
                -- interface to master device a
132
                a_we_i: in std_logic;
133
                a_stb_i: in std_logic;
134
                a_cyc_i: in std_logic;
135
                a_ack_o: out std_logic;
136
                a_ack_oi: in std_logic := '-';
137
                a_err_o: out std_logic;
138
                a_err_oi: in std_logic := '-';
139
                a_rty_o: out std_logic;
140
                a_rty_oi: in std_logic := '-';
141
 
142
                -- interface to master device b
143
                b_we_i: in std_logic;
144
                b_stb_i: in std_logic;
145
                b_cyc_i: in std_logic;
146
                b_ack_o: out std_logic;
147
                b_ack_oi: in std_logic := '-';
148
                b_err_o: out std_logic;
149
                b_err_oi: in std_logic := '-';
150
                b_rty_o: out std_logic;
151
                b_rty_oi: in std_logic := '-';
152
 
153
                -- interface to shared devices
154
                s_we_o: out std_logic;
155
                s_stb_o: out std_logic;
156
                s_cyc_o: out std_logic;
157
                s_ack_i: in std_logic;
158
                s_err_i: in std_logic := '-';
159
                s_rty_i: in std_logic := '-';
160
 
161
                mux_signal: out std_logic; -- 0: select A signals, 1: select B signals
162
 
163
                -- misc control lines
164
                priority: in std_logic -- 0: A have priority over B, 1: B have priority over A
165
        );
166
        end component;
167
 
168
        component wb_out_reg
169 4 tantos
        generic (
170
                width : positive := 8;
171
                bus_width: positive := 8;
172
                offset: integer := 0
173
        );
174
        port (
175
                clk_i: in std_logic;
176
                rst_i: in std_logic;
177
                rst_val: std_logic_vector(width-1 downto 0) := (others => '0');
178 2 tantos
 
179 4 tantos
        cyc_i: in std_logic := '1';
180
                stb_i: in std_logic;
181
        sel_i: in std_logic_vector ((bus_width/8)-1 downto 0) := (others => '1');
182
                we_i: in std_logic;
183
                ack_o: out std_logic;
184
                ack_oi: in std_logic := '-';
185
                adr_i: in std_logic_vector (size2bits((width+offset+bus_width-1)/bus_width)-1 downto 0) := (others => '0');
186
                dat_i: in std_logic_vector (bus_width-1 downto 0);
187
                dat_oi: in std_logic_vector (bus_width-1 downto 0) := (others => '-');
188
                dat_o: out std_logic_vector (bus_width-1 downto 0);
189
                q: out std_logic_vector (width-1 downto 0)
190
        );
191 2 tantos
        end component;
192
 
193 4 tantos
        component wb_bus_resize
194 2 tantos
        generic (
195 6 tantos
                m_bus_width: positive;
196
                m_addr_width: positive;
197
                s_bus_width: positive;
198
                s_addr_width: positive;
199 2 tantos
                little_endien: boolean := true -- if set to false, big endien
200
        );
201
        port (
202
--              clk_i: in std_logic;
203
--              rst_i: in std_logic := '0';
204
 
205
                -- Master bus interface
206
                m_adr_i: in std_logic_vector (m_addr_width-1 downto 0);
207
                m_sel_i: in std_logic_vector ((m_bus_width/8)-1 downto 0) := (others => '1');
208
                m_dat_i: in std_logic_vector (m_bus_width-1 downto 0);
209
                m_dat_oi: in std_logic_vector (m_bus_width-1 downto 0) := (others => '-');
210
                m_dat_o: out std_logic_vector (m_bus_width-1 downto 0);
211
                m_cyc_i: in std_logic;
212
                m_ack_o: out std_logic;
213
                m_ack_oi: in std_logic := '-';
214
                m_err_o: out std_logic;
215
                m_err_oi: in std_logic := '-';
216
                m_rty_o: out std_logic;
217
                m_rty_oi: in std_logic := '-';
218
                m_we_i: in std_logic;
219
                m_stb_i: in std_logic;
220
 
221
                -- Slave bus interface
222 4 tantos
                s_adr_o: out std_logic_vector (s_addr_width-1 downto 0);
223 2 tantos
                s_sel_o: out std_logic_vector ((s_bus_width/8)-1 downto 0);
224
                s_dat_i: in std_logic_vector (s_bus_width-1 downto 0);
225
                s_dat_o: out std_logic_vector (s_bus_width-1 downto 0);
226
                s_cyc_o: out std_logic;
227
                s_ack_i: in std_logic;
228
                s_err_i: in std_logic := '-';
229
                s_rty_i: in std_logic := '-';
230
                s_we_o: out std_logic;
231
                s_stb_o: out std_logic
232
        );
233
        end component;
234
 
235 6 tantos
        signal v_mem_start: std_logic_vector(v_adr_width-1 downto 0);
236
        signal v_mem_end: std_logic_vector(v_adr_width-1 downto 0);
237 4 tantos
 
238
        signal reg_bank: std_logic_vector((8*12)-1 downto 0);
239 2 tantos
 
240 4 tantos
        alias fifo_treshold: std_logic_vector(7 downto 0) is reg_bank( 7 downto  0);
241
        alias bpp: std_logic_vector(1 downto 0)           is reg_bank( 9 downto  8);
242
        alias multi_scan: std_logic_vector(1 downto 0)    is reg_bank(13 downto 12);
243
        alias hbs: std_logic_vector(7 downto 0)           is reg_bank(23 downto 16);
244
        alias hss: std_logic_vector(7 downto 0)           is reg_bank(31 downto 24);
245
        alias hse: std_logic_vector(7 downto 0)           is reg_bank(39 downto 32);
246
        alias htotal: std_logic_vector(7 downto 0)        is reg_bank(47 downto 40);
247
        alias vbs: std_logic_vector(7 downto 0)           is reg_bank(55 downto 48);
248
        alias vss: std_logic_vector(7 downto 0)           is reg_bank(63 downto 56);
249
        alias vse: std_logic_vector(7 downto 0)           is reg_bank(71 downto 64);
250
        alias vtotal: std_logic_vector(7 downto 0)        is reg_bank(79 downto 72);
251
        alias pps: std_logic_vector(7 downto 0)           is reg_bank(87 downto 80);
252
        alias sync_pol: std_logic_vector (3 downto 0)     is reg_bank(91 downto 88);
253
        alias reset_core: std_logic_vector(0 downto 0)    is reg_bank(95 downto 95);
254 2 tantos
 
255 6 tantos
    signal v_mem_start_stb: std_logic;    -- selects total register
256
    signal v_mem_end_stb: std_logic;      -- selects offset register
257
    signal reg_bank_stb: std_logic; -- selects all other registers (in a single bank)
258
 
259 4 tantos
        signal reg_bank_do: std_logic_vector(cpu_dat_width-1 downto 0);
260 6 tantos
        signal v_mem_start_do: std_logic_vector(cpu_dat_width-1 downto 0);
261 2 tantos
 
262 4 tantos
        signal reg_bank_ack: std_logic;
263 6 tantos
        signal v_mem_start_ack: std_logic;
264 2 tantos
 
265 4 tantos
        signal a_adr_o : std_logic_vector((v_adr_width-1) downto 0);
266 6 tantos
        signal a_sel_o : std_logic_vector((v_dat_width/8)-1 downto 0);
267 4 tantos
        signal a_dat_o : std_logic_vector((v_dat_width-1) downto 0);
268
        signal a_dat_i : std_logic_vector((v_dat_width-1) downto 0);
269 2 tantos
        signal a_we_o : std_logic;
270
        signal a_stb_o : std_logic;
271
        signal a_cyc_o : std_logic;
272
        signal a_ack_i : std_logic;
273
 
274 4 tantos
        signal b_adr_o : std_logic_vector((v_adr_width-1) downto 0);
275 6 tantos
        signal b_sel_o : std_logic_vector((v_dat_width/8)-1 downto 0);
276 4 tantos
--      signal b_dat_o : std_logic_vector((v_dat_width-1) downto 0);
277
        signal b_dat_i : std_logic_vector((v_dat_width-1) downto 0);
278 2 tantos
        signal b_stb_o : std_logic;
279
--      signal b_we_o : std_logic;
280
--      signal b_cyc_o : std_logic;
281
        signal b_ack_i : std_logic;
282
 
283
        signal mux_signal: std_logic;
284
 
285
        signal high_prior: std_logic;
286
 
287
        signal reset_engine: std_logic;
288
 
289
        signal i_h_sync: std_logic;
290
        signal i_h_blank: std_logic;
291
        signal i_v_sync: std_logic;
292
        signal i_v_blank: std_logic;
293
 
294
        signal s_wrn : std_logic;
295 4 tantos
 
296
        constant v_adr_zero : std_logic_vector(v_adr_width-1 downto 0) := (others => '0');
297
        constant reg_bank_rst_val: std_logic_vector(reg_bank'Range) := (others => '0');
298 6 tantos
        constant reg_bank_size: integer := size2bits((reg_bank'HIGH+cpu_dat_width)/cpu_dat_width);
299
        constant tot_ofs_size: integer := size2bits((v_adr_width+cpu_dat_width-1)/cpu_dat_width);
300 2 tantos
begin
301
        -- map all registers:
302 4 tantos
--              adr_i: in std_logic_vector (max(log2((width+offset+bus_width-1)/bus_width)-1,0) downto 0) := (others => '0');
303
 
304
        reg_bank_reg: wb_out_reg
305
                generic map( width => reg_bank'HIGH+1, bus_width => cpu_dat_width , offset => 0 )
306 2 tantos
                port map(
307 6 tantos
                stb_i => reg_bank_stb,
308 4 tantos
                q => reg_bank,
309
                rst_val => reg_bank_rst_val,
310 6 tantos
                dat_oi => reg_dat_oi,
311 4 tantos
                dat_o => reg_bank_do,
312 6 tantos
                ack_oi => reg_ack_oi,
313 4 tantos
                ack_o => reg_bank_ack,
314 6 tantos
                adr_i => reg_adr_i(reg_bank_size-1 downto 0),
315
                sel_i => reg_sel_i, cyc_i => reg_cyc_i, we_i => reg_we_i, clk_i => clk_i, rst_i => rst_i, dat_i => reg_dat_i );
316
        v_mem_start_reg: wb_out_reg
317 4 tantos
                generic map( width => v_adr_width, bus_width => cpu_dat_width , offset => 0 )
318 2 tantos
                port map(
319 6 tantos
            stb_i => v_mem_start_stb,
320
            q => v_mem_start,
321 4 tantos
            rst_val => v_adr_zero,
322
            dat_oi => reg_bank_do,
323 6 tantos
            dat_o => v_mem_start_do,
324 4 tantos
            ack_oi => reg_bank_ack,
325 6 tantos
            ack_o => v_mem_start_ack,
326
                adr_i => reg_adr_i(tot_ofs_size-1 downto 0),
327
                sel_i => reg_sel_i, cyc_i => reg_cyc_i, we_i => reg_we_i, clk_i => clk_i, rst_i => rst_i, dat_i => reg_dat_i );
328
        v_mem_end_reg: wb_out_reg
329 4 tantos
                generic map( width => v_adr_width, bus_width => cpu_dat_width , offset => 0 )
330 2 tantos
                port map(
331 6 tantos
            stb_i => v_mem_end_stb,
332
            q => v_mem_end,
333 4 tantos
            rst_val => v_adr_zero,
334 6 tantos
            dat_oi => v_mem_start_do,
335
            dat_o => reg_dat_o, -- END OF THE CHAIN
336
            ack_oi => v_mem_start_ack,
337
            ack_o => reg_ack_o, -- END OF THE CHAIN
338
                adr_i => reg_adr_i(tot_ofs_size-1 downto 0),
339
                sel_i => reg_sel_i, cyc_i => reg_cyc_i, we_i => reg_we_i, clk_i => clk_i, rst_i => rst_i, dat_i => reg_dat_i );
340 2 tantos
 
341 4 tantos
    reset_engine <= rst_i or not reset_core(0);
342 2 tantos
 
343
        v_e: video_engine
344 4 tantos
                generic map ( v_mem_width => v_dat_width, v_addr_width => v_adr_width, fifo_size => fifo_size, dual_scan_fifo_size => fifo_size )
345 2 tantos
                port map (
346
                        clk => clk_i,
347
                        clk_en => clk_en,
348
                        reset => reset_engine,
349 6 tantos
                        v_mem_start => v_mem_start,
350
                        v_mem_end => v_mem_end,
351 2 tantos
                        fifo_treshold => fifo_treshold,
352
                        bpp => bpp,
353
                        multi_scan => multi_scan,
354
                        hbs => hbs,
355
                        hss => hss,
356
                        hse => hse,
357
                        htotal => htotal,
358
                        vbs => vbs,
359
                        vss => vss,
360
                        vse => vse,
361
                        vtotal => vtotal,
362
                        pps => pps,
363
 
364
                        high_prior => high_prior,
365
 
366
                        v_mem_rd => b_stb_o,
367
                        v_mem_rdy => b_ack_i,
368
                        v_mem_addr => b_adr_o,
369
                        v_mem_data => b_dat_i,
370
 
371
                        h_sync => i_h_sync,
372
                        h_blank => i_h_blank,
373
                        v_sync => i_v_sync,
374
                        v_blank => i_v_blank,
375
                        h_tc => h_tc,
376
                        v_tc => v_tc,
377
                        blank => blank,
378
                        video_out => video_out
379
                );
380
 
381
        h_sync <= i_h_sync xor sync_pol(0);
382
        v_sync <= i_v_sync xor sync_pol(1);
383
        h_blank <= i_h_blank;-- xor sync_pol(2);
384
        v_blank <= i_v_blank;-- xor sync_pol(3);
385
 
386 4 tantos
        resize: wb_bus_resize
387 2 tantos
                generic map (
388 6 tantos
                        m_bus_width => cpu_dat_width, s_bus_width => v_dat_width, m_addr_width => cpu_adr_width, s_addr_width => v_adr_width, little_endien => true
389 2 tantos
                )
390
                port map (
391 6 tantos
                        m_adr_i => vmem_adr_i,
392
                        m_cyc_i => vmem_cyc_i,
393
                        m_sel_i => vmem_sel_i,
394
                        m_dat_i => vmem_dat_i,
395
                        m_dat_oi => vmem_dat_oi,
396
                        m_dat_o => vmem_dat_o,
397
                        m_ack_o => vmem_ack_o,
398
                        m_ack_oi => vmem_ack_oi, -- Beginning of the chain
399
                        m_we_i => vmem_we_i,
400 2 tantos
                        m_stb_i => vmem_stb_i,
401
 
402
                        s_adr_o => a_adr_o,
403
                        s_sel_o => a_sel_o,
404
                        s_dat_i => a_dat_i,
405
                        s_dat_o => a_dat_o,
406
                s_cyc_o => a_cyc_o,
407
                        s_ack_i => a_ack_i,
408
                        s_we_o => a_we_o,
409
                        s_stb_o => a_stb_o
410
                );
411
 
412
 
413
        arbiter: wb_arbiter
414
        port map (
415
                rst_i => reset_engine,
416
 
417
                a_we_i => a_we_o,
418
                a_cyc_i => a_cyc_o,
419
                a_stb_i => a_stb_o,
420
                a_ack_o => a_ack_i,
421
                a_ack_oi => '-',
422
 
423
                b_we_i => '0',
424
                b_cyc_i => b_stb_o,
425
                b_stb_i => b_stb_o,
426
                b_ack_o => b_ack_i,
427 4 tantos
                b_ack_oi => '0',
428 2 tantos
 
429
                s_we_o => v_we_o,
430
                s_stb_o => v_stb_o,
431
                s_ack_i => v_ack_i,
432 4 tantos
                s_cyc_o => v_cyc_o,
433 2 tantos
 
434
                mux_signal => mux_signal,
435
 
436
                priority => high_prior
437
        );
438
 
439
    b_sel_o <= (others => '1');
440
 
441
        bus_mux: process is
442
        begin
443
                wait on mux_signal, v_dat_i, a_adr_o, a_dat_o, b_adr_o, a_sel_o, b_sel_o;
444
                if (mux_signal = '0') then
445
                        v_adr_o <= a_adr_o;
446
                        v_sel_o <= a_sel_o;
447
                        v_dat_o <= a_dat_o;
448
                        a_dat_i <= v_dat_i;
449
                        b_dat_i <= (others => '-');
450
                else
451
                        v_adr_o <= b_adr_o;
452
                        v_sel_o <= b_sel_o;
453
                        v_dat_o <= (others => '-');
454
                        b_dat_i <= v_dat_i;
455
                        a_dat_i <= (others => '-');
456
                end if;
457
        end process;
458
 
459 6 tantos
        addr_decoder: process is
460
        begin
461
                wait on reg_stb_i, reg_adr_i;
462
 
463
        v_mem_start_stb <= '0';
464
        v_mem_end_stb <= '0';
465
        reg_bank_stb <= '0';
466
 
467
                if (reg_stb_i = '1') then
468
                        case (reg_adr_i(reg_bank_size)) is
469
                                when '0' =>
470
                                case (reg_adr_i(reg_bank_size-2)) is
471
                                        when '0' => v_mem_end_stb <= '1';
472
                                        when '1' => v_mem_start_stb <= '1';
473
                                        when others =>
474
                                end case;
475
                                when '1' => reg_bank_stb <= '1';
476
                                when others =>
477
                        end case;
478
                end if;
479
        end process;
480 2 tantos
end vga_core;
481
 

powered by: WebSVN 2.1.0

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