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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [System09_Xess_XSA-3S1000/] [System09_Xess_XSA-3S1000_dual.vhd] - Blame information for rev 201

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 201 davidgb
--===========================================================================----
2
--
3
--  S Y N T H E Z I A B L E    System09 - SOC.
4
--
5
--  www.OpenCores.Org - February 2007
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : System09_Xess_XSA-3S1000.vhd
9
--
10
-- Purpose        : Top level file for 6809 compatible system on a chip
11
--                  Designed with Xilinx XC3S1000 Spartan 3 FPGA.
12
--                  Implemented With XESS XSA-3S1000 FPGA board.
13
--                  *** Note ***
14
--                  This configuration can run Flex9 however it only has
15
--                  32k bytes of user memory and the VDU is monochrome
16
--                  The design needs to be updated to use the SDRAM on 
17
--                  the XSA-3S1000 board.
18
--                  This configuration also lacks a DAT so cannot use
19
--                  the RAM Disk features of SYS09BUG.
20
--
21
-- Dependencies   : ieee.Std_Logic_1164
22
--                  ieee.std_logic_unsigned
23
--                  ieee.std_logic_arith
24
--                  ieee.numeric_std
25
--                  unisim.vcomponents
26
--
27
-- Uses           : mon_rom    (sys09bug_rom4k_b16.vhd) Sys09Bug Monitor ROM
28
--                  cpu09      (cpu09.vhd)          CPU core
29
--                  ACIA_6850  (acia6850.vhd)      ACIA / UART
30
--                  ACIA_Clock (ACIA_Clock.vhd)      ACIA clock.
31
--                  keyboard   (keyboard.vhd)        PS/2 Keyboard interface
32
--                             (ps2_keyboard.vhd)
33
--                             (keymap_rom_slice.vhd) Key map table 
34
--                  vdu8_mono  (vdu8_mono.vhd)        Monochrome VDU
35
--                             (char_rom2k_b16.vhd)
36
--                             (ram2k_b16.vhd)
37
--                  timer      (timer.vhd)            Interrupt timer
38
--                  trap       (trap.vhd)             Bus condition trap logic
39
--                  flex_ram   (flex9_ram8k_b16.vhd)  Flex operating system
40
--                  ram_32K    (ram32k_b16.vhd)       32 KBytes of Block RAM
41
--                  
42
-- 
43
-- Author         : John E. Kent      
44
--                  dilbert57@opencores.org      
45
--
46
-- Memory Map     :
47
--
48
-- $0000 - User program RAM (32K Bytes)
49
-- $C000 - Flex Operating System memory (8K Bytes)
50
-- $E000 - ACIA (SWTPc)
51
-- $E010 - Reserved for FD1771 FDC (SWTPc)
52
-- $E020 - Keyboard
53
-- $E030 - VDU
54
-- $E040 - IDE / Compact Flash interface
55
-- $E050 - Timer
56
-- $E060 - Bus trap
57
-- $E070 - Reserced for Parallel I/O (B5-X300)
58
-- $E080 - Reserved for 6821 PIA (?) (SWTPc)
59
-- $E090 - Reserved for 6840 PTM (?) (SWTPc)
60
-- $F000 - Sys09Bug monitor Program (4K Bytes)
61
--
62
--===========================================================================----
63
--
64
-- Revision History:
65
--===========================================================================--
66
-- Version 0.1 - 20 March 2003
67
-- Version 0.2 - 30 March 2003
68
-- Version 0.3 - 29 April 2003
69
-- Version 0.4 - 29 June 2003
70
--
71
-- Version 0.5 - 19 July 2003
72
-- prints out "Hello World"
73
--
74
-- Version 0.6 - 5 September 2003
75
-- Runs SBUG
76
--
77
-- Version 1.0- 6 Sep 2003 - John Kent
78
-- Inverted SysClk
79
-- Initial release to Open Cores
80
--
81
-- Version 1.1 - 17 Jan 2004 - John Kent
82
-- Updated miniUart.
83
--
84
-- Version 1.2 - 25 Jan 2004 - John Kent
85
-- removed signals "test_alu" and "test_cc" 
86
-- Trap hardware re-instated.
87
--
88
-- Version 1.3 - 11 Feb 2004 - John Kent
89
-- Designed forked off to produce System09_VDU
90
-- Added VDU component
91
-- VDU runs at 25MHz and divides the clock by 2 for the CPU
92
-- UART Runs at 57.6 Kbps
93
--
94
-- Version 2.0 - 2 September 2004 - John Kent
95
-- ported to Digilent Xilinx Spartan3 starter board
96
-- removed Compact Flash and Trap Logic.
97
-- Replaced SBUG with KBug9s
98
--
99
-- Version 3.0 - 29th August 2006 - John Kent
100
-- Adapted to XSA-3S1000 board.
101
-- Removed DAT and miniUART.
102
-- Used 32KBytes of Block RAM.
103
--
104
-- Version 3.1 - 15th January 2007 - John Kent
105
-- Modified vdu8 interface
106
-- Added a clock divider
107
--
108
-- Version 3.2 - 25th February 2007 - John Kent
109
-- reinstated ACIA_6850 and ACIA_Clock
110
-- Updated VDU8 & Keyboard with generic parameters
111
-- Defined Constants for clock speed calculations
112
--
113
-- Version 3.3 - 1st July 2007 - John Kent
114
-- Made VDU mono to save on one RAMB16
115
-- Used distributed memory for Key Map ROM to save one RAMB16
116
-- Added Flex RAM at $C000 to $DFFF using 4 spare RAMB16s
117
-- Added timer and trap logic
118
-- Added IDE Interface for Compact Flash
119
-- Replaced KBug9s and stack with Sys09Bug.
120
--
121
-- Version 4.0 - 1st February 2008 - John kent
122
-- Replaced Block RAM with SDRAM Interface
123
-- Modified Hold timing for SDRAM
124
-- Added CF and Ethernet interface 
125
-- via the 16 bit peripheral bus at $E100
126
--
127
-- Version 4.1 - 11 Feb 2021 - David Burnette
128
-- Removed RS-232 handshake on XST-3.0 board.
129
-- Instead, using the extra 2 pins to implement
130
-- a second ACIA interface.
131
--
132
--===========================================================================--
133
library ieee;
134
   use ieee.std_logic_1164.all;
135
   use IEEE.STD_LOGIC_ARITH.ALL;
136
   use IEEE.STD_LOGIC_UNSIGNED.ALL;
137
   use ieee.numeric_std.all;
138
library work;
139
   use work.common.all;
140
   use WORK.xsasdram.all;
141
library unisim;
142
   use unisim.vcomponents.all;
143
 
144
entity system09 is
145
  port(
146
    CLKA         : in  Std_Logic;  -- 100MHz Clock input
147
--    CLKB         : in  Std_Logic;  -- 50MHz Clock input
148
    SW2_N        : in  Std_logic;  -- Master Reset input (active low)
149
    SW3_N        : in  Std_logic;  -- Non Maskable Interrupt input (active low)
150
 
151
    -- PS/2 Keyboard
152
    ps2_clk      : inout Std_logic;
153
    ps2_dat      : inout Std_Logic;
154
 
155
    -- CRTC output signals
156
    vga_vsync_n  : out Std_Logic;
157
    vga_hsync_n  : out Std_Logic;
158
    vga_blue     : out std_logic_vector(2 downto 0);
159
    vga_green    : out std_logic_vector(2 downto 0);
160
    vga_red      : out std_logic_vector(2 downto 0);
161
 
162
    -- RS232 Port
163
    RS232_RXD    : in  Std_Logic;
164
    RS232_TXD    : out Std_Logic;
165
--  RS232_CTS    : in  Std_Logic;
166
--  RS232_RTS    : out Std_Logic;
167
 
168
    -- For XST 3.0 board, pull the jumpers and tie to a PmodRS232
169
    RS232b_RXD   : in  Std_logic;
170
    RS232b_TXD   : out Std_logic;
171
 
172
    -- Status 7 segment LED
173
    S            : out std_logic_vector(7 downto 0);
174
 
175
    -- SDRAM side
176
    SDRAM_clkfb  : in  std_logic;            -- feedback SDRAM clock after PCB delays
177
    SDRAM_clkout : out std_logic;            -- clock to SDRAM
178
    SDRAM_CKE    : out std_logic;            -- clock-enable to SDRAM
179
    SDRAM_CS_N   : out std_logic;            -- chip-select to SDRAM
180
    SDRAM_RAS_N  : out std_logic;            -- SDRAM row address strobe
181
    SDRAM_CAS_N  : out std_logic;            -- SDRAM column address strobe
182
    SDRAM_WE_N   : out std_logic;            -- SDRAM write enable
183
    SDRAM_BA     : out std_logic_vector(1 downto 0);  -- SDRAM bank address
184
    SDRAM_A      : out std_logic_vector(12 downto 0);  -- SDRAM row/column address
185
    SDRAM_D      : inout  std_logic_vector(15 downto 0);  -- data from SDRAM
186
    SDRAM_DQMH   : out std_logic;            -- enable upper-byte of SDRAM databus if true
187
    SDRAM_DQML   : out std_logic;            -- enable lower-byte of SDRAM databus if true
188
 
189
    -- Peripheral I/O bus $E100 - $E1FF
190
    PB_RD_N      : out std_logic;
191
    PB_WR_N      : out std_logic;
192
    PB_A         : out std_logic_vector(4 downto 0);
193
    PB_D         : inout std_logic_vector(15 downto 0);
194
 
195
    -- IDE Compact Flash $E100 - $E13F
196
    ide_dmack_n  : out std_logic;
197
    ide_cs0_n    : out std_logic;
198
    ide_cs1_n    : out std_logic;
199
 
200
    -- Ethernet $E140 - $E17F
201
    ether_cs_n   : out std_logic;
202
    ether_aen    : out std_logic; -- Ethernet address enable not 
203
    ether_bhe_n  : out std_logic; -- Ethernet bus high enable 
204
    ether_clk    : in  std_logic; -- Ethernet clock 
205
    ether_rdy    : in  std_logic; -- Ethernet ready
206
    ether_irq    : in  std_logic; -- Ethernet irq - Shared with BAR6
207
 
208
    -- Slot 1 $E180 - $E1BF
209
    slot1_cs_n   : out std_logic;
210
--  slot1_irq    : in  std_logic;
211
 
212
    -- Slot 2 $E1C0 - $E1FF
213
    slot2_cs_n   : out std_logic;
214
--  slot2_irq    : in  std_logic;
215
 
216
-- CPU Debug Interface signals
217
--    cpu_reset_o     : out Std_Logic;
218
--    cpu_clk_o       : out Std_Logic;
219
--    cpu_rw_o        : out std_logic;
220
--    cpu_vma_o       : out std_logic;
221
--    cpu_halt_o      : out std_logic;
222
--    cpu_hold_o      : out std_logic;
223
--    cpu_firq_o      : out std_logic;
224
--    cpu_irq_o       : out std_logic;
225
--    cpu_nmi_o       : out std_logic;
226
--    cpu_addr_o      : out std_logic_vector(15 downto 0);
227
--    cpu_data_in_o   : out std_logic_vector(7 downto 0);
228
--    cpu_data_out_o  : out std_logic_vector(7 downto 0);
229
 
230
    -- Disable Flash
231
    FLASH_CE_N   : out std_logic
232
  );
233
end system09;
234
 
235
-------------------------------------------------------------------------------
236
-- Architecture for System09
237
-------------------------------------------------------------------------------
238
architecture rtl of system09 is
239
 
240
  -----------------------------------------------------------------------------
241
  -- constants
242
  -----------------------------------------------------------------------------
243
 
244
  -- SDRAM
245
  constant MEM_CLK_FREQ         : natural := 100_000; -- operating frequency of Memory in KHz
246
  constant SYS_CLK_DIV          : real    := 2.0;    -- divisor for FREQ (can only be 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 8.0 or 16.0)
247
  constant PIPE_EN              : boolean := false;  -- if true, enable pipelined read operations
248
  constant MAX_NOP              : natural := 10000;  -- number of NOPs before entering self-refresh
249
  constant MULTIPLE_ACTIVE_ROWS : boolean := false;  -- if true, allow an active row in each bank
250
  constant DATA_WIDTH           : natural := 16;     -- host & SDRAM data width
251
  constant NROWS                : natural := 8192;   -- number of rows in SDRAM array
252
  constant NCOLS                : natural := 512;    -- number of columns in SDRAM array
253
  constant HADDR_WIDTH          : natural := 24;     -- host-side address width
254
  constant SADDR_WIDTH          : natural := 13;     -- SDRAM-side address width
255
 
256
  constant SYS_CLK_FREQ         : natural := ((MEM_CLK_FREQ*2)/integer(SYS_CLK_DIV*2.0))*1000;  -- FPGA System Clock
257
  constant CPU_CLK_FREQ         : natural := 25_000_000;  -- CPU Clock (Hz)
258
  constant CPU_CLK_DIV          : natural := (SYS_CLK_FREQ/CPU_CLK_FREQ);
259
  constant VGA_CLK_FREQ         : natural := 25_000_000;  -- VGA Pixel Clock
260
  constant VGA_CLK_DIV          : natural := ((MEM_CLK_FREQ*1000)/VGA_CLK_FREQ);
261
  constant BAUD_RATE            : integer := 57600;     -- Baud Rate
262
  constant ACIA_CLK_FREQ        : integer := BAUD_RATE * 16;
263
 
264
  constant TRESET               : natural := 300;      -- min initialization interval (us)
265
  constant RST_CYCLES           : natural := 1+(TRESET*(MEM_CLK_FREQ/1_000));  -- SDRAM power-on initialization interval
266
 
267
  type hold_state_type is ( hold_release_state, hold_request_state );
268
 
269
  -----------------------------------------------------------------------------
270
  -- Signals
271
  -----------------------------------------------------------------------------
272
  -- BOOT ROM
273
  signal rom_cs         : Std_logic;
274
  signal rom_data_out   : Std_Logic_Vector(7 downto 0);
275
 
276
  -- Flex Memory & Monitor Stack
277
  signal flex_cs        : Std_logic;
278
  signal flex_data_out  : Std_Logic_Vector(7 downto 0);
279
 
280
  -- ACIA/UART Interface signals
281
  signal acia_data_out  : Std_Logic_Vector(7 downto 0);
282
  signal acia_cs        : Std_Logic;
283
  signal acia_irq       : Std_Logic;
284
  signal acia_clk       : Std_Logic;
285
  signal rxd            : Std_Logic;
286
  signal txd            : Std_Logic;
287
  signal DCD_n          : Std_Logic;
288
  signal RTS_n          : Std_Logic;
289
  signal CTS_n          : Std_Logic;
290
 
291
  -- Second ACIA interface
292
  signal aciaB_data_out : Std_Logic_Vector(7 downto 0);
293
  signal aciaB_cs       : Std_Logic;
294
  signal aciaB_irq      : Std_Logic;
295
  signal rxdB           : Std_Logic;
296
  signal txdB           : Std_Logic;
297
  signal DCDB_n         : Std_Logic;
298
  signal RTSB_n         : Std_Logic;
299
  signal CTSB_n         : Std_Logic;
300
 
301
  -- keyboard port
302
  signal keyboard_data_out : std_logic_vector(7 downto 0);
303
  signal keyboard_cs       : std_logic;
304
  signal keyboard_irq      : std_logic;
305
 
306
  -- RAM
307
  signal ram_cs         : std_logic; -- memory chip select
308
  signal ram_data_out   : std_logic_vector(7 downto 0);
309
  signal ram_rd_req     : std_logic; -- ram read request (asynch set on ram read, cleared falling CPU clock edge)
310
  signal ram_wr_req     : std_logic; -- ram write request (set on rising CPU clock edge, asynch clear on acknowledge) 
311
  signal ram_hold       : std_logic; -- hold off slow accesses
312
  signal ram_release    : std_logic; -- Release ram hold
313
 
314
  -- CPU Interface signals
315
  signal cpu_reset      : Std_Logic;
316
  signal cpu_clk        : Std_Logic;
317
  signal cpu_rw         : std_logic;
318
  signal cpu_vma        : std_logic;
319
  signal cpu_halt       : std_logic;
320
  signal cpu_hold       : std_logic;
321
  signal cpu_firq       : std_logic;
322
  signal cpu_irq        : std_logic;
323
  signal cpu_nmi        : std_logic;
324
  signal cpu_addr       : std_logic_vector(15 downto 0);
325
  signal cpu_data_in    : std_logic_vector(7 downto 0);
326
  signal cpu_data_out   : std_logic_vector(7 downto 0);
327
 
328
  -- Dynamic Address Translation
329
  signal dat_cs       : std_logic;
330
  signal dat_addr     : std_logic_vector(7 downto 0);
331
 
332
  -- Video Display Unit
333
  signal vdu_cs         : std_logic;
334
  signal vdu_data_out   : std_logic_vector(7 downto 0);
335
  signal vga_red_o      : std_logic;
336
  signal vga_green_o    : std_logic;
337
  signal vga_blue_o     : std_logic;
338
 
339
  -- timer
340
  signal timer_data_out : std_logic_vector(7 downto 0);
341
  signal timer_cs       : std_logic;
342
  signal timer_irq      : std_logic;
343
 
344
  -- trap
345
  signal trap_cs        : std_logic;
346
  signal trap_data_out  : std_logic_vector(7 downto 0);
347
  signal trap_irq       : std_logic;
348
 
349
  -- Peripheral Bus port
350
  signal pb_data_out   : std_logic_vector(7 downto 0);
351
  signal pb_cs         : std_logic;   -- peripheral bus chip select
352
  signal pb_wru        : std_logic;   -- upper byte write strobe
353
  signal pb_wrl        : std_logic;   -- lower byte write strobe
354
  signal pb_rdu        : std_logic;   -- upper byte read strobe
355
  signal pb_rdl        : std_logic;   -- lower byte read strobe
356
  signal pb_hold       : std_logic;   -- hold peripheral bus access
357
  signal pb_release    : std_logic;   -- release hold of peripheral bus
358
  signal pb_count      : std_logic_vector(3 downto 0); -- hold counter
359
  signal pb_hold_state : hold_state_type;
360
  signal pb_wreg       : std_logic_vector(7 downto 0); -- lower byte write register
361
  signal pb_rreg       : std_logic_vector(7 downto 0); -- lower byte read register
362
 
363
  -- Peripheral chip selects on Peripheral Bus
364
  signal ide_cs        : std_logic; -- IDE CF interface
365
  signal ether_cs      : std_logic; -- Ethernet interface
366
  signal slot1_cs      : std_logic; -- Expansion slot 1
367
  signal slot2_cs      : std_logic; -- Expansion slot 2
368
 
369
  signal rst_i         : std_logic;     -- internal reset signal
370
  signal clk_i         : std_logic;     -- internal master clock signal
371
  signal lock          : std_logic;     -- SDRAM clock DLL lock indicator
372
 
373
  -- signals that go through the SDRAM host-side interface
374
  signal opBegun       : std_logic;        -- SDRAM operation started indicator
375
  signal earlyBegun    : std_logic;        -- SDRAM operation started indicator
376
  signal ramDone       : std_logic;        -- SDRAM operation complete indicator
377
  signal rdDone        : std_logic;        -- SDRAM read operation complete indicator
378
  signal wrDone        : std_logic;        -- SDRAM write operation complete indicator
379
  signal hAddr         : std_logic_vector(HADDR_WIDTH-1 downto 0);  -- host address bus
380
  signal hDIn          : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data to SDRAM
381
  signal hDOut         : std_logic_vector(DATA_WIDTH-1 downto 0);  -- host-side data from SDRAM
382
  signal hRd           : std_logic;        -- host-side read control signal
383
  signal hWr           : std_logic;        -- host-side write control signal
384
  signal hUds          : std_logic;        -- host-side upper data strobe
385
  signal hLds          : std_logic;        -- host-side lower data strobe
386
  signal rdPending     : std_logic;        -- read operation pending in SDRAM pipeline
387
  type ram_type is (ram_state_0,
388
                    ram_state_rd1, ram_state_rd2,
389
                    ram_state_wr1,
390
                    ram_state_3 );
391
  signal ram_state     : ram_type;
392
 
393
  signal CountL        : std_logic_vector(23 downto 0);
394
  signal clk_count     : natural range 0 to CPU_CLK_DIV;
395
  signal Clk25         : std_logic;
396
  signal vga_clk       : std_logic;
397
 
398
-----------------------------------------------------------------
399
--
400
-- CPU09 CPU core
401
--
402
-----------------------------------------------------------------
403
 
404
component cpu09
405
  port (
406
    clk:      in  std_logic;
407
    rst:      in  std_logic;
408
    vma:      out std_logic;
409
    addr:     out std_logic_vector(15 downto 0);
410
    rw:       out std_logic;     -- Asynchronous memory interface
411
    data_out: out std_logic_vector(7 downto 0);
412
    data_in:  in  std_logic_vector(7 downto 0);
413
    irq:      in  std_logic;
414
    firq:     in  std_logic;
415
    nmi:      in  std_logic;
416
    halt:     in  std_logic;
417
    hold:     in  std_logic
418
  );
419
end component;
420
 
421
----------------------------------------
422
--
423
-- 4K Block RAM Monitor ROM
424
-- $F000 - $FFFF
425
--
426
----------------------------------------
427
 
428
component mon_rom
429
  Port (
430
    clk   : in  std_logic;
431
    rst   : in  std_logic;
432
    cs    : in  std_logic;
433
    rw    : in  std_logic;
434
    addr  : in  std_logic_vector (11 downto 0);
435
    data_out : out std_logic_vector (7 downto 0);
436
    data_in : in  std_logic_vector (7 downto 0)
437
  );
438
end component;
439
 
440
----------------------------------------
441
--
442
-- 8KBytes Block RAM for FLEX9
443
-- $C000 - $DFFF
444
--
445
----------------------------------------
446
 
447
component flex_ram
448
  Port (
449
    clk      : in  std_logic;
450
    rst      : in  std_logic;
451
    cs       : in  std_logic;
452
    rw       : in  std_logic;
453
    addr     : in  std_logic_vector (12 downto 0);
454
    data_out    : out std_logic_vector (7 downto 0);
455
    data_in    : in  std_logic_vector (7 downto 0)
456
  );
457
end component;
458
 
459
-----------------------------------------------------------------
460
--
461
-- 6850 Compatible ACIA / UART
462
--
463
-----------------------------------------------------------------
464
 
465
component acia6850
466
  port (
467
    clk      : in  Std_Logic;  -- System Clock
468
    rst      : in  Std_Logic;  -- Reset input (active high)
469
    cs       : in  Std_Logic;  -- miniUART Chip Select
470
    rw       : in  Std_Logic;  -- Read / Not Write
471
    addr     : in  Std_Logic;  -- Register Select
472
    data_in  : in  Std_Logic_Vector(7 downto 0); -- Data Bus In 
473
    data_out : out Std_Logic_Vector(7 downto 0); -- Data Bus Out
474
    irq      : out Std_Logic;  -- Interrupt
475
    RxC      : in  Std_Logic;  -- Receive Baud Clock
476
    TxC      : in  Std_Logic;  -- Transmit Baud Clock
477
    RxD      : in  Std_Logic;  -- Receive Data
478
    TxD      : out Std_Logic;  -- Transmit Data
479
    DCD_n    : in  Std_Logic;  -- Data Carrier Detect
480
    CTS_n    : in  Std_Logic;  -- Clear To Send
481
    RTS_n    : out Std_Logic   -- Request To send
482
  );
483
end component;
484
 
485
-----------------------------------------------------------------
486
--
487
-- ACIA Clock divider
488
--
489
-----------------------------------------------------------------
490
 
491
component ACIA_Clock
492
  generic (
493
    SYS_CLK_FREQ  : integer :=  SYS_CLK_FREQ;
494
    ACIA_CLK_FREQ : integer := ACIA_CLK_FREQ
495
  );
496
  port (
497
    clk      : in  Std_Logic;  -- System Clock Input
498
    ACIA_clk : out Std_logic   -- ACIA Clock output
499
  );
500
end component;
501
 
502
----------------------------------------
503
--
504
-- PS/2 Keyboard
505
--
506
----------------------------------------
507
 
508
component keyboard
509
  generic(
510
    KBD_CLK_FREQ : integer := CPU_CLK_FREQ
511
  );
512
  port(
513
    clk             : in    std_logic;
514
    rst             : in    std_logic;
515
    cs              : in    std_logic;
516
    rw              : in    std_logic;
517
    addr            : in    std_logic;
518
    data_in         : in    std_logic_vector(7 downto 0);
519
    data_out        : out   std_logic_vector(7 downto 0);
520
    irq             : out   std_logic;
521
    kbd_clk         : inout std_logic;
522
    kbd_data        : inout std_logic
523
  );
524
end component;
525
 
526
----------------------------------------
527
--
528
-- Video Display Unit.
529
--
530
----------------------------------------
531
 
532
component vdu8
533
  generic(
534
    VDU_CLK_FREQ           : integer := CPU_CLK_FREQ; -- HZ
535
    VGA_CLK_FREQ           : integer := VGA_CLK_FREQ; -- HZ
536
    VGA_HOR_CHARS          : integer := 80; -- CHARACTERS
537
    VGA_VER_CHARS          : integer := 25; -- CHARACTERS
538
    VGA_PIX_PER_CHAR       : integer := 8;  -- PIXELS
539
    VGA_LIN_PER_CHAR       : integer := 16; -- LINES
540
    VGA_HOR_BACK_PORCH     : integer := 40; -- PIXELS
541
    VGA_HOR_SYNC           : integer := 96; -- PIXELS
542
    VGA_HOR_FRONT_PORCH    : integer := 24; -- PIXELS
543
    VGA_VER_BACK_PORCH     : integer := 13; -- LINES
544
    VGA_VER_SYNC           : integer := 2;  -- LINES
545
    VGA_VER_FRONT_PORCH    : integer := 35  -- LINES
546
  );
547
  port(
548
    -- control register interface
549
    vdu_clk      : in  std_logic;  -- CPU Clock - 25MHz
550
    vdu_rst      : in  std_logic;
551
    vdu_cs       : in  std_logic;
552
    vdu_rw       : in  std_logic;
553
    vdu_addr     : in  std_logic_vector(2 downto 0);
554
    vdu_data_in  : in  std_logic_vector(7 downto 0);
555
    vdu_data_out : out std_logic_vector(7 downto 0);
556
 
557
    -- vga port connections
558
    vga_clk      : in  std_logic; -- VGA Pixel Clock - 25 MHz
559
    vga_red_o    : out std_logic;
560
    vga_green_o  : out std_logic;
561
    vga_blue_o   : out std_logic;
562
    vga_hsync_o  : out std_logic;
563
    vga_vsync_o  : out std_logic
564
  );
565
end component;
566
 
567
----------------------------------------
568
--
569
-- Timer module
570
--
571
----------------------------------------
572
 
573
component timer
574
  port (
575
    clk       : in std_logic;
576
    rst       : in std_logic;
577
    cs        : in std_logic;
578
    rw        : in std_logic;
579
    addr      : in std_logic;
580
    data_in   : in std_logic_vector(7 downto 0);
581
    data_out  : out std_logic_vector(7 downto 0);
582
    irq       : out std_logic
583
  );
584
end component;
585
 
586
------------------------------------------------------------
587
--
588
-- Bus Trap logic
589
--
590
------------------------------------------------------------
591
 
592
component trap
593
  port (
594
    clk        : in  std_logic;
595
    rst        : in  std_logic;
596
    cs         : in  std_logic;
597
    rw         : in  std_logic;
598
    vma        : in  std_logic;
599
    addr       : in  std_logic_vector(15 downto 0);
600
    data_in    : in  std_logic_vector(7 downto 0);
601
    data_out   : out std_logic_vector(7 downto 0);
602
    irq        : out std_logic
603
  );
604
end component;
605
 
606
----------------------------------------
607
--
608
-- Dynamic Address Translation Registers
609
--
610
----------------------------------------
611
 
612
component dat_ram
613
  port (
614
    clk      : in  std_logic;
615
    rst      : in  std_logic;
616
    cs       : in  std_logic;
617
    rw       : in  std_logic;
618
    addr_lo  : in  std_logic_vector(3 downto 0);
619
    addr_hi  : in  std_logic_vector(3 downto 0);
620
    data_in  : in  std_logic_vector(7 downto 0);
621
    data_out : out std_logic_vector(7 downto 0)
622
  );
623
end component;
624
 
625
----------------------------------------
626
--
627
-- SDRAM Controller for XSA-3S1000
628
--
629
----------------------------------------
630
 
631
component XSASDRAMCntl
632
  generic(
633
    FREQ                 :     natural := MEM_CLK_FREQ;-- operating frequency in KHz
634
    CLK_DIV              :     real    := SYS_CLK_DIV; -- divisor for FREQ (can only be 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 8.0 or 16.0)
635
    PIPE_EN              :     boolean := PIPE_EN;     -- if true, enable pipelined read operations
636
    MAX_NOP              :     natural := MAX_NOP;     -- number of NOPs before entering self-refresh
637
    MULTIPLE_ACTIVE_ROWS :     boolean := MULTIPLE_ACTIVE_ROWS;  -- if true, allow an active row in each bank
638
    DATA_WIDTH           :     natural := DATA_WIDTH;  -- host & SDRAM data width
639
    NROWS                :     natural := NROWS;       -- number of rows in SDRAM array
640
    NCOLS                :     natural := NCOLS;       -- number of columns in SDRAM array
641
    HADDR_WIDTH          :     natural := HADDR_WIDTH; -- host-side address width
642
    SADDR_WIDTH          :     natural := SADDR_WIDTH  -- SDRAM-side address width
643
  );
644
  port(
645
    -- host side
646
    clk                  : in  std_logic;  -- master clock
647
    bufclk               : out std_logic;  -- buffered master clock
648
    clk1x                : out std_logic;  -- host clock sync'ed to master clock (and divided if CLK_DIV>1)
649
    clk2x                : out std_logic;  -- double-speed host clock
650
    lock                 : out std_logic;  -- true when host clock is locked to master clock
651
    rst                  : in  std_logic;  -- reset
652
    rd                   : in  std_logic;  -- initiate read operation
653
    wr                   : in  std_logic;  -- initiate write operation
654
    uds                  : in  std_logic;  -- upper data strobe
655
    lds                  : in  std_logic;  -- lower data strobe
656
    earlyOpBegun         : out std_logic;  -- read/write/self-refresh op begun     (async)
657
    opBegun              : out std_logic;  -- read/write/self-refresh op begun (clocked)
658
    rdPending            : out std_logic;  -- read operation(s) are still in the pipeline
659
    done                 : out std_logic;  -- read or write operation is done
660
    rdDone               : out std_logic;  -- read done and data is available
661
    hAddr                : in  std_logic_vector(HADDR_WIDTH-1 downto 0);  -- address from host
662
    hDIn                 : in  std_logic_vector(DATA_WIDTH-1 downto 0);  -- data from host
663
    hDOut                : out std_logic_vector(DATA_WIDTH-1 downto 0);  -- data to host
664
    status               : out std_logic_vector(3 downto 0);  -- diagnostic status of the FSM         
665
 
666
    -- SDRAM side
667
    sclkfb               : in    std_logic;           -- clock from SDRAM after PCB delays
668
    sclk                 : out   std_logic;           -- SDRAM clock sync'ed to master clock
669
    cke                  : out   std_logic;           -- clock-enable to SDRAM
670
    cs_n                 : out   std_logic;           -- chip-select to SDRAM
671
    ras_n                : out   std_logic;           -- SDRAM row address strobe
672
    cas_n                : out   std_logic;           -- SDRAM column address strobe
673
    we_n                 : out   std_logic;           -- SDRAM write enable
674
    ba                   : out   std_logic_vector(1 downto 0);  -- SDRAM bank address bits
675
    sAddr                : out   std_logic_vector(SADDR_WIDTH-1 downto 0);  -- SDRAM row/column address
676
    sData                : inout std_logic_vector(DATA_WIDTH-1 downto 0);  -- SDRAM in/out databus
677
    dqmh                 : out   std_logic;           -- high databits I/O mask
678
    dqml                 : out   std_logic            -- low databits I/O mask
679
  );
680
end component;
681
 
682
--
683
-- Clock buffer
684
--
685
 
686
component BUFG
687
   Port (
688
     i: in std_logic;
689
     o: out std_logic
690
  );
691
end component;
692
 
693
begin
694
 
695
  -----------------------------------------------------------------------------
696
  -- Instantiation of internal components
697
  -----------------------------------------------------------------------------
698
 
699
  my_cpu : cpu09
700
    port map (
701
      clk       => cpu_clk,
702
      rst       => cpu_reset,
703
      vma       => cpu_vma,
704
      addr      => cpu_addr(15 downto 0),
705
      rw        => cpu_rw,
706
      data_out  => cpu_data_out,
707
      data_in   => cpu_data_in,
708
      irq       => cpu_irq,
709
      firq      => cpu_firq,
710
      nmi       => cpu_nmi,
711
      halt      => cpu_halt,
712
      hold      => cpu_hold
713
    );
714
 
715
  my_rom : mon_rom
716
    port map (
717
      clk   => cpu_clk,
718
      rst   => cpu_reset,
719
      cs    => rom_cs,
720
      rw    => '1',
721
      addr  => cpu_addr(11 downto 0),
722
      data_in => cpu_data_out,
723
      data_out => rom_data_out
724
    );
725
 
726
  my_flex : flex_ram
727
    port map (
728
      clk       => cpu_clk,
729
      rst       => cpu_reset,
730
      cs        => flex_cs,
731
      rw        => cpu_rw,
732
      addr      => cpu_addr(12 downto 0),
733
      data_out     => flex_data_out,
734
      data_in     => cpu_data_out
735
    );
736
 
737
  my_acia  : acia6850
738
    port map (
739
      clk       => cpu_clk,
740
      rst       => cpu_reset,
741
      cs        => acia_cs,
742
      rw        => cpu_rw,
743
      addr      => cpu_addr(0),
744
      data_in   => cpu_data_out,
745
      data_out  => acia_data_out,
746
      irq       => acia_irq,
747
      RxC       => acia_clk,
748
      TxC       => acia_clk,
749
      RxD       => rxd,
750
      TxD       => txd,
751
      DCD_n     => dcd_n,
752
      CTS_n     => cts_n,
753
      RTS_n     => rts_n
754
    );
755
 
756
  my_ACIA_Clock : ACIA_Clock
757
    generic map(
758
      SYS_CLK_FREQ  =>  SYS_CLK_FREQ,
759
      ACIA_CLK_FREQ => ACIA_CLK_FREQ
760
    )
761
    port map(
762
      clk        => Clk_i,
763
      acia_clk   => acia_clk
764
    );
765
 
766
  -- Second ACIA
767
  my_aciaB  : acia6850
768
    port map (
769
      clk       => cpu_clk,
770
      rst       => cpu_reset,
771
      cs        => aciaB_cs,
772
      rw        => cpu_rw,
773
      addr      => cpu_addr(0),
774
      data_in   => cpu_data_out,
775
      data_out  => aciaB_data_out,
776
      irq       => aciaB_irq,
777
      RxC       => acia_clk,
778
      TxC       => acia_clk,
779
      RxD       => rxdB,
780
      TxD       => txdB,
781
      DCD_n     => dcdB_n,
782
      CTS_n     => ctsB_n,
783
      RTS_n     => rtsB_n
784
    );
785
 
786
  ----------------------------------------
787
  --
788
  -- PS/2 Keyboard Interface
789
  --
790
  ----------------------------------------
791
  my_keyboard : keyboard
792
    generic map (
793
      KBD_CLK_FREQ => CPU_CLK_FREQ
794
    )
795
    port map(
796
      clk          => cpu_clk,
797
      rst          => cpu_reset,
798
      cs           => keyboard_cs,
799
      rw           => cpu_rw,
800
      addr         => cpu_addr(0),
801
      data_in      => cpu_data_out(7 downto 0),
802
      data_out     => keyboard_data_out(7 downto 0),
803
      irq          => keyboard_irq,
804
      kbd_clk      => ps2_clk,
805
      kbd_data     => ps2_dat
806
    );
807
 
808
  ----------------------------------------
809
  --
810
  -- Video Display Unit instantiation
811
  --
812
  ----------------------------------------
813
  my_vdu : vdu8
814
    generic map(
815
      VDU_CLK_FREQ           => CPU_CLK_FREQ, -- HZ
816
      VGA_CLK_FREQ           => VGA_CLK_FREQ, -- HZ
817
      VGA_HOR_CHARS          => 80, -- CHARACTERS
818
      VGA_VER_CHARS          => 25, -- CHARACTERS
819
      VGA_PIX_PER_CHAR       => 8,  -- PIXELS
820
      VGA_LIN_PER_CHAR       => 16, -- LINES
821
      VGA_HOR_BACK_PORCH     => 40, -- PIXELS
822
      VGA_HOR_SYNC           => 96, -- PIXELS
823
      VGA_HOR_FRONT_PORCH    => 24, -- PIXELS
824
      VGA_VER_BACK_PORCH     => 13, -- LINES
825
      VGA_VER_SYNC           => 2,  -- LINES
826
      VGA_VER_FRONT_PORCH    => 35  -- LINES
827
    )
828
    port map(
829
      -- Control Registers
830
      vdu_clk       => cpu_clk,               -- 12.5 MHz System Clock in
831
      vdu_rst       => cpu_reset,
832
      vdu_cs        => vdu_cs,
833
      vdu_rw        => cpu_rw,
834
      vdu_addr      => cpu_addr(2 downto 0),
835
      vdu_data_in   => cpu_data_out,
836
      vdu_data_out  => vdu_data_out,
837
      -- vga port connections
838
      vga_clk       => vga_clk,               -- 25 MHz VDU pixel clock
839
      vga_red_o     => vga_red_o,
840
      vga_green_o   => vga_green_o,
841
      vga_blue_o    => vga_blue_o,
842
      vga_hsync_o   => vga_hsync_n,
843
      vga_vsync_o   => vga_vsync_n
844
   );
845
 
846
  ----------------------------------------
847
  --
848
  -- Timer Module
849
  --
850
  ----------------------------------------
851
  my_timer  : timer
852
    port map (
853
      clk       => cpu_clk,
854
      rst       => cpu_reset,
855
      cs        => timer_cs,
856
      rw        => cpu_rw,
857
      addr      => cpu_addr(0),
858
      data_in   => cpu_data_out,
859
      data_out  => timer_data_out,
860
      irq       => timer_irq
861
    );
862
 
863
  ----------------------------------------
864
  --
865
  -- Bus Trap Interrupt logic
866
  --
867
  ----------------------------------------
868
  my_trap : trap
869
    port map (
870
      clk        => cpu_clk,
871
      rst        => cpu_reset,
872
      cs         => trap_cs,
873
      rw         => cpu_rw,
874
      vma        => cpu_vma,
875
      addr       => cpu_addr,
876
      data_in    => cpu_data_out,
877
      data_out   => trap_data_out,
878
      irq        => trap_irq
879
    );
880
 
881
  my_dat : dat_ram
882
    port map (
883
      clk       => cpu_clk,
884
      rst       => cpu_reset,
885
      cs        => dat_cs,
886
      rw        => cpu_rw,
887
      addr_hi   => cpu_addr(15 downto 12),
888
      addr_lo   => cpu_addr(3 downto 0),
889
      data_in   => cpu_data_out,
890
      data_out  => dat_addr(7 downto 0)
891
    );
892
 
893
  ------------------------------------------------------------------------
894
  -- Instantiate the SDRAM controller that connects to the memory tester
895
  -- module and interfaces to the external SDRAM chip.
896
  ------------------------------------------------------------------------
897
  u1 : xsaSDRAMCntl
898
    generic map(
899
      FREQ                 => MEM_CLK_FREQ,
900
      CLK_DIV              => SYS_CLK_DIV,
901
      PIPE_EN              => PIPE_EN,
902
      MAX_NOP              => MAX_NOP,
903
      MULTIPLE_ACTIVE_ROWS => MULTIPLE_ACTIVE_ROWS,
904
      DATA_WIDTH           => DATA_WIDTH,
905
      NROWS                => NROWS,
906
      NCOLS                => NCOLS,
907
      HADDR_WIDTH          => HADDR_WIDTH,
908
      SADDR_WIDTH          => SADDR_WIDTH
909
    )
910
    port map(
911
      -- Host Side
912
      clk                  => CLKA,     -- master clock from external clock source (unbuffered)
913
      bufclk               => open,     -- buffered master clock output
914
      clk1x                => clk_i,    -- synchronized master clock (accounts for delays to external SDRAM)
915
      clk2x                => open,     -- synchronized doubled master clock
916
      lock                 => lock,     -- DLL lock indicator
917
      rst                  => rst_i,    -- reset
918
      rd                   => hRd,      -- host-side SDRAM read control from memory tester
919
      wr                   => hWr,      -- host-side SDRAM write control from memory tester
920
      uds                  => hUds,     -- host-side SDRAM upper data strobe
921
      lds                  => hLds,     -- host-side SDRAM lower data strobe
922
      rdPending            => rdPending,-- read operation to SDRAM is in progress
923
      opBegun              => opBegun,  -- indicates memory read/write has begun
924
      earlyOpBegun         => earlyBegun,  -- early indicator that memory operation has begun
925
      rdDone               => rdDone,   -- indicates SDRAM memory read operation is done
926
      done                 => ramDone, -- indicates SDRAM memory read or write operation is done
927
      hAddr                => hAddr,    -- host-side address from memory tester to SDRAM
928
      hDIn                 => hDIn,     -- test data pattern from memory tester to SDRAM
929
      hDOut                => hDOut,    -- SDRAM data output to memory tester
930
      status               => open,     -- SDRAM controller state (for diagnostics)
931
      -- SDRAM Side
932
      sclkfb               => SDRAM_clkfb,    -- clock feedback with added external PCB delays
933
      sclk                 => SDRAM_clkout,   -- synchronized clock to external SDRAM
934
      cke                  => SDRAM_cke,      -- SDRAM clock enable
935
      cs_n                 => SDRAM_cs_n,     -- SDRAM chip-select
936
      ras_n                => SDRAM_ras_n,    -- SDRAM RAS
937
      cas_n                => SDRAM_cas_n,    -- SDRAM CAS
938
      we_n                 => SDRAM_we_n,     -- SDRAM write-enable
939
      ba                   => SDRAM_ba,       -- SDRAM bank address
940
      sAddr                => SDRAM_A,        -- SDRAM address
941
      sData                => SDRAM_D,        -- SDRAM databus
942
      dqmh                 => SDRAM_dqmh,     -- SDRAM DQMH
943
      dqml                 => SDRAM_dqml      -- SDRAM DQML
944
    );
945
 
946
  cpu_clk_buffer : BUFG
947
    port map(
948
      i => Clk25,
949
      o => cpu_clk
950
    );
951
 
952
  vga_clk_buffer : BUFG
953
    port map(
954
      i => Clk25,
955
      o => vga_clk
956
    );
957
 
958
  ----------------------------------------------------------------------
959
  --
960
  -- Process to decode memory map
961
  --
962
  ----------------------------------------------------------------------
963
 
964
  mem_decode: process( cpu_addr, cpu_rw, cpu_vma,
965
                     dat_addr,
966
                     rom_data_out,
967
                     flex_data_out,
968
                     acia_data_out,
969
                     aciaB_data_out,
970
                     keyboard_data_out,
971
                     vdu_data_out,
972
                     pb_data_out,
973
                     timer_data_out,
974
                     trap_data_out,
975
                     ram_data_out
976
                     )
977
  begin
978
    cpu_data_in <= (others=>'0');
979
    dat_cs      <= '0';
980
    rom_cs      <= '0';
981
    flex_cs     <= '0';
982
    acia_cs     <= '0';
983
    aciaB_cs     <= '0';
984
    keyboard_cs <= '0';
985
    vdu_cs      <= '0';
986
    timer_cs    <= '0';
987
    trap_cs     <= '0';
988
    pb_cs       <= '0';
989
    ide_cs      <= '0';
990
    ether_cs    <= '0';
991
    slot1_cs    <= '0';
992
    slot2_cs    <= '0';
993
    ram_cs      <= '0';
994
 
995
    if cpu_addr( 15 downto 8 ) = "11111111" then  -- $FFxx
996
      cpu_data_in <= rom_data_out;
997
      dat_cs      <= cpu_vma;              -- write DAT
998
      rom_cs      <= cpu_vma;              -- read  ROM
999
 
1000
    --
1001
    -- Sys09Bug Monitor ROM $F000 - $FFFF
1002
    --
1003
    elsif dat_addr(3 downto 0) = "1111" then -- $XF000 - $XFFFF
1004
      cpu_data_in <= rom_data_out;
1005
      rom_cs      <= cpu_vma;
1006
 
1007
    --
1008
    -- IO Devices $E000 - $E7FF
1009
    --
1010
    elsif dat_addr(3 downto 0) = "1110" then -- $XE000 - $XEFFF
1011
      case cpu_addr(11 downto 8) is
1012
        --
1013
        -- SWTPC peripherals from $E000 to $E0FF
1014
        --
1015
        when "0000" =>
1016
          case cpu_addr(7 downto 4) is
1017
          --
1018
          -- Console Port ACIA $E000 - $E00F
1019
          --
1020
            when "0000" => -- $E000
1021
              if cpu_addr(2) = '0' then
1022
                cpu_data_in <= acia_data_out;   -- $E000
1023
                acia_cs     <= cpu_vma;
1024
              else
1025
                cpu_data_in <= aciaB_data_out;  -- $E004
1026
                aciaB_cs     <= cpu_vma;
1027
              end if;
1028
 
1029
            --
1030
            -- Reserved
1031
            -- Floppy Disk Controller port $E010 - $E01F
1032
            --
1033
 
1034
            --
1035
            -- Keyboard port $E020 - $E02F
1036
            --
1037
            when "0010" => -- $E020
1038
              cpu_data_in <= keyboard_data_out;
1039
              keyboard_cs <= cpu_vma;
1040
 
1041
            --
1042
            -- VDU port $E030 - $E03F
1043
            --
1044
            when "0011" => -- $E030
1045
              cpu_data_in <= vdu_data_out;
1046
              vdu_cs      <= cpu_vma;
1047
 
1048
            --
1049
            -- Reserved SWTPc MP-T Timer $E040 - $E04F
1050
            --
1051
            when "0100" => -- $E040
1052
              cpu_data_in <= (others=> '0');
1053
 
1054
            --
1055
            -- Timer $E050 - $E05F
1056
            --
1057
            when "0101" => -- $E050
1058
              cpu_data_in <= timer_data_out;
1059
              timer_cs    <= cpu_vma;
1060
 
1061
            --
1062
            -- Bus Trap Logic $E060 - $E06F
1063
            --
1064
            when "0110" => -- $E060
1065
              cpu_data_in <= trap_data_out;
1066
              trap_cs     <= cpu_vma;
1067
 
1068
            --
1069
            -- Reserved SWTPc MP-ID PIA Timer/Printer Port $E080 - $E08F
1070
            --
1071
 
1072
            --
1073
            -- Reserved SWTPc MP-ID PTM 6840 Timer Port $E090 - $E09F
1074
            --
1075
 
1076
            --
1077
            -- Remaining 6 slots reserved for non SWTPc Peripherals
1078
            --
1079
            when others => -- $E0A0 to $E0FF
1080
              null;
1081
          end case;
1082
 
1083
        --
1084
        -- XST-3.0 Peripheral Bus goes here
1085
        -- $E100 to $E1FF
1086
        -- Four devices
1087
        -- IDE, Ethernet, Slot1, Slot2
1088
        --
1089
        when "0001" =>
1090
          cpu_data_in <= pb_data_out;
1091
          pb_cs       <= cpu_vma;
1092
          case cpu_addr(7 downto 6) is
1093
            --
1094
            -- IDE Interface $E100 to $E13F
1095
            --
1096
            when "00" =>
1097
              ide_cs   <= cpu_vma;
1098
            --
1099
            -- Ethernet Interface $E140 to $E17F
1100
            --
1101
            when "01" =>
1102
              ether_cs <= cpu_vma;
1103
            --
1104
            -- Slot 1 Interface $E180 to $E1BF
1105
            --
1106
            when "10" =>
1107
              slot1_cs <= cpu_vma;
1108
            --
1109
            -- Slot 2 Interface $E1C0 to $E1FF
1110
            --
1111
            when "11" =>
1112
              slot2_cs <= cpu_vma;
1113
            --
1114
            -- Nothing else
1115
            --
1116
            when others =>
1117
              null;
1118
          end case;
1119
 
1120
        --
1121
        -- $E200 to $EFFF reserved for future use
1122
        --
1123
        when others =>
1124
           null;
1125
      end case;
1126
 
1127
    --
1128
    -- Flex RAM $0C000 - $0DFFF
1129
    --
1130
    elsif dat_addr(7 downto 1) = "0000110" then -- $0C000 - $0DFFF
1131
      cpu_data_in <= flex_data_out;
1132
      flex_cs     <= cpu_vma;
1133
 
1134
    --
1135
    -- Everything else is RAM
1136
    --
1137
    else
1138
      cpu_data_in <= ram_data_out;
1139
      ram_cs      <= cpu_vma;
1140
    end if;
1141
 
1142
  end process;
1143
 
1144
  --
1145
  -- 16-bit Peripheral Bus
1146
  -- 6809 Big endian
1147
  -- ISA bus little endian
1148
  -- Not sure about IDE interface
1149
  --
1150
  peripheral_bus: process( clk_i, cpu_reset, cpu_rw, cpu_addr, cpu_data_out,
1151
                         pb_cs, pb_wreg, pb_rreg )
1152
  begin
1153
    pb_wru <= pb_cs and (not cpu_rw) and (not cpu_addr(0));
1154
    pb_wrl <= pb_cs and (not cpu_rw) and      cpu_addr(0) ;
1155
    pb_rdu <= pb_cs and      cpu_rw  and (not cpu_addr(0));
1156
    pb_rdl <= pb_cs and      cpu_rw  and      cpu_addr(0) ;
1157
    pb_a   <= cpu_addr(5 downto 1);
1158
 
1159
    --
1160
    -- Register upper byte from CPU on first CPU write
1161
    -- and lower byte from the peripheral bus on first CPU read
1162
    --
1163
    if cpu_reset = '1' then
1164
      pb_wreg <= (others => '0');
1165
      pb_rreg <= (others => '0');
1166
    elsif clk_i'event and clk_i ='1' then
1167
      if pb_wru = '1' then
1168
        pb_wreg <= cpu_data_out;
1169
      end if;
1170
      if pb_rdu = '1' then
1171
        pb_rreg <= pb_d(7 downto 0);
1172
      end if;
1173
    end if;
1174
    --
1175
    -- Peripheral bus read and write strobes are
1176
    -- Syncronized with the 50 MHz clock
1177
    -- and are asserted until the peripheral bus hold is released
1178
    --
1179
    if cpu_reset = '1' then
1180
      pb_wr_n <= '1';
1181
      pb_rd_n <= '1';
1182
    elsif clk_i'event and clk_i ='1' then
1183
      if pb_hold = '1' then
1184
        pb_wr_n  <= not pb_wrl;
1185
        pb_rd_n  <= not pb_rdu;
1186
      else
1187
        pb_wr_n <= '1';
1188
        pb_rd_n <= '1';
1189
      end if;
1190
    end if;
1191
    --
1192
    -- The peripheral bus will be an output 
1193
    -- the registered even byte on data(15 downto 8)
1194
    -- and the CPU odd bytes on data(7 downto 0)
1195
    -- on odd byte writes
1196
    --
1197
    if pb_wrl = '1' then
1198
      pb_d <= pb_wreg & cpu_data_out;
1199
    else
1200
      pb_d <= (others => 'Z');
1201
    end if;
1202
 
1203
    --
1204
    -- On even byte reads,
1205
    -- the CPU reads the low (even) byte of the peripheral bus
1206
    -- On odd byte reads,
1207
    -- the CPU reads the registered (odd byte) input from the peripheral bus
1208
    --
1209
    if pb_rdu = '1' then
1210
      pb_data_out <= pb_d(15 downto 8);
1211
    elsif pb_rdl = '1' then
1212
      pb_data_out <= pb_rreg;
1213
    else
1214
      pb_data_out <= (others => '0');
1215
    end if;
1216
 
1217
  end process;
1218
 
1219
  --
1220
  -- Hold Peripheral bus accesses for a few cycles
1221
  --
1222
  peripheral_bus_hold: process( cpu_clk, cpu_reset, pb_rdu, pb_wrl ) --, ether_rdy )
1223
  begin
1224
    if cpu_reset = '1' then
1225
      pb_release    <= '0';
1226
      pb_count      <= "0000";
1227
      pb_hold_state <= hold_release_state;
1228
    elsif rising_edge(cpu_clk) then
1229
      --
1230
      -- The perpheral bus hold signal should be generated on 
1231
      -- 16 bit bus read which will be on even byte reads or 
1232
      -- 16 bit bus write which will be on odd byte writes.
1233
      -- 
1234
      case pb_hold_state is
1235
        when hold_release_state =>
1236
          pb_release <= '0';
1237
          if (pb_rdu = '1') or (pb_wrl = '1') then
1238
            pb_count      <= "0100";
1239
            pb_hold_state <= hold_request_state;
1240
          elsif (pb_rdl = '1') or (pb_wru = '1') then
1241
            pb_release    <= '1';
1242
            pb_hold_state <= hold_release_state;
1243
          end if;
1244
 
1245
        when hold_request_state =>
1246
          if pb_count = "0000" then
1247
--          if ether_rdy = '1' then
1248
              pb_release    <= '1';
1249
              pb_hold_state <= hold_release_state;
1250
--          end if;
1251
          else
1252
            pb_count <= pb_count - "0001";
1253
          end if;
1254
        when others =>
1255
          null;
1256
      end case;
1257
    end if;
1258
  end process;
1259
 
1260
  --
1261
  -- Compact Flash Control
1262
  --
1263
  compact_flash: process( ide_cs, cpu_addr )
1264
  begin
1265
   ide_cs0_n  <= not( ide_cs ) or cpu_addr(4);
1266
   ide_cs1_n  <= not( ide_cs and cpu_addr(4));
1267
   ide_dmack_n  <= '1';
1268
  end process;
1269
 
1270
  --
1271
  -- Interrupts and other bus control signals
1272
  --
1273
  interrupts : process( SW3_N,
1274
                      pb_cs, pb_hold, pb_release, ram_hold,
1275
--                    ether_irq, 
1276
                      acia_irq,
1277
                      aciaB_irq,
1278
                      keyboard_irq,
1279
                      trap_irq,
1280
                      timer_irq
1281
                      )
1282
  begin
1283
    pb_hold    <= pb_cs and (not pb_release);
1284
    cpu_irq    <= acia_irq or aciaB_irq or keyboard_irq;
1285
    cpu_nmi    <= trap_irq or not( SW3_N );
1286
    cpu_firq   <= timer_irq;
1287
    cpu_halt   <= '0';
1288
    cpu_hold   <= pb_hold or ram_hold;
1289
    FLASH_CE_N <= '1';
1290
  end process;
1291
 
1292
  --
1293
  -- Flash 7 segment LEDS
1294
  --
1295
  my_led_flasher: process( clk_i, rst_i, CountL )
1296
  begin
1297
    if rst_i = '1' then
1298
         CountL <= "000000000000000000000000";
1299
    elsif rising_edge(clk_i) then
1300
         CountL <= CountL + 1;
1301
    end if;
1302
    --  S(7 downto 0) <= CountL(23 downto 16);
1303
  end process;
1304
 
1305
  --
1306
  -- Generate CPU & Pixel Clock from Memory Clock
1307
  --
1308
  my_prescaler : process( clk_i, clk_count )
1309
  begin
1310
    if rising_edge( clk_i ) then
1311
      if clk_count = 0 then
1312
        clk_count <= CPU_CLK_DIV-1;
1313
      else
1314
        clk_count <= clk_count - 1;
1315
      end if;
1316
      if clk_count = 0 then
1317
         clk25 <= '0';
1318
      elsif clk_count = (CPU_CLK_DIV/2) then
1319
         clk25 <= '1';
1320
      end if;
1321
    end if;
1322
  end process;
1323
 
1324
  --
1325
  -- Reset button and reset timer
1326
  --
1327
  my_switch_assignments : process( rst_i, SW2_N, lock )
1328
  begin
1329
    rst_i <= not SW2_N;
1330
    cpu_reset <= rst_i or (not lock);
1331
  end process;
1332
 
1333
  --
1334
  -- RS232 signals:
1335
  --
1336
  my_acia_assignments : process( RS232_RXD, --RS232_CTS, 
1337
                                 txd, rts_n )
1338
  begin
1339
    rxd       <= RS232_RXD;
1340
    cts_n     <= '0'; -- RS232_CTS;
1341
    dcd_n     <= '0';
1342
    RS232_TXD <= txd;
1343
--  RS232_RTS <= rts_n;
1344
  end process;
1345
  my_aciaB_assignments : process( RS232B_RXD, --RS232B_CTS, 
1346
                                 txdB, rtsB_n )
1347
  begin
1348
    rxdB       <= RS232B_RXD;
1349
    ctsB_n     <= '0'; -- RS232B_CTS;
1350
    dcdB_n     <= '0';
1351
    RS232B_TXD <= txdB;
1352
--  RS232B_RTS <= rtsB_n;
1353
  end process;
1354
 
1355
  --
1356
  -- Pin assignments for ethernet controller
1357
  --
1358
  my_ethernet_assignments : process( clk_i, cpu_reset, ether_cs )
1359
  begin
1360
    ether_cs_n  <= not ether_cs;
1361
    ether_aen   <= not ether_cs; -- Ethernet address enable not 
1362
    ether_bhe_n <= '1';          -- Ethernet bus high enable - 8 bit access only
1363
  end process;
1364
 
1365
  --
1366
  -- I/O expansion slot assignments
1367
  --
1368
  my_slot_assignments : process( slot1_cs, slot2_cs)
1369
  begin
1370
    slot1_cs_n <= not slot1_cs;
1371
    slot2_cs_n <= not slot2_cs;
1372
  end process;
1373
 
1374
  --
1375
  -- VGA ouputs
1376
  --
1377
  my_vga_assignments : process( vga_red_o, vga_green_o, vga_blue_o )
1378
  begin
1379
    VGA_red(0)   <= vga_red_o;
1380
    VGA_red(1)   <= vga_red_o;
1381
    VGA_red(2)   <= vga_red_o;
1382
    VGA_green(0) <= vga_green_o;
1383
    VGA_green(1) <= vga_green_o;
1384
    VGA_green(2) <= vga_green_o;
1385
    VGA_blue(0)  <= vga_blue_o;
1386
    VGA_blue(1)  <= vga_blue_o;
1387
    VGA_blue(2)  <= vga_blue_o;
1388
  end process;
1389
 
1390
  --
1391
  -- SDRAM read write control
1392
  --
1393
  my_sdram_rw : process( clk_i, cpu_reset,
1394
                       opBegun, ramDone,
1395
                       ram_state,
1396
                       ram_rd_req, ram_wr_req )
1397
  begin
1398
    if( cpu_reset = '1' ) then
1399
      hRd        <= '0';
1400
      hWr        <= '0';
1401
      ram_hold   <= '0';
1402
      ram_state  <= ram_state_0;
1403
 
1404
    elsif( falling_edge(clk_i) ) then
1405
      --
1406
      -- ram state machine
1407
      --
1408
      case ram_state is
1409
 
1410
      when ram_state_0 =>
1411
        if ram_rd_req = '1' then
1412
          ram_hold   <= '1';
1413
          hRd        <= '1';
1414
          ram_state  <= ram_state_rd1;
1415
        elsif ram_wr_req = '1' then
1416
          ram_hold   <= '1';
1417
          hWr        <= '1';
1418
          ram_state  <= ram_state_wr1;
1419
        end if;
1420
 
1421
      when ram_state_rd1 =>
1422
        if opBegun = '1' then
1423
          hRd        <= '0';
1424
          ram_state  <= ram_state_rd2;
1425
        end if;
1426
 
1427
      when ram_state_rd2 =>
1428
        if ramDone = '1' then
1429
          ram_hold   <= '0';
1430
          ram_state  <= ram_state_3;
1431
        end if;
1432
 
1433
      when ram_state_wr1 =>
1434
        if opBegun = '1' then
1435
          ram_hold   <= '0';
1436
          hWr        <= '0';
1437
          ram_state  <= ram_state_3;
1438
        end if;
1439
 
1440
      when ram_state_3 =>
1441
        if ram_release = '1' then
1442
          ram_state  <= ram_state_0;
1443
        end if;
1444
 
1445
      when others =>
1446
        hRd        <= '0';
1447
        hWr        <= '0';
1448
        ram_hold   <= '0';
1449
        ram_state  <= ram_state_0;
1450
    end case;
1451
 
1452
    end if;
1453
  end process;
1454
 
1455
  --
1456
  -- SDRAM Address and data bus assignments
1457
  --
1458
  my_sdram_addr_data : process( cpu_addr, dat_addr,
1459
                                cpu_data_out, hDout )
1460
  begin
1461
    hAddr(23 downto 19)  <= "00000";
1462
    hAddr(18 downto 11)  <= dat_addr;
1463
    hAddr(10 downto 0)   <= cpu_addr(11 downto 1);
1464
    hUds                 <= not cpu_addr(0);
1465
    hLds                 <=     cpu_addr(0);
1466
    if cpu_addr(0) = '0' then
1467
      hDin( 7 downto 0) <= (others=>'0');
1468
      hDin(15 downto 8) <= cpu_data_out;
1469
      ram_data_out      <= hDout(15 downto 8);
1470
    else
1471
      hDin( 7 downto 0) <= cpu_data_out;
1472
      hDin(15 downto 8) <= (others=>'0');
1473
      ram_data_out      <= hDout( 7 downto 0);
1474
    end if;
1475
  end process;
1476
 
1477
  --
1478
  -- Hold RAM until falling CPU clock edge
1479
  --
1480
  ram_bus_hold: process( cpu_clk, cpu_reset, ram_hold )
1481
  begin
1482
    if ram_hold = '1' then
1483
      ram_release   <= '0';
1484
    elsif falling_edge(cpu_clk) then
1485
      ram_release   <= '1';
1486
    end if;
1487
  end process;
1488
 
1489
  --
1490
  -- CPU read data request on rising CPU clock edge
1491
  --
1492
  ram_read_request: process( hRd, cpu_clk, ram_cs, cpu_rw, ram_release )
1493
  begin
1494
    if hRd = '1' then
1495
      ram_rd_req   <= '0';
1496
    elsif rising_edge(cpu_clk) then
1497
      if (ram_cs = '1') and (cpu_rw = '1') and (ram_release = '1') then
1498
        ram_rd_req   <= '1';
1499
      end if;
1500
    end if;
1501
  end process;
1502
 
1503
  --
1504
  -- CPU write data to RAM valid on rising CPU clock edge
1505
  --
1506
  ram_write_request: process( hWr, cpu_clk, ram_cs, cpu_rw, ram_release )
1507
  begin
1508
    if hWr = '1' then
1509
       ram_wr_req   <= '0';
1510
    elsif rising_edge(cpu_clk) then
1511
      if (ram_cs = '1') and (cpu_rw = '0') and (ram_release = '1') then
1512
        ram_wr_req   <= '1';
1513
      end if;
1514
    end if;
1515
  end process;
1516
 
1517
  status_leds : process( rst_i, cpu_reset, lock )
1518
  begin
1519
    S(0) <= rst_i;
1520
    S(1) <= cpu_reset;
1521
    S(2) <= lock;
1522
    S(3) <= countL(23);
1523
    S(7 downto 4) <= "0000";
1524
  end process;
1525
 
1526
--  debug_proc : process( cpu_reset, cpu_clk, cpu_rw, cpu_vma,
1527
--                      cpu_halt, cpu_hold,
1528
--                      cpu_firq, cpu_irq, cpu_nmi,
1529
--                      cpu_addr, cpu_data_out, cpu_data_in )
1530
--  begin
1531
--    cpu_reset_o    <= cpu_reset;
1532
--    cpu_clk_o      <= cpu_clk;
1533
--    cpu_rw_o       <= cpu_rw;
1534
--    cpu_vma_o      <= cpu_vma;
1535
--    cpu_halt_o     <= cpu_halt;
1536
--    cpu_hold_o     <= cpu_hold;
1537
--    cpu_firq_o     <= cpu_firq;
1538
--    cpu_irq_o      <= cpu_irq;
1539
--    cpu_nmi_o      <= cpu_nmi;
1540
--    cpu_addr_o     <= cpu_addr;
1541
--    cpu_data_out_o <= cpu_data_out;
1542
--    cpu_data_in_o  <= cpu_data_in;
1543
--  end process;
1544
 
1545
end rtl; --===================== End of architecture =======================--
1546
 

powered by: WebSVN 2.1.0

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