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

Subversion Repositories System09

[/] [System09/] [tags/] [V10/] [rtl/] [vhdl/] [System09_tb.vhd] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dilbert57
--===========================================================================----
2
--
3
--  T E S T B E N C H    System09_tb - SOC Testbench.
4
--
5
--  www.OpenCores.Org - September 2003
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : System09_tb.vhd
9
--
10
-- Purpose        : Test Bench for system 09
11
--                  Top level file for 6809 compatible system on a chip
12
--                  Designed with Xilinx XC2S300e Spartan 2+ FPGA.
13
--                  Implemented With BurchED B5-X300 FPGA board,
14
--                  B3-SRAM module, B5-CF module and B3-FPGA-CPU-IO module
15
--
16
-- Dependencies   : ieee.Std_Logic_1164
17
--                  ieee.std_logic_unsigned
18
--                  ieee.std_logic_arith
19
--                  ieee.numeric_std
20
--
21
-- Uses           : boot_rom (sbug.vhd)       Monitor ROM
22
--                  cpu09    (cpu09.vhd)      CPU core
23
--                  dat_ram  (datram.vhd)     Dynamic Address Translation
24
--                  miniuart (minitUART2.vhd) ACIA / MiniUART
25
--                           (rxunit2.vhd)
26
--                           (tx_unit2.vhd)
27
--                           (clkunit2.vhd)
28
--                  timer    (timer.vhd)      Timer module
29
-- 
30
-- Author         : John E. Kent
31
--                  dilbert57@opencores.org      
32
--
33
--===========================================================================----
34
--
35
-- Revision History:
36
--===========================================================================--
37
--
38
-- Version 1.0 
39
-- John Kent - 6 Sep 2003 - Initial release to Open Cores
40
--
41
--===========================================================================--
42
library ieee;
43
   use ieee.std_logic_1164.all;
44
   use IEEE.STD_LOGIC_ARITH.ALL;
45
   use IEEE.STD_LOGIC_UNSIGNED.ALL;
46
   use ieee.numeric_std.all;
47
 
48
entity System09 is
49
  port(
50
    LED         : out std_logic;  -- Diagnostic LED Flasher
51
 
52
    -- Memory Interface signals
53
    ram_csn     : out Std_Logic;
54
    ram_wrln    : out Std_Logic;
55
    ram_wrun    : out Std_Logic;
56
    ram_addr    : out Std_Logic_Vector(16 downto 0);
57
    ram_data    : inout Std_Logic_Vector(15 downto 0);
58
 
59
         -- Stuff on the peripheral board
60
--  aux_clock   : in  Std_Logic;  -- FPGA-CPU-IO clock
61
 
62
         -- PS/2 Mouse interface
63
--       mouse_clock : in  Std_Logic;
64
--       mouse_data  : in  Std_Logic;
65
 
66
         -- Uart Interface
67
    rxbit       : in  Std_Logic;
68
         txbit       : out Std_Logic;
69
    rts_n       : out Std_Logic;
70
    cts_n       : in  Std_Logic;
71
 
72
         -- CRTC output signals
73
--         v_drive     : out Std_Logic;
74
--    h_drive     : out Std_Logic;
75
--    blue_lo     : out std_logic;
76
--    blue_hi     : out std_logic;
77
--    green_lo    : out std_logic;
78
--    green_hi    : out std_logic;
79
--    red_lo      : out std_logic;
80
--    red_hi      : out std_logic;
81
--         buzzer      : out std_logic;
82
 
83
-- Compact Flash
84
    cf_rst_n     : out std_logic;
85
         cf_cs0_n     : out std_logic;
86
         cf_cs1_n     : out std_logic;
87
    cf_rd_n      : out std_logic;
88
    cf_wr_n      : out std_logic;
89
         cf_cs16_n    : out std_logic;
90
    cf_a         : out std_logic_vector(2 downto 0);
91
    cf_d         : inout std_logic_vector(15 downto 0);
92
 
93
-- Test Pins
94
 
95
         test_alu    : out std_logic_vector(15 downto 0);
96
         test_cc     : out std_logic_vector(7 downto 0)
97
         );
98
end;
99
 
100
-------------------------------------------------------------------------------
101
-- Architecture for memio Controller Unit
102
-------------------------------------------------------------------------------
103
architecture my_computer of System09 is
104
  -----------------------------------------------------------------------------
105
  -- Signals
106
  -----------------------------------------------------------------------------
107
  signal SysClk    : std_logic;
108
  signal reset_n   : std_logic;
109
 
110
  -- BOOT ROM
111
  signal rom_data_out  : Std_Logic_Vector(7 downto 0);
112
 
113
  -- UART Interface signals
114
  signal uart_data_out : Std_Logic_Vector(7 downto 0);
115
  signal uart_cs       : Std_Logic;
116
  signal uart_irq      : Std_Logic;
117
 
118
  -- timer
119
  signal timer_data_out : std_logic_vector(7 downto 0);
120
  signal timer_cs    : std_logic;
121
  signal timer_irq   : std_logic;
122
  signal timer_out   : std_logic;
123
 
124
  -- compact flash port
125
  signal cf_data_out : std_logic_vector(7 downto 0);
126
  signal cf_cs       : std_logic;
127
  signal cf_rd       : std_logic;
128
  signal cf_wr       : std_logic;
129
 
130
  -- RAM
131
  signal ram_cs      : std_logic; -- memory chip select
132
  signal ram_wrl     : std_logic; -- memory write lower
133
  signal ram_wru     : std_logic; -- memory write upper
134
  signal ram_data_out    : std_logic_vector(7 downto 0);
135
 
136
  -- CPU Interface signals
137
  signal cpu_reset   : Std_Logic;
138
  signal cpu_clk     : Std_Logic;
139
  signal cpu_rw      : std_logic;
140
  signal cpu_vma     : std_logic;
141
  signal cpu_halt    : std_logic;
142
  signal cpu_hold    : std_logic;
143
  signal cpu_firq    : std_logic;
144
  signal cpu_irq     : std_logic;
145
  signal cpu_nmi     : std_logic;
146
  signal cpu_addr    : std_logic_vector(15 downto 0);
147
  signal cpu_data_in : std_logic_vector(7 downto 0);
148
  signal cpu_data_out: std_logic_vector(7 downto 0);
149
 
150
  -- Dynamic address translation
151
  signal dat_cs      : std_logic;
152
  signal dat_addr    : std_logic_vector(7 downto 0);
153
 
154
  -- Boot ROM Map switch
155
--  signal map_cs      : Std_Logic;
156
--  signal map_sw      : Std_Logic;
157
 
158
  -- synchronous RAM
159
  signal xram_data_out : std_logic_vector(7 downto 0);
160
  signal xram_cs       : std_logic;
161
 
162
  -- Flashing Led test signals
163
  signal countL      : std_logic_vector(23 downto 0);
164
 
165
-----------------------------------------------------------------
166
--
167
-- CPU09 CPU core
168
--
169
-----------------------------------------------------------------
170
 
171
component cpu09
172
  port (
173
         clk:        in std_logic;
174
    rst:      in        std_logic;
175
    rw:      out        std_logic;              -- Asynchronous memory interface
176
    vma:             out        std_logic;
177
    address:  out       std_logic_vector(15 downto 0);
178
    data_in:  in        std_logic_vector(7 downto 0);
179
         data_out: out std_logic_vector(7 downto 0);
180
         halt:     in  std_logic;
181
         hold:     in  std_logic;
182
         irq:      in  std_logic;
183
         nmi:      in  std_logic;
184
         firq:     in  std_logic;
185
         test_alu: out std_logic_vector(15 downto 0);
186
         test_cc:  out std_logic_vector(7 downto 0)
187
  );
188
end component;
189
 
190
-----------------------------------------------------------------
191
--
192
-- Open Cores Mini UART
193
--
194
-----------------------------------------------------------------
195
 
196
component miniUART
197
  port (
198
     SysClk   : in  Std_Logic;  -- System Clock
199
     rst      : in  Std_Logic;  -- Reset input
200
     cs       : in  Std_Logic;
201
     rw       : in  Std_Logic;
202
     RxD      : in  Std_Logic;
203
     TxD      : out Std_Logic;
204
     CTS_n    : in  Std_Logic;
205
     RTS_n    : out Std_Logic;
206
     Irq      : out Std_logic;
207
     Addr     : in  Std_Logic;
208
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- 
209
     DataOut  : out Std_Logic_Vector(7 downto 0)); -- 
210
end component;
211
 
212
----------------------------------------
213
--
214
-- Timer module
215
--
216
----------------------------------------
217
 
218
component timer
219
  port (
220
     clk       : in std_logic;
221
          rst       : in std_logic;
222
          cs        : in std_logic;
223
          rw        : in std_logic;
224
          addr      : in std_logic;
225
          data_in   : in std_logic_vector(7 downto 0);
226
          data_out  : out std_logic_vector(7 downto 0);
227
          irq       : out std_logic;
228
     timer_in  : in std_logic;
229
          timer_out : out std_logic
230
          );
231
end component;
232
 
233
 
234
component boot_rom
235
  port (
236
    addr  : in  Std_Logic_Vector(10 downto 0);  -- 2K byte boot rom
237
         data  : out Std_Logic_Vector(7 downto 0));
238
end component;
239
 
240
--component sbug_rom
241
--    Port (
242
--       MEMclk   : in std_logic;
243
--       MEMaddr  : in std_logic_vector (10 downto 0);
244
--       MEMrdata : out std_logic_vector (7 downto 0)
245
--    );
246
--end component sbug_rom;
247
 
248
component dat_ram
249
  port (
250
    clk:      in  std_logic;
251
         rst:      in  std_logic;
252
         cs:       in  std_logic;
253
         rw:       in  std_logic;
254
         addr_lo:  in  std_logic_vector(3 downto 0);
255
         addr_hi:  in  std_logic_vector(3 downto 0);
256
    data_in:  in  std_logic_vector(7 downto 0);
257
         data_out: out std_logic_vector(7 downto 0)
258
         );
259
end component;
260
 
261
 
262
-- component block_ram
263
--    Port (
264
--       MEMclk   : in  std_logic;
265
--               MEMcs    : in  std_logic;
266
--               MEMrw    : in  std_logic;
267
--       MEMaddr  : in  std_logic_vector (10 downto 0);
268
--       MEMrdata : out std_logic_vector (7 downto 0);
269
--       MEMwdata : in  std_logic_vector (7 downto 0)
270
--    );
271
--end component;
272
 
273
 
274
-- component BUFG 
275
--  port (
276
--     i: in std_logic;
277
--        o: out std_logic
278
--  );
279
-- end component;
280
 
281
begin
282
  -----------------------------------------------------------------------------
283
  -- Instantiation of internal components
284
  -----------------------------------------------------------------------------
285
 
286
my_cpu : cpu09  port map (
287
         clk         => SysClk,
288
    rst       => cpu_reset,
289
    rw       => cpu_rw,
290
    vma       => cpu_vma,
291
    address   => cpu_addr(15 downto 0),
292
    data_in   => cpu_data_in,
293
         data_out  => cpu_data_out,
294
         halt      => cpu_halt,
295
         hold      => cpu_hold,
296
         irq       => cpu_irq,
297
         nmi       => cpu_nmi,
298
         firq      => cpu_firq,
299
         test_alu  => test_alu,
300
         test_cc   => test_cc
301
  );
302
 
303
 
304
my_uart  : miniUART port map (
305
    SysClk    => SysClk,
306
         rst       => cpu_reset,
307
    cs        => uart_cs,
308
         rw        => cpu_rw,
309
         RxD       => rxbit,
310
         TxD       => txbit,
311
         CTS_n     => cts_n,
312
         RTS_n     => rts_n,
313
    Irq       => uart_irq,
314
    Addr      => cpu_addr(0),
315
         Datain    => cpu_data_out,
316
         DataOut   => uart_data_out
317
         );
318
 
319
my_timer  : timer port map (
320
    clk       => SysClk,
321
         rst       => cpu_reset,
322
    cs        => timer_cs,
323
         rw        => cpu_rw,
324
    addr      => cpu_addr(0),
325
         data_in   => cpu_data_out,
326
         data_out  => timer_data_out,
327
    irq       => timer_irq,
328
         timer_in  => CountL(5),
329
         timer_out => timer_out
330
    );
331
 
332
my_rom : boot_rom port map (
333
         addr       => cpu_addr(10 downto 0),
334
    data       => rom_data_out
335
         );
336
 
337
--my_rom : sbug_rom port map (
338
--       MEMclk   => SysClk,
339
--       MEMaddr  => cpu_addr(10 downto 0),
340
--       MEMrdata => rom_data_out
341
--    );
342
 
343
 
344
my_dat : dat_ram port map (
345
    clk        => SysClk,
346
         rst        => cpu_reset,
347
         cs         => dat_cs,
348
         rw         => cpu_rw,
349
         addr_hi    => cpu_addr(15 downto 12),
350
         addr_lo    => cpu_addr(3 downto 0),
351
    data_in    => cpu_data_out,
352
         data_out   => dat_addr(7 downto 0)
353
         );
354
 
355
 
356
--my_ram : block_ram port map (
357
--       MEMclk   => SysClk,
358
--       MEMcs    => xram_cs,
359
--               MEMrw    => cpu_rw,
360
--       MEMaddr  => cpu_addr(10 downto 0),
361
--       MEMwdata => cpu_data_out,
362
--       MEMrdata => xram_data_out
363
--    );
364
 
365
--  clk_buffer : BUFG port map(
366
--    i => e_clk,
367
--         o => cpu_clk
368
--    );         
369
 
370
----------------------------------------------------------------------
371
--
372
-- Process to decode memory map
373
--
374
----------------------------------------------------------------------
375
 
376
mem_decode: process(
377
                     cpu_addr, cpu_vma,
378
--                                                 map_cs, map_sw,
379
                                              rom_data_out, ram_data_out,
380
--                                                 xram_data_out,
381
                                              cf_data_out,
382
                                                   timer_data_out,
383
                                                   uart_data_out )
384
begin
385
    --
386
         -- Memory map
387
         --
388
    case cpu_addr(15 downto 11) is
389
                when "11111" => -- $F800 - $FFFF
390
                   cpu_data_in <= rom_data_out;       -- read ROM
391
                        dat_cs    <= cpu_vma;              -- write DAT
392
                        ram_cs    <= '0';
393
                        uart_cs   <= '0';
394
                        cf_cs     <= '0';
395
                        timer_cs  <= '0';
396
--                      xram_cs   <= '0';
397
--                      map_cs    <= '0';
398
--              when "11101" => -- $E800 - $EFFF
399
--              when "11111" => -- $F800 - $FFFF
400
--                 if map_sw = '1' then
401
--                   cpu_data_in <= rom_data_out;     -- read ROM
402
--                        dat_cs    <= '0';                -- disable write to DAT
403
--                        ram_cs    <= cpu_vma;            -- enable write to RAM
404
--                      else
405
--                        cpu_data_in <= ram_data_out;     -- read RAM
406
--                        dat_cs    <= cpu_vma;            -- enable write DAT
407
--                        ram_cs    <= cpu_vma and cpu_rw; -- disable write to RAM
408
--                      end if;
409
--                      uart_cs   <= '0';
410
--                      cf_cs     <= '0';
411
--                      timer_cs  <= '0';
412
--                      map_cs    <= '0';
413
--      when "11110" => -- $F000 - $F7FF
414
--            cpu_data_in <= xram_data_out;
415
--                      dat_cs    <= '0';
416
--                      ram_cs    <= '0';
417
--                      uart_cs   <= '0';
418
--                      cf_cs     <= '0';
419
--                      xram_cs   <= cpu_vma;
420
                when "11100" => -- $E000 - $E7FF
421
                   dat_cs    <= '0';
422
                        ram_cs    <= '0';
423
--                      xram_cs   <= '0';
424
                   case cpu_addr(7 downto 4) is
425
                        when "0000" => -- $E000
426
                     cpu_data_in <= uart_data_out;
427
                          uart_cs     <= cpu_vma;
428
                          cf_cs       <= '0';
429
                          timer_cs    <= '0';
430
--                        map_cs      <= '0';
431
                        when "0001" => -- $E010
432
           cpu_data_in <= cf_data_out;
433
                          uart_cs     <= '0';
434
           cf_cs       <= cpu_vma;
435
                          timer_cs    <= '0';
436
--                        map_cs      <= '0';
437
                        when "0010" => -- $E020
438
           cpu_data_in <= timer_data_out;
439
                          uart_cs     <= '0';
440
                          cf_cs       <= '0';
441
           timer_cs    <= cpu_vma;
442
                          map_cs      <= '0';
443
                        when "0011" => -- $E030
444
           cpu_data_in <= "00000000";
445
                          uart_cs     <= '0';
446
                          cf_cs       <= '0';
447
           timer_cs    <= '0';
448
--                        map_cs      <= cpu_vma;
449
                        when others => -- $E040 to $E7FF
450
           cpu_data_in <= "00000000";
451
                          uart_cs     <= '0';
452
                          cf_cs       <= '0';
453
                          timer_cs    <= '0';
454
--                        map_cs      <= '0';
455
                   end case;
456
                when others =>
457
                  cpu_data_in <= ram_data_out;
458
                  ram_cs      <= cpu_vma;
459
--                xram_cs     <= '0';
460
                  dat_cs      <= '0';
461
                  uart_cs     <= '0';
462
                  cf_cs       <= '0';
463
                  timer_cs    <= '0';
464
--                map_cs      <= '0';
465
         end case;
466
end process;
467
 
468
--
469
-- B3-SRAM Control
470
-- Processes to read and write memory based on bus signals
471
--
472
ram_process: process( SysClk, Reset_n,
473
                      cpu_addr, cpu_rw, cpu_data_out,
474
                                               dat_addr,
475
                      ram_cs, ram_wrl, ram_wru, ram_data )
476
begin
477
    ram_csn <= not( ram_cs and Reset_n );
478
         ram_wrl  <= (not dat_addr(5)) and (not cpu_rw) and (not SysClk);
479
         ram_wrln <= not (ram_wrl);
480
    ram_wru  <= dat_addr(5) and (not cpu_rw) and (not SysClk);
481
         ram_wrun <= not (ram_wru);
482
         ram_addr(16 downto 12) <= dat_addr(4 downto 0);
483
         ram_addr(11 downto 0) <= cpu_addr(11 downto 0);
484
 
485
    if ram_wrl = '1' then
486
                ram_data(7 downto 0) <= cpu_data_out;
487
         else
488
      ram_data(7 downto 0)  <= "ZZZZZZZZ";
489
         end if;
490
 
491
         if ram_wru = '1' then
492
                ram_data(15 downto 8) <= cpu_data_out;
493
         else
494
      ram_data(15 downto 8)  <= "ZZZZZZZZ";
495
    end if;
496
 
497
         if dat_addr(5) = '1' then
498
      ram_data_out <= ram_data(15 downto 8);
499
         else
500
      ram_data_out <= ram_data(7 downto 0);
501
    end if;
502
end process;
503
 
504
--
505
-- Compact Flash Control
506
--
507
compact_flash: process( Reset_n,
508
                 cpu_addr, cpu_rw,  cpu_data_out,
509
                                          cf_cs, cf_rd, cf_wr, cf_d )
510
begin
511
         cf_rst_n  <= Reset_n;
512
         cf_cs0_n  <= not( cf_cs ) or cpu_addr(3);
513
         cf_cs1_n  <= not( cf_cs and cpu_addr(3));
514
         cf_cs16_n <= '1';
515
         cf_wr     <= cf_cs and (not cpu_rw);
516
         cf_rd     <= cf_cs and cpu_rw;
517
         cf_wr_n   <= not cf_wr;
518
         cf_rd_n   <= not cf_rd;
519
         cf_a      <= cpu_addr(2 downto 0);
520
         if cf_wr = '1' then
521
           cf_d(7 downto 0) <= cpu_data_out;
522
         else
523
           cf_d(7 downto 0) <= "ZZZZZZZZ";
524
         end if;
525
         cf_data_out <= cf_d(7 downto 0);
526
         cf_d(15 downto 8) <= "ZZZZZZZZ";
527
end process;
528
 
529
--
530
-- ROM Map switch
531
-- The Map switch output is initially set
532
-- On a Write to the Map Switch port, clear the Map Switch
533
-- and map the RAM in place of the boot ROM.
534
--
535
--map_proc : process( SysClk, Reset_n, map_cs, cpu_rw )
536
--begin
537
--  if SysClk'event and SysClk = '1' then
538
--    if Reset_n = '0' then
539
--          map_sw <= '1';
540
--       else
541
--          if (map_cs = '1') and (cpu_rw = '0') then
542
--                 map_sw <= '0';
543
--               else
544
--                 map_sw <= map_sw;
545
--               end if;
546
--       end if;
547
--  end if;
548
--end process;
549
 
550
--
551
-- Interrupts and other bus control signals
552
--
553
interrupts : process( Reset_n, uart_irq
554
--                    ,timer_irq
555
                                                         )
556
begin
557
         cpu_reset <= not Reset_n; -- CPU reset is active high
558
    cpu_irq  <= uart_irq;
559
         cpu_nmi  <= timer_irq;
560
--       cpu_nmi  <= '0';
561
         cpu_firq <= '0';
562
         cpu_halt <= '0';
563
         cpu_hold <= '0';
564
end process;
565
 
566
  --
567
  -- flash led to indicate code is working
568
  --
569
  increment: process (SysClk, CountL )
570
  begin
571
    if(SysClk'event and SysClk = '1') then
572
      countL <= countL + 1;
573
    end if;
574
         LED <= countL(21);
575
  end process;
576
-- *** Test Bench - User Defined Section ***
577
tb : PROCESS
578
        variable count : integer;
579
   BEGIN
580
 
581
        SysClk <= '0';
582
        Reset_n <= '0';
583
 
584
                for count in 0 to 512 loop
585
                        SysClk <= '0';
586
                        if count = 0 then
587
                                Reset_n <= '0';
588
                        elsif count = 1 then
589
                                Reset_n <= '1';
590
                        end if;
591
                        wait for 100 ns;
592
                        SysClk <= '1';
593
                        wait for 100 ns;
594
                end loop;
595
 
596
      wait; -- will wait forever
597
   END PROCESS;
598
 
599
 
600
end; --===================== End of architecture =======================--
601
 

powered by: WebSVN 2.1.0

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