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

Subversion Repositories system05

[/] [system05/] [trunk/] [rtl/] [vhdl/] [System05_tb.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dilbert57
--===========================================================================--
2
--
3
--  S Y N T H E Z I A B L E    System05   System On a Chip
4
--
5
--  This core adheres to the GNU public license  
6
--
7
-- File name      : system05.vhd
8
--
9
-- Purpose        : Top level file for a 6805 compatible system on a chip
10
--                  Designed for the Burch ED B5-Spartan IIe board with
11
--                  X2S300e FPGA,
12
--                  128K x 16 Word SRAM module (B5-SRAM)
13
--                  CPU I/O module (B5-Peripheral-Connectors)
14
--                  Using mimiUart from open cores modified to look like a 6850
15
--                  
16
-- Dependencies   : ieee.Std_Logic_1164
17
--                  ieee.std_logic_unsigned
18
--                  ieee.std_logic_arith
19
--                  ieee.numeric_std
20
--
21
-- Uses           : cpu05.vhd  (6805 compatible CPU core)
22
--                  miniuart3.vhd, (6850 compatible UART)
23
--                    rxunit3.vhd, 
24
--                    txunit3.vhd
25
--                  timer.vhd  (timer module)
26
--                  ioport.vhd (parallel I/O port)
27
--
28
-- Author         : John E. Kent      
29
--
30
--===========================================================================----
31
--
32
-- Revision History:
33
--===========================================================================--
34
--
35
--       Version   Date            Author     Notes
36
--  0.0       14th July 2001  John Kent  Started design
37
--  0.1       30th May 2004   John Kent  Initial Release
38
--
39
--
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 System05_tb is
49
  port(
50
    LED         : out std_logic;  -- Diagnostic LED Flasher
51
 
52
    -- Memory Interface signals
53
    ram_csn     : out Std_Logic;
54
    ram_wrun    : out Std_Logic;
55
    ram_wrln    : 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;  -- Extra clock
61
--       buzzer      : out Std_Logic;
62
 
63
         -- PS/2 Mouse interface
64
--       mouse_clock : in  Std_Logic;
65
--       mouse_data  : in  Std_Logic;
66
 
67
         -- Uart Interface
68
    rxbit       : in  Std_Logic;
69
         txbit       : out Std_Logic;
70
    rts_n       : out Std_Logic;
71
    cts_n       : in  Std_Logic;
72
 
73
         -- Keyboard interface
74
--    kb_clock    : in  Std_Logic;
75
--      kb_data     : in  Std_Logic;
76
 
77
         -- CRTC output signals
78
--       v_drive     : out Std_Logic;
79
--    h_drive     : out Std_Logic;
80
--    blue_lo     : out std_logic;
81
--    blue_hi     : out std_logic;
82
--    green_lo    : out std_logic;
83
--    green_hi    : out std_logic;
84
--    red_lo      : out std_logic;
85
--    red_hi      : out std_logic;
86
 
87
    -- External Bus
88
    bus_addr     : out   std_logic_vector(15 downto 0);
89
         bus_data     : inout std_logic_vector(7 downto 0);
90
         bus_rw       : out   std_logic;
91
         bus_cs       : out   std_logic;
92
         bus_clk      : out   std_logic;
93
         bus_reset    : out   std_logic;
94
 
95
    -- I/O Ports
96
    porta        : inout std_logic_vector(7 downto 0);
97
    portb        : inout std_logic_vector(7 downto 0);
98
    portc        : inout std_logic_vector(7 downto 0);
99
    portd        : inout std_logic_vector(7 downto 0);
100
 
101
    -- Timer I/O
102
--    timer0_in    : in std_logic;
103
         timer0_out   : out std_logic;
104
--    timer1_in    : in std_logic;
105
         timer1_out   : out std_logic
106
        );
107
end System05_tb;
108
 
109
-------------------------------------------------------------------------------
110
-- Architecture for memio Controller Unit
111
-------------------------------------------------------------------------------
112
architecture my_computer of System05_tb is
113
  signal SysClk      : Std_Logic;  -- System Clock input
114
  signal Reset_n     : Std_logic;  -- Master Reset input (active low)
115
  -----------------------------------------------------------------------------
116
  -- Signals
117
  -----------------------------------------------------------------------------
118
  -- BOOT ROM
119
  signal rom_data_out  : Std_Logic_Vector(7 downto 0);
120
 
121
  -- UART Interface signals
122
  signal uart_data_out : Std_Logic_Vector(7 downto 0);
123
  signal uart_cs       : Std_Logic;
124
  signal uart_irq      : Std_Logic;
125
  signal dcd_n         : Std_Logic;
126
 
127
  -- I/O Port
128
  signal ioport_data_out : std_logic_vector(7 downto 0);
129
  signal ioport_cs       : std_logic;
130
 
131
  -- Timer I/O
132
  signal timer_data_out : std_logic_vector(7 downto 0);
133
  signal timer_cs       : std_logic;
134
  signal timer_irq      : Std_Logic;
135
 
136
  -- RAM
137
  signal ram_cs       : std_logic; -- memory chip select
138
  signal ram_wrl      : std_logic; -- memory write lower
139
  signal ram_wru      : std_logic; -- memory write upper
140
  signal ram_data_out : std_logic_vector(7 downto 0);
141
 
142
  -- Sequencer Interface signals
143
  signal cpu_reset   : Std_Logic;
144
  signal cpu_clk     : Std_Logic;
145
  signal cpu_rw      : std_logic;
146
  signal cpu_vma     : std_logic;
147
  signal cpu_addr    : Std_Logic_Vector(15 downto 0);
148
  signal cpu_data_in : Std_Logic_Vector(7 downto 0);
149
  signal cpu_data_out: Std_Logic_Vector(7 downto 0);
150
 
151
  -- External interrupt input
152
  signal ext_irq     : Std_Logic;
153
 
154
  -- Counter signals
155
  signal countL       : std_logic_vector(23 downto 0);
156
  signal BaudCount    : std_logic_vector(4 downto 0);
157
  signal baudclk      : Std_Logic;
158
 
159
-----------------------------------------------------------------
160
--
161
-- CPU Core
162
--
163
-----------------------------------------------------------------
164
 
165
component cpu05 is
166
  port (
167
         clk       : in  std_logic;
168
    rst       : in  std_logic;
169
    vma       : out std_logic;
170
    rw        : out std_logic;
171
    addr      : out std_logic_vector(15 downto 0);
172
    data_in   : in  std_logic_vector(7 downto 0);
173
         data_out  : out std_logic_vector(7 downto 0);
174
         irq_ext   : in  std_logic;
175
         irq_timer : in  std_logic;
176
         irq_uart  : in  std_logic
177
         );
178
end component cpu05;
179
 
180
------------------------------------------
181
--
182
-- Program memory
183
--
184
------------------------------------------
185
 
186
component boot_rom is
187
  port (
188
    addr     : in  Std_Logic_Vector(5 downto 0);  -- 64 byte boot rom
189
         data     : out Std_Logic_Vector(7 downto 0)
190
  );
191
end component boot_rom;
192
 
193
-----------------------------------------------------------------
194
--
195
-- Open Cores Mini UART
196
--
197
-----------------------------------------------------------------
198
 
199
component miniUART
200
  port (
201
     clk      : in  Std_Logic;  -- System Clock
202
     rst      : in  Std_Logic;  -- Reset input (active high)
203
     cs       : in  Std_Logic;  -- miniUART Chip Select
204
     rw       : in  Std_Logic;  -- Read / Not Write
205
     irq      : out Std_Logic;  -- Interrupt
206
     Addr     : in  Std_Logic;  -- Register Select
207
     DataIn   : in  Std_Logic_Vector(7 downto 0); -- Data Bus In 
208
     DataOut  : out Std_Logic_Vector(7 downto 0); -- Data Bus Out
209
     RxC      : in  Std_Logic;  -- Receive Baud Clock
210
     TxC      : in  Std_Logic;  -- Transmit Baud Clock
211
     RxD      : in  Std_Logic;  -- Receive Data
212
     TxD      : out Std_Logic;  -- Transmit Data
213
          DCD_n    : in  Std_Logic;  -- Data Carrier Detect
214
     CTS_n    : in  Std_Logic;  -- Clear To Send
215
     RTS_n    : out Std_Logic );  -- Request To send
216
end component;
217
 
218
 
219
---------------------------------------
220
--
221
-- Three port parallel I/O
222
--
223
---------------------------------------
224
 
225
component ioport is
226
  port (
227
     clk      : in std_logic;
228
          rst      : in std_logic;
229
          cs       : in std_logic;
230
          rw       : in std_logic;
231
          addr     : in std_logic_vector(2 downto 0);
232
          data_in  : in std_logic_vector(7 downto 0);
233
          data_out : out std_logic_vector(7 downto 0);
234
          porta_io : inout std_logic_vector(7 downto 0);
235
          portb_io : inout std_logic_vector(7 downto 0);
236
          portc_io : inout std_logic_vector(7 downto 0);
237
          portd_io : inout std_logic_vector(7 downto 0)
238
          );
239
end component;
240
 
241
----------------------------------------
242
--
243
-- Timer module
244
--
245
----------------------------------------
246
 
247
component timer is
248
  port (
249
     clk       : in std_logic;
250
          rst       : in std_logic;
251
          cs        : in std_logic;
252
          rw        : in std_logic;
253
          addr      : in std_logic_vector(2 downto 0);
254
          data_in   : in std_logic_vector(7 downto 0);
255
          data_out  : out std_logic_vector(7 downto 0);
256
          irq_out   : out std_logic;
257
     tim0_in   : in std_logic;
258
          tim0_out  : out std_logic;
259
     tim1_in   : in std_logic;
260
          tim1_out  : out std_logic
261
          );
262
end component;
263
 
264
------------------------------------------
265
--
266
-- Global clock buffer for debug
267
--
268
------------------------------------------
269
 
270
--component BUFG is 
271
--  port (
272
--     i: in std_logic;
273
--        o: out std_logic
274
--  );
275
--end component;
276
 
277
begin
278
 
279
-----------------------------------------------------------------------------
280
-- Instantiation of internal components
281
-----------------------------------------------------------------------------
282
 
283
my_cpu : cpu05 port map (
284
         clk         => cpu_clk,
285
    rst       => cpu_reset,
286
    vma       => cpu_vma,
287
    rw       => cpu_rw,
288
    addr      => cpu_addr(15 downto 0),
289
    data_in   => cpu_data_in,
290
         data_out  => cpu_data_out,
291
         irq_ext   => ext_irq,
292
         irq_timer => timer_irq,
293
         irq_uart  => uart_irq
294
         );
295
 
296
rom : boot_rom port map (
297
         addr       => cpu_addr(5 downto 0),
298
    data       => rom_data_out
299
         );
300
 
301
my_uart  : miniUART port map (
302
         clk         => cpu_clk,
303
         rst       => cpu_reset,
304
    cs        => uart_cs,
305
         rw        => cpu_rw,
306
    irq       => uart_irq,
307
    Addr      => cpu_addr(0),
308
         Datain    => cpu_data_out,
309
         DataOut   => uart_data_out,
310
         RxC       => baudclk,
311
         TxC       => baudclk,
312
         RxD       => rxbit,
313
         TxD       => txbit,
314
         DCD_n     => dcd_n,
315
         CTS_n     => cts_n,
316
         RTS_n     => rts_n
317
         );
318
 
319
my_ioport  : ioport port map (
320
    clk       => cpu_clk,
321
         rst       => cpu_reset,
322
    cs        => ioport_cs,
323
         rw        => cpu_rw,
324
    addr      => cpu_addr(2 downto 0),
325
         data_in   => cpu_data_out,
326
         data_out  => ioport_data_out,
327
         porta_io  => porta,
328
         portb_io  => portb,
329
         portc_io  => portc,
330
         portd_io  => portd
331
    );
332
 
333
my_timer  : timer port map (
334
    clk       => cpu_clk,
335
         rst       => cpu_reset,
336
    cs        => timer_cs,
337
         rw        => cpu_rw,
338
    addr      => cpu_addr(2 downto 0),
339
         data_in   => cpu_data_out,
340
         data_out  => timer_data_out,
341
    irq_out   => timer_irq,
342
         tim0_in   => CountL(4),
343
         tim0_out  => timer0_out,
344
         tim1_in   => CountL(6),
345
         tim1_out  => timer1_out
346
    );
347
 
348
 
349
 
350
--bufginst: BUFG port map(
351
--    i => countL(0),
352
--       o => cpu_clk
353
--       );
354
 
355
-- bufginst: BUFG port map(i => SysClk, o => cpu_clk );  
356
 
357
----------------------------------------------------------------------
358
--
359
--  Processes to read and write memory based on bus signals
360
--
361
----------------------------------------------------------------------
362
 
363
memory_decode: process( Reset_n, cpu_clk,
364
                 cpu_addr, cpu_vma,
365
                                          rom_data_out, ram_data_out,
366
                                          ioport_data_out, timer_data_out, uart_data_out, bus_data )
367
begin
368
    case cpu_addr(15 downto 6) is
369
                when "1111111111" =>
370
                   cpu_data_in <= rom_data_out;
371
                        ram_cs      <= '0';
372
                   ioport_cs   <= '0';
373
                   timer_cs    <= '0';
374
                        uart_cs     <= '0';
375
                        bus_cs      <= '0';
376
                when "0000000000" =>
377
                   --
378
                        -- Decode 64 bytes of I/O space here
379
                        --
380
                        ram_cs <= '0';
381
                        case cpu_addr(5 downto 3) is
382
                           --
383
                                -- I/O ports $0000 - $0007
384
                                --  
385
                           when "000" =>
386
              cpu_data_in <= ioport_data_out;
387
                                  ioport_cs   <= cpu_vma;
388
                                  timer_cs    <= '0';
389
                             uart_cs     <= '0';
390
                             bus_cs      <= '0';
391
                                --
392
                                -- Timer $0008 - $000F
393
                                --
394
                                when "001" =>
395
                                  cpu_data_in <= timer_data_out;
396
                                  ioport_cs   <= '0';
397
                                  timer_cs    <= cpu_vma;
398
                             uart_cs     <= '0';
399
                             bus_cs      <= '0';
400
            --
401
                                -- ACIA $0010 - $0017
402
                                --
403
                           when "010" =>
404
                        cpu_data_in <= uart_data_out;
405
                                  ioport_cs   <= '0';
406
                                  timer_cs    <= '0';
407
                             uart_cs     <= cpu_vma;
408
                             bus_cs      <= '0';
409
            --
410
                                -- Reserved $0018 - $003F
411
                                --
412
                                when others =>
413
                                  cpu_data_in <= bus_data;
414
                                  ioport_cs   <= '0';
415
                                  timer_cs    <= '0';
416
                             uart_cs     <= '0';
417
                             bus_cs      <= cpu_vma;
418
         end case;
419
                when others =>
420
                  cpu_data_in <= ram_data_out;
421
                  ram_cs      <= cpu_vma;
422
                  ioport_cs   <= '0';
423
                  timer_cs    <= '0';
424
                  uart_cs     <= '0';
425
                  bus_cs      <= '0';
426
         end case;
427
end process;
428
 
429
--------------------------------------------------------------
430
--
431
-- B5 SRAM interface
432
--
433
--------------------------------------------------------------
434
Ram_decode: process( Reset_n, cpu_clk,
435
                     cpu_addr, cpu_rw, cpu_vma, cpu_data_out,
436
                     ram_cs, ram_wrl, ram_wru, ram_data )
437
begin
438
    cpu_reset <= not Reset_n;
439
         ram_wrl  <= (not cpu_rw) and cpu_addr(0);
440
    ram_wru  <= (not cpu_rw) and (not cpu_addr(0));
441
         ram_wrln <= not ram_wrl;
442
         ram_wrun <= not ram_wru;
443
    ram_csn  <= not( Reset_n and ram_cs and cpu_clk );
444
    ram_addr(16 downto 15) <= "00";
445
         ram_addr(14 downto 0) <= cpu_addr(15 downto 1);
446
 
447
    if ram_cs = '1' then
448
 
449
                if ram_wrl = '1' then
450
                  ram_data(7 downto 0) <= cpu_data_out;
451
                else
452
        ram_data(7 downto 0)  <= "ZZZZZZZZ";
453
                end if;
454
 
455
                if ram_wru = '1' then
456
                  ram_data(15 downto 8) <= cpu_data_out;
457
                else
458
        ram_data(15 downto 8)  <= "ZZZZZZZZ";
459
                end if;
460
 
461
    else
462
      ram_data(7 downto 0)  <= "ZZZZZZZZ";
463
      ram_data(15 downto 8) <= "ZZZZZZZZ";
464
    end if;
465
 
466
    if cpu_addr(0) = '0' then
467
           ram_data_out(7 downto 0) <= ram_data(15 downto 8);
468
         else
469
           ram_data_out(7 downto 0) <= ram_data(7 downto 0);
470
    end if;
471
 
472
end process;
473
 
474
--
475
-- CPU bus signals
476
--
477
my_bus : process( cpu_clk, cpu_reset, cpu_rw, cpu_addr, cpu_data_out )
478
begin
479
        bus_clk   <= cpu_clk;
480
   bus_reset <= cpu_reset;
481
        bus_rw    <= cpu_rw;
482
   bus_addr  <= cpu_addr;
483
        if( cpu_rw = '1' ) then
484
           bus_data <= "ZZZZZZZZ";
485
   else
486
           bus_data <= cpu_data_out;
487
   end if;
488
end process;
489
 
490
  --
491
  -- flash led to indicate code is working
492
  --
493
blink: process (SysClk, CountL )
494
begin
495
    if(SysClk'event and SysClk = '0') then
496
      countL <= countL + 1;
497
    end if;
498
         LED <= countL(21);
499
end process;
500
 
501
 
502
--
503
-- 57.6 Kbaud * 16 divider for 25 MHz system clock
504
--
505
my_baud_clock: process( SysClk )
506
begin
507
    if(SysClk'event and SysClk = '0') then
508
                if( BaudCount = 26 )    then
509
                   BaudCount <= "00000";
510
                else
511
                   BaudCount <= BaudCount + 1;
512
                end if;
513
    end if;
514
    baudclk <= BaudCount(4);  -- 25MHz / 27  = 926,000 KHz = 57,870Bd * 16
515
         dcd_n <= '0';
516
end process;
517
 
518
  --
519
  -- tie down inputs and outputs
520
  --
521
  -- CRTC output signals
522
  --
523
--       v_drive     <= '0';
524
--    h_drive     <= '0';
525
--    blue_lo     <= '0';
526
--    blue_hi     <= '0';
527
--    green_lo    <= '0';
528
--    green_hi    <= '0';
529
--    red_lo      <= '0';
530
--    red_hi      <= '0';
531
--       buzzer      <= '0';
532
 
533
  --
534
  -- tie down unused interrupts
535
  --
536
  ext_irq <= '0';
537
  cpu_clk <= SysClk;
538
 
539
-- *** Test Bench - User Defined Section ***
540
tb : PROCESS
541
        variable count : integer;
542
   BEGIN
543
 
544
        SysClk <= '0';
545
        Reset_n <= '0';
546
 
547
                for count in 0 to 512 loop
548
                        SysClk <= '0';
549
                        if count = 0 then
550
                                Reset_n <= '0';
551
                        elsif count = 1 then
552
                                Reset_n <= '1';
553
                        end if;
554
                        wait for 100 ns;
555
                        SysClk <= '1';
556
                        wait for 100 ns;
557
                end loop;
558
 
559
      wait; -- will wait forever
560
   END PROCESS;
561
 
562
 
563
end my_computer; --===================== End of architecture =======================--
564
 

powered by: WebSVN 2.1.0

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