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

Subversion Repositories z80soc

[/] [z80soc/] [branches/] [RonivonCosta/] [S3E/] [top_s3e.vhd] - Blame information for rev 44

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rrred
-------------------------------------------------------------------------------------------------
2
-- Z80_Soc (Z80 System on Chip)
3
-- 
4 18 rrred
-- Version 0.5 Beta Spartan 3E
5 11 rrred
--
6
-- Developer: Ronivon Candido Costa
7
-- Release Date: 2008 / 04 / 16
8
--
9
-- Based on the T80 core: http://www.opencores.org/projects.cgi/web/t80
10 18 rrred
-- This version developed and tested on: Diligent Spartan 3E
11 11 rrred
--
12
-- Peripherals configured (Using Ports):
13
--
14 18 rrred
--      08 KB Internal ROM      Read                    (0x0000h - 0x1FFFh)
15
--      02 KB INTERNAL VRAM     Write                   (0x2000h - 0x27FFh)
16
-- 16 KB INTERNAL       RAM     Read/Write      (0x4000h - 0xFFFFh)
17
--      08 Green Leds                   Out                     (Port 0x01h)
18
--      01 LCD display                  Out                     (0x3FE0 x 0x3FFF)
19
--      04 Switches                             In                              (Port 0x20h)
20
--      04 Push buttons         In                              (Port 0x30h)
21
--      PS/2 keyboard                   In                              (Port 0x80h)
22
--      Video Out (VGA)         Out                     (0x2000h - 0x24B0)
23 11 rrred
--
24
--
25
--  Revision history:
26
--
27 18 rrred
-- 2008/05/11 - Fixed access to RAM and VRAM,
28
--              Released same ROM version for DE1 and S3E
29
--
30
-- 2008/05/01 - Added LCD support for Spartan 3E
31
--
32 11 rrred
-- 2008/04(21 - Ported to Spartan 3E
33
--
34
--      2008/04/17 - Added Video support for 80x40 mode
35
--  2008/04/16 - Release Version 0.5-DE1-Beta
36
--
37
-- TO-DO:
38 18 rrred
-- - Implement hardware control for the Rotary knob
39
-- - Implement hardware control for the A/D and IO pins
40
-- - Monitor program to introduce Z80 Assmebly codes and run
41 11 rrred
--      - Serial communication, to download assembly code from PC
42
--      - Add hardware support for 80x40 Video out
43
--      - SD/MMC card interface to read/store data and programs
44
-------------------------------------------------------------------------------------------------
45
 
46
library IEEE;
47
use IEEE.std_logic_1164.all;
48
use IEEE.std_logic_arith.all;
49
use IEEE.std_logic_unsigned.all;
50
 
51
entity Z80SOC_TOP is
52
  generic (
53
    swcount             : integer := 4;
54
         keycount       : integer := 4;
55
         ledrcount      : integer := 10;
56
         ledgcount      : integer := 8;
57
         sramdepth      : integer := 16;
58
         dramdepth      : integer := 13;
59
         framdepth      : integer := 25;
60
         vgadepth       : integer := 1);
61
        port(
62
    -- Clocks
63
    CLOCK_50 : in std_logic;                                    -- 50 MHz
64
 
65
    -- Buttons and switches
66
    KEY : in std_logic_vector(keycount - 1 downto 0);         -- Push buttons
67
    SW : in std_logic_vector(swcount-1 downto 0);          -- Switches
68
 
69
    -- LED displays
70
    LEDG : out std_logic_vector(ledgcount-1 downto 0);       -- Green LEDs
71
 
72
    -- RS-232 interface
73
    -- UART_TXD : out std_logic;                      -- UART transmitter   
74
    -- UART_RXD : in std_logic;                       -- UART receiver
75
 
76
    -- PS/2 port
77
    PS2_DAT,                    -- Data
78
    PS2_CLK : inout std_logic;     -- Clock
79
 
80
    -- VGA output
81
    VGA_HS,                                             -- H_SYNC
82
    VGA_VS : out std_logic;                             -- SYNC
83
    VGA_R,                                              -- Red[3:0]
84
    VGA_G,                                              -- Green[3:0]
85
    VGA_B : out std_logic;                                                                         -- Blue[3:0]
86
         SF_D  : out std_logic_vector(3 downto 0);
87 18 rrred
         LCD_E, LCD_RS, LCD_RW, SF_CE0 : out std_logic;
88
         AP     : out std_logic_vector(15 downto 0);
89
         DI     : out std_logic_vector(7 downto 0);
90
         DO     : out std_logic_vector(7 downto 0);
91
         WR     : out  std_logic;
92
         RD     : out std_logic;
93
         MR     : out std_logic;
94
         IQ     : out std_logic
95 11 rrred
);
96
end Z80SOC_TOP;
97
 
98
architecture rtl of Z80SOC_TOP is
99
 
100 18 rrred
        component T80se
101
        generic(
102
                Mode : integer := 0;     -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
103
                T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
104
                IOWait : integer := 1   -- 0 => Single cycle I/O, 1 => Std I/O cycle
105
        );
106
        port(
107
                RESET_n : in std_logic;
108
                CLK_n           : in std_logic;
109
                CLKEN           : in std_logic;
110
                WAIT_n  : in std_logic;
111
                INT_n           : in std_logic;
112
                NMI_n           : in std_logic;
113
                BUSRQ_n : in std_logic;
114
                M1_n            : out std_logic;
115
                MREQ_n  : out std_logic;
116
                IORQ_n  : out std_logic;
117
                RD_n            : out std_logic;
118
                WR_n            : out std_logic;
119
                RFSH_n  : out std_logic;
120
                HALT_n  : out std_logic;
121
                BUSAK_n : out std_logic;
122
                A                       : out std_logic_vector(15 downto 0);
123
                DI                      : in std_logic_vector(7 downto 0);
124
                DO                      : out std_logic_vector(7 downto 0)
125
        );
126
        end component;
127
 
128
        component sram16k
129
                port (
130
                addr    : IN std_logic_VECTOR(13 downto 0);
131
                clk     : IN std_logic;
132
                din     : IN std_logic_VECTOR(7 downto 0);
133
                dout    : OUT std_logic_VECTOR(7 downto 0);
134
                we              : IN std_logic);
135
        end component;
136
 
137
        component Clock_357Mhz
138
        PORT (
139
                clock_50Mhz                             : IN    STD_LOGIC;
140
                clock_357Mhz                    : OUT   STD_LOGIC);
141
        end component;
142
 
143 11 rrred
        component clk_div
144
        PORT
145
        (
146
                clock_25Mhz                             : IN    STD_LOGIC;
147
                clock_1MHz                              : OUT   STD_LOGIC;
148
                clock_100KHz                    : OUT   STD_LOGIC;
149
                clock_10KHz                             : OUT   STD_LOGIC;
150
                clock_1KHz                              : OUT   STD_LOGIC;
151
                clock_100Hz                             : OUT   STD_LOGIC;
152
                clock_10Hz                              : OUT   STD_LOGIC;
153
                clock_1Hz                               : OUT   STD_LOGIC);
154
        end component;
155
 
156
        component lcd
157
        port(
158 18 rrred
                clk, reset                                                      : in std_logic;
159
                SF_D                                                                    : out std_logic_vector(3 downto 0);
160 11 rrred
                LCD_E, LCD_RS, LCD_RW, SF_CE0 : out std_logic;
161 18 rrred
                lcd_addr                                                                : out std_logic_vector(4 downto 0);
162
                lcd_char                                                                : in std_logic_vector(7 downto 0));
163 11 rrred
        end component;
164
 
165
        component lcdvram
166
        port (
167 18 rrred
                addra   : IN std_logic_VECTOR(4 downto 0);
168
                addrb   : IN std_logic_VECTOR(4 downto 0);
169
                clka    : IN std_logic;
170
                clkb    : IN std_logic;
171
                dina    : IN std_logic_VECTOR(7 downto 0);
172
                doutb   : OUT std_logic_VECTOR(7 downto 0);
173
                wea     : IN std_logic);
174 11 rrred
        end component;
175
 
176
        component rom
177
        port (
178 18 rrred
                Clk     : in std_logic;
179
                A               : in std_logic_vector(11 downto 0);
180
                D               : out std_logic_vector(7 downto 0));
181 11 rrred
        end component;
182
 
183
        component ps2kbd
184
        PORT (
185
                        keyboard_clk    : inout std_logic;
186
                        keyboard_data   : inout std_logic;
187 18 rrred
                        clock                           : in std_logic;
188
                        clkdelay                        : in std_logic;
189
                        reset                           : in std_logic;
190
                        read                            : in std_logic;
191 11 rrred
                        scan_ready              : out std_logic;
192
                        ps2_ascii_code  : out std_logic_vector(7 downto 0));
193
        end component;
194
 
195 18 rrred
        component vram
196
                port (
197
                addra   : IN std_logic_VECTOR(10 downto 0);
198
                addrb   : IN std_logic_VECTOR(10 downto 0);
199
                clka    : IN std_logic;
200
                clkb    : IN std_logic;
201
                dina    : IN std_logic_VECTOR(7 downto 0);
202
                doutb   : OUT std_logic_VECTOR(7 downto 0);
203
                wea     : IN std_logic);
204
        end component;
205 11 rrred
 
206 18 rrred
        COMPONENT video
207
        PORT(   CLOCK_25                : IN STD_LOGIC;
208
                        VRAM_DATA       : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
209
                        VRAM_ADDR       : OUT STD_LOGIC_VECTOR(12 DOWNTO 0);
210
                        VRAM_CLOCK      : OUT STD_LOGIC;
211
                        VRAM_WREN       : OUT STD_LOGIC;
212 11 rrred
                        VGA_R,
213
                        VGA_G,
214
                        VGA_B                   : OUT STD_LOGIC;
215
                        VGA_HS,
216 18 rrred
                        VGA_VS          : OUT STD_LOGIC);
217 11 rrred
        END COMPONENT;
218
 
219
        signal MREQ_n   : std_logic;
220
        signal IORQ_n   : std_logic;
221
        signal RD_n             : std_logic;
222
        signal WR_n             : std_logic;
223
        signal MWr_n    : std_logic;
224
        signal Rst_n_s  : std_logic;
225
        signal Clk_Z80  : std_logic;
226
        signal DI_CPU   : std_logic_vector(7 downto 0);
227
        signal DO_CPU   : std_logic_vector(7 downto 0);
228 18 rrred
        signal A                        : std_logic_vector(15 downto 0);
229 11 rrred
        signal One              : std_logic;
230
 
231
        signal D_ROM    : std_logic_vector(7 downto 0);
232
 
233 18 rrred
        signal clk25mhz         : std_logic;
234 11 rrred
        signal clk100hz         : std_logic;
235 18 rrred
        signal clk10hz                  : std_logic;
236
        signal clk1hz                   : std_logic;
237 11 rrred
 
238 18 rrred
        signal vram_addra               : std_logic_vector(15 downto 0);
239
        signal vram_addrb               : std_logic_vector(15 downto 0);
240
        signal vram_dina                        : std_logic_vector(7 downto 0);
241
        signal vram_dinb                        : std_logic_vector(7 downto 0);
242
        signal vram_douta               : std_logic_vector(7 downto 0);
243
        signal vram_doutb               : std_logic_vector(7 downto 0);
244
        signal vram_wea                 : std_logic;
245
        signal vram_web                 : std_logic;
246
        signal vram_clka                        : std_logic;
247
        signal vram_clkb                        : std_logic;
248 11 rrred
 
249 18 rrred
        -- sram signals
250
        signal sram_addr                : std_logic_vector(15 downto 0);
251
        signal sram_din         : std_logic_vector(7 downto 0);
252
        signal sram_dout                : std_logic_vector(7 downto 0);
253
        signal sram_we                  : std_logic;
254
 
255 11 rrred
        -- LCD signals
256
        signal lcd_wea                  : std_logic;
257
        signal lcd_addra                : std_logic_vector(4 downto 0);
258
        signal lcd_addrb                : std_logic_vector(4 downto 0);
259
        signal lcd_dina         : std_logic_vector(7 downto 0);
260
        signal lcd_doutb                : std_logic_vector(7 downto 0);
261
 
262
        -- VGA conversion from 4 bits to 8 bit
263
        signal VGA_Rs, VGA_Gs, VGA_Bs   : std_logic_vector(3 downto 0);
264
        signal VGA_HSs, VGA_VSs                 : std_logic;
265
 
266
        -- PS/2 Keyboard
267
        signal ps2_read                                 : std_logic;
268
        signal ps2_scan_ready                   : std_logic;
269
        signal ps2_ascii_sig                            : std_logic_vector(7 downto 0);
270
        signal ps2_ascii_reg1                   : std_logic_vector(7 downto 0);
271
        signal ps2_ascii_reg                            : std_logic_vector(7 downto 0);
272
 
273
begin
274
 
275
        Rst_n_s <= not KEY(3);
276
 
277 18 rrred
        LEDG <= DO_CPU when (IORQ_n = '0' and Wr_n = '0' and A(7 downto 0) = x"01");
278 11 rrred
 
279 18 rrred
--      Write into VRAM
280
        vram_addra <= A - x"2000" when (A >= x"2000" and A < x"2800");
281
        vram_wea <= '0' when (A >= x"2000" and A < x"2800" and Wr_n = '0' and MReq_n = '0') else '1';
282
        vram_dina <= DO_CPU when (A >= x"2000" and A < x"2800" and Wr_n = '0' and MReq_n = '0');
283
 
284
-- Write into LCD video ram
285
        lcd_addra <= A - x"3FE0" when (A >= x"3FE0" and A < x"4000" and MReq_n = '0');
286
        lcd_wea <= '0' when (A >= x"3FE0" and A < x"4000" and Wr_n = '0' and MReq_n = '0') else '1';
287
        lcd_dina <= DO_CPU when (A >= x"3FE0" and A < x"4000" and Wr_n = '0' and MReq_n = '0');
288
 
289
-- Write into SRAM
290
        sram_addr <= A - x"4000" when (A >= x"4000" and A <= x"7FFF");
291
        sram_we <= '0' when (A >= x"4000" and A <= x"7FFF" and Wr_n = '0' and MReq_n = '0') else '1';
292
        sram_din <= DO_CPU when (A >= x"4000" and A <= x"7FFF" and Wr_n = '0' and MReq_n = '0');
293
 
294
        DI_CPU <= sram_dout when (Rd_n = '0' and MReq_n = '0' and A >= x"4000") else
295
                        D_ROM when (Rd_n = '0' and MReq_n = '0' and A < x"2000") else
296 11 rrred
                        ("0000" & SW) when (IORQ_n = '0' and Rd_n = '0' and A(7 downto 0) = x"20") else
297
                        ("0000" & KEY) when (IORQ_n = '0' and Rd_n = '0' and A(7 downto 0) = x"30") else
298 18 rrred
                        ps2_ascii_reg when (IORQ_n = '0' and Rd_n = '0' and A(7 downto 0) = x"80") else
299
                        "ZZZZZZZZ";
300 11 rrred
 
301
        -- the following three processes deals with different clock domain signals
302
        ps2_process1: process(CLOCK_50)
303
        begin
304
                if CLOCK_50'event and CLOCK_50 = '1' then
305
                        if ps2_read = '1' then
306
                                if ps2_ascii_sig /= x"FF" then
307
                                        ps2_read <= '0';
308
                                        ps2_ascii_reg1 <= "00000000";
309
                                end if;
310
                        elsif ps2_scan_ready = '1' then
311
                                if ps2_ascii_sig = x"FF" then
312
                                        ps2_read <= '1';
313
                                else
314
                                        ps2_ascii_reg1 <= ps2_ascii_sig;
315
                                end if;
316
                        end if;
317
                end if;
318
        end process;
319
 
320
        ps2_process2: process(Clk_Z80)
321
        begin
322
                if Clk_Z80'event and Clk_Z80 = '1' then
323
                        ps2_ascii_reg <= ps2_ascii_reg1;
324
                end if;
325
        end process;
326
 
327
        One <= '1';
328 18 rrred
        z80_inst: T80se
329 11 rrred
                port map (
330
                        M1_n => open,
331
                        MREQ_n => MReq_n,
332
                        IORQ_n => IORq_n,
333
                        RD_n => Rd_n,
334
                        WR_n => Wr_n,
335
                        RFSH_n => open,
336
                        HALT_n => open,
337
                        WAIT_n => One,
338
                        INT_n => One,
339
                        NMI_n => One,
340
                        RESET_n => Rst_n_s,
341
                        BUSRQ_n => One,
342
                        BUSAK_n => open,
343
                        CLK_n => Clk_Z80,
344 18 rrred
                        CLKEN => One,
345 11 rrred
                        A => A,
346
                        DI => DI_CPU,
347
                        DO => DO_CPU
348
                );
349 18 rrred
 
350
        video_out_inst: video port map (
351
                        CLOCK_25                        => clk25mhz,
352
                        VRAM_DATA               => vram_doutb,
353
                        VRAM_ADDR               => vram_addrb(12 downto 0),
354
                        VRAM_CLOCK              => vram_clkb,
355
                        VRAM_WREN               => vram_web,
356 11 rrred
                        VGA_R                           => VGA_R,
357
                        VGA_G                           => VGA_G,
358
                        VGA_B                           => VGA_B,
359
                        VGA_HS                  => VGA_HS,
360
                        VGA_VS                  => VGA_VS
361
        );
362
 
363
        vram_inst: vram port map (
364
                clka            => Clk_Z80,
365 18 rrred
                clkb            => vram_clkb,
366
      wea       => vram_wea,
367
      addra             => vram_addra(10 downto 0),
368
      addrb             => vram_addrb(10 downto 0),
369
      dina      => vram_dina,
370
                doutb           => vram_doutb
371 11 rrred
        );
372
 
373
        rom_inst: rom
374
                port map (
375 18 rrred
                        Clk => Clk_Z80,
376
                        A       => A(11 downto 0),
377
                        D       => D_ROM
378 11 rrred
                );
379
 
380
        ps2_kbd_inst : ps2kbd PORT MAP (
381
                keyboard_clk    => PS2_CLK,
382
                keyboard_data   => PS2_DAT,
383
                clock                   => CLOCK_50,
384
                clkdelay                => clk100hz,
385
                reset                   => Rst_n_s,
386
                read                    => ps2_read,
387
                scan_ready              => ps2_scan_ready,
388
                ps2_ascii_code  => ps2_ascii_sig
389
        );
390
 
391 18 rrred
        clk25mhz_proc: process (CLOCK_50)
392 11 rrred
   begin
393
                if CLOCK_50'event and CLOCK_50 = '1' then
394 18 rrred
        clk25mhz <= not clk25mhz;
395 11 rrred
                end if;
396
   end process;
397
 
398
   clkdiv_inst: clk_div
399
                port map (
400 18 rrred
                clock_25Mhz             => clk25mhz,
401 11 rrred
                clock_1MHz              => open,
402
                clock_100KHz    => open,
403
                clock_10KHz             => open,
404
                clock_1KHz              => open,
405
                clock_100Hz             => clk100hz,
406
                clock_10Hz              => clk10hz,
407
                clock_1Hz               => clk1hz
408 18 rrred
        );
409
 
410
        clock_z80_inst : Clock_357Mhz
411
        port map (
412
                clock_50Mhz             => CLOCK_50,
413
                clock_357Mhz    => Clk_Z80
414
        );
415
 
416 11 rrred
        lcd_inst: lcd
417
        port map (
418
                clk                     => CLOCK_50,
419
                reset                   => not Rst_n_s,
420
                SF_D                    => SF_D,
421
                LCD_E                   => LCD_E,
422
                LCD_RS          => LCD_RS,
423
                LCD_RW          => LCD_RW,
424
                SF_CE0          => SF_CE0,
425
                lcd_addr                => lcd_addrb,
426
                lcd_char                => lcd_doutb
427
        );
428
 
429
        lcdvram_inst : lcdvram
430
                port map (
431
                        addra => lcd_addra,
432
                        addrb => lcd_addrb,
433
                        clka => Clk_Z80,
434
                        clkb => CLOCK_50,
435
                        dina => lcd_dina,
436
                        doutb => lcd_doutb,
437
                        wea => lcd_wea
438
                );
439 18 rrred
 
440
        ram16k_inst : sram16k
441
                port map (
442
                        addr => sram_addr(13 downto 0),
443
                        clk => Clk_Z80,
444
                        din => sram_din,
445
                        dout => sram_dout,
446
                        we => sram_we
447
        );
448 11 rrred
 
449
end;

powered by: WebSVN 2.1.0

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