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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_6_1_beta/] [bench/] [vhdl/] [tb.vhd] - Blame information for rev 306

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

Line No. Rev Author Line
1 8 arniml
-------------------------------------------------------------------------------
2
--
3
-- The testbench for t48_core.
4
--
5 201 arniml
-- $Id: tb.vhd,v 1.12 2005-11-01 21:21:48 arniml Exp $
6 8 arniml
--
7
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
8
--
9
-- All rights reserved
10
--
11
-- Redistribution and use in source and synthezised forms, with or without
12
-- modification, are permitted provided that the following conditions are met:
13
--
14
-- Redistributions of source code must retain the above copyright notice,
15
-- this list of conditions and the following disclaimer.
16
--
17
-- Redistributions in synthesized form must reproduce the above copyright
18
-- notice, this list of conditions and the following disclaimer in the
19
-- documentation and/or other materials provided with the distribution.
20
--
21
-- Neither the name of the author nor the names of other contributors may
22
-- be used to endorse or promote products derived from this software without
23
-- specific prior written permission.
24
--
25
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
29
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
-- POSSIBILITY OF SUCH DAMAGE.
36
--
37
-- Please report bugs to the author, but before you do so, please
38
-- make sure that this is not a derivative work and that
39
-- you have the latest version of this file.
40
--
41
-- The latest version of this file can be found at:
42
--      http://www.opencores.org/cvsweb.shtml/t48/
43
--
44
-------------------------------------------------------------------------------
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
 
49
entity tb is
50
 
51
end tb;
52
 
53
 
54
use work.t48_core_comp_pack.all;
55
 
56
use work.t48_tb_pack.all;
57
 
58
architecture behav of tb is
59
 
60
  -- clock period, 11 MHz
61
  constant period_c : time := 90 ns;
62
 
63 80 arniml
  component if_timing
64
    port(
65
      xtal_i   : in std_logic;
66
      ale_i    : in std_logic;
67
      psen_n_i : in std_logic;
68
      rd_n_i   : in std_logic;
69
      wr_n_i   : in std_logic;
70
      prog_n_i : in std_logic;
71
      db_bus_i : in std_logic_vector(7 downto 0);
72
      p2_i     : in std_logic_vector(7 downto 0)
73
    );
74
  end component;
75
 
76 111 arniml
  component lpm_rom
77
    generic (
78
      LPM_WIDTH           : positive;
79
      LPM_TYPE            : string    := "LPM_ROM";
80
      LPM_WIDTHAD         : positive;
81
      LPM_NUMWORDS        : natural   := 0;
82
      LPM_FILE            : string;
83
      LPM_ADDRESS_CONTROL : string    := "REGISTERED";
84
      LPM_OUTDATA         : string    := "REGISTERED";
85
      LPM_HINT            : string    := "UNUSED"
86
    );
87
    port (
88
      address             : in  std_logic_vector(LPM_WIDTHAD-1 downto 0);
89
      inclock             : in  std_logic;
90 183 arniml
      outclock            : in  std_logic;
91 111 arniml
      memenab             : in  std_logic;
92
      q                   : out std_logic_vector(LPM_WIDTH-1 downto 0)
93
    );
94
  end component;
95
 
96 8 arniml
  signal xtal_s          : std_logic;
97 10 arniml
  signal xtal_n_s        : std_logic;
98 8 arniml
  signal res_n_s         : std_logic;
99
  signal xtal3_s         : std_logic;
100
  signal int_n_s         : std_logic;
101
  signal ale_s           : std_logic;
102
  signal rom_addr_s      : std_logic_vector(11 downto 0);
103
  signal rom_data_s      : std_logic_vector( 7 downto 0);
104
  signal ram_data_to_s   : std_logic_vector( 7 downto 0);
105
  signal ram_data_from_s : std_logic_vector( 7 downto 0);
106
  signal ram_addr_s      : std_logic_vector( 7 downto 0);
107
  signal ram_we_s        : std_logic;
108
 
109
  signal p1_s            : std_logic_vector( 7 downto 0);
110
  signal t48_p1_s        : std_logic_vector( 7 downto 0);
111 33 arniml
  signal p1_low_imp_s    : std_logic;
112 8 arniml
  signal p2_s            : std_logic_vector( 7 downto 0);
113
  signal t48_p2_s        : std_logic_vector( 7 downto 0);
114 201 arniml
  signal p2l_low_imp_s   : std_logic;
115
  signal p2h_low_imp_s   : std_logic;
116 80 arniml
  signal psen_n_s        : std_logic;
117 30 arniml
  signal prog_n_s        : std_logic;
118 8 arniml
 
119
  signal bus_s           : std_logic_vector( 7 downto 0);
120
  signal t48_bus_s       : std_logic_vector( 7 downto 0);
121
  signal bus_dir_s       : std_logic;
122
 
123 111 arniml
  signal ext_mem_addr_q      : std_logic_vector( 7 downto 0);
124 8 arniml
  signal ext_ram_data_from_s : std_logic_vector( 7 downto 0);
125 111 arniml
  signal ext_ram_we_q        : std_logic;
126 8 arniml
  signal rd_n_s              : std_logic;
127
  signal wr_n_s              : std_logic;
128
 
129 111 arniml
  signal ext_rom_data_s  : std_logic_vector( 7 downto 0);
130
  signal ext_rom_addr_s  : std_logic_vector(11 downto 0);
131
 
132 103 arniml
  signal tb_p1_q : std_logic_vector( 7 downto 0);
133
  signal tb_p2_q : std_logic_vector( 7 downto 0);
134
 
135 111 arniml
  signal ext_mem_sel_we_q : boolean;
136
  signal ena_ext_ram_q    : boolean;
137
  signal ena_tb_periph_q  : boolean;
138 103 arniml
 
139 8 arniml
  signal zero_s          : std_logic;
140
  signal one_s           : std_logic;
141
  signal zero_byte_s     : std_logic_vector( 7 downto 0);
142
 
143
begin
144
 
145
  zero_s      <= '0';
146
  one_s       <= '1';
147
  zero_byte_s <= (others => '0');
148
 
149 111 arniml
  -----------------------------------------------------------------------------
150
  -- Internal ROM, 2k bytes
151
  -- Initialized by file t48_rom.hex.
152
  -----------------------------------------------------------------------------
153
  rom_internal_2k : lpm_rom
154 8 arniml
    generic map (
155 111 arniml
      LPM_WIDTH           => 8,
156
      LPM_TYPE            => "LPM_ROM",
157
      LPM_WIDTHAD         => 11,
158
      LPM_NUMWORDS        => 2 ** 11,
159
      LPM_FILE            => "t48_rom.hex",
160
      LPM_ADDRESS_CONTROL => "REGISTERED",
161
      LPM_OUTDATA         => "UNREGISTERED",
162
      LPM_HINT            => "UNUSED"
163 8 arniml
    )
164
    port map (
165 111 arniml
      address  => rom_addr_s(10 downto 0),
166
      inclock  => xtal_s,
167 183 arniml
      outclock => zero_s,               -- unused
168 111 arniml
      memenab  => one_s,
169
      q        => rom_data_s
170 8 arniml
    );
171
 
172 111 arniml
  -----------------------------------------------------------------------------
173
  -- External ROM, 2k bytes
174
  -- Initialized by file t48_ext_rom.hex.
175
  -----------------------------------------------------------------------------
176
  ext_rom_addr_s(11 downto 8) <= t48_p2_s(3 downto 0);
177
  ext_rom_addr_s( 7 downto 0) <= ext_mem_addr_q;
178
  rom_external_2k : lpm_rom
179
    generic map (
180
      LPM_WIDTH           => 8,
181
      LPM_TYPE            => "LPM_ROM",
182
      LPM_WIDTHAD         => 11,
183
      LPM_NUMWORDS        => 2 ** 11,
184
      LPM_FILE            => "t48_ext_rom.hex",
185
      LPM_ADDRESS_CONTROL => "REGISTERED",
186
      LPM_OUTDATA         => "UNREGISTERED",
187
      LPM_HINT            => "UNUSED"
188
    )
189
    port map (
190
      address  => ext_rom_addr_s(10 downto 0),
191
      inclock  => xtal_s,
192 183 arniml
      outclock => zero_s,               -- unused
193 111 arniml
      memenab  => one_s,
194
      q        => ext_rom_data_s
195
    );
196
 
197
  -----------------------------------------------------------------------------
198
  -- Internal RAM, 256 bytes
199
  -----------------------------------------------------------------------------
200 8 arniml
  ram_256 : syn_ram
201
    generic map (
202
      address_width_g => 8
203
    )
204
    port map (
205
      clk_i      => xtal_s,
206
      res_i      => res_n_s,
207
      ram_addr_i => ram_addr_s,
208
      ram_data_i => ram_data_to_s,
209
      ram_we_i   => ram_we_s,
210
      ram_data_o => ram_data_from_s
211
    );
212
 
213 111 arniml
  -----------------------------------------------------------------------------
214
  -- External RAM, 256 bytes
215
  -----------------------------------------------------------------------------
216 8 arniml
  ext_ram_b : syn_ram
217
    generic map (
218
      address_width_g => 8
219
    )
220
    port map (
221
      clk_i      => xtal_s,
222
      res_i      => res_n_s,
223 111 arniml
      ram_addr_i => ext_mem_addr_q,
224 8 arniml
      ram_data_i => bus_s,
225 111 arniml
      ram_we_i   => ext_ram_we_q,
226 8 arniml
      ram_data_o => ext_ram_data_from_s
227
    );
228
 
229
  t48_core_b : t48_core
230
    generic map (
231
      xtal_div_3_g        => 1,
232
      register_mnemonic_g => 1,
233
      include_port1_g     => 1,
234
      include_port2_g     => 1,
235
      include_bus_g       => 1,
236
      include_timer_g     => 1,
237
      sample_t1_state_g   => 4
238
    )
239
    port map (
240 201 arniml
      xtal_i        => xtal_s,
241
      reset_i       => res_n_s,
242
      t0_i          => p1_s(0),
243
      t0_o          => open,
244
      t0_dir_o      => open,
245
      int_n_i       => int_n_s,
246
      ea_i          => rom_addr_s(11),
247
      rd_n_o        => rd_n_s,
248
      psen_n_o      => psen_n_s,
249
      wr_n_o        => wr_n_s,
250
      ale_o         => ale_s,
251
      db_i          => bus_s,
252
      db_o          => t48_bus_s,
253
      db_dir_o      => bus_dir_s,
254
      t1_i          => p1_s(1),
255
      p2_i          => p2_s,
256
      p2_o          => t48_p2_s,
257
      p2l_low_imp_o => p2l_low_imp_s,
258
      p2h_low_imp_o => p2h_low_imp_s,
259
      p1_i          => p1_s,
260
      p1_o          => t48_p1_s,
261
      p1_low_imp_o  => p1_low_imp_s,
262
      prog_n_o      => prog_n_s,
263
      clk_i         => xtal_s,
264
      en_clk_i      => xtal3_s,
265
      xtal3_o       => xtal3_s,
266
      dmem_addr_o   => ram_addr_s,
267
      dmem_we_o     => ram_we_s,
268
      dmem_data_i   => ram_data_from_s,
269
      dmem_data_o   => ram_data_to_s,
270
      pmem_addr_o   => rom_addr_s,
271
      pmem_data_i   => rom_data_s
272 8 arniml
    );
273
 
274 80 arniml
  if_timing_b : if_timing
275
    port map (
276
      xtal_i   => xtal_s,
277
      ale_i    => ale_s,
278
      psen_n_i => psen_n_s,
279
      rd_n_i   => rd_n_s,
280
      wr_n_i   => wr_n_s,
281
      prog_n_i => prog_n_s,
282
      db_bus_i => bus_s,
283 83 arniml
      p2_i     => t48_p2_s
284 80 arniml
    );
285 8 arniml
 
286 80 arniml
 
287 8 arniml
  -----------------------------------------------------------------------------
288
  -- Port logic
289
  --
290
  ports: process (t48_p1_s,
291 33 arniml
                  p1_low_imp_s,
292 8 arniml
                  t48_p2_s,
293 201 arniml
                  p2l_low_imp_s,
294
                  p2h_low_imp_s)
295
    function t48_port_f(t48_p   : std_logic_vector;
296 33 arniml
                        low_imp : std_logic) return std_logic_vector is
297 201 arniml
      variable p_v : std_logic_vector(t48_p'range);
298 8 arniml
    begin
299 33 arniml
      if low_imp = '1' then
300 8 arniml
        p_v := t48_p;
301
 
302
      else
303
        for i in p_v'range loop
304
          if t48_p(i) = '1' then
305
            p_v(i) := 'H';
306
          else
307
            p_v(i) := t48_p(i);
308
          end if;
309
        end loop;
310
 
311
      end if;
312
 
313
      return p_v;
314
    end;
315
 
316
  begin
317
 
318 33 arniml
    p1_s <= t48_port_f(t48_p   => t48_p1_s,
319
                       low_imp => p1_low_imp_s);
320 8 arniml
 
321 201 arniml
    p2_s(3 downto 0) <= t48_port_f(t48_p   => t48_p2_s(3 downto 0),
322
                                   low_imp => p2l_low_imp_s);
323
    p2_s(7 downto 4) <= t48_port_f(t48_p   => t48_p2_s(7 downto 4),
324
                                   low_imp => p2h_low_imp_s);
325 8 arniml
 
326
  end process ports;
327
  --
328
  -----------------------------------------------------------------------------
329
 
330
  bus_s <=   t48_bus_s
331
           when bus_dir_s = '1' else
332
             (others => 'Z');
333
 
334
  bus_s <=   ext_ram_data_from_s
335 111 arniml
           when rd_n_s = '0' and ena_ext_ram_q else
336 8 arniml
             (others => 'Z');
337
 
338 111 arniml
  bus_s <=   ext_rom_data_s
339
           when psen_n_s = '0' else
340
             (others => 'Z');
341 8 arniml
 
342 111 arniml
 
343 8 arniml
  -----------------------------------------------------------------------------
344 103 arniml
  -- External memory access signals
345 8 arniml
  --
346 103 arniml
  ext_mem: process (wr_n_s,
347 111 arniml
                    ext_mem_addr_q,
348
                    ena_ext_ram_q,
349 8 arniml
                    ale_s,
350
                    bus_s,
351
                    xtal_s)
352
  begin
353
    if ale_s'event and ale_s = '0' then
354
      if not is_X(bus_s) then
355 111 arniml
        ext_mem_addr_q <= bus_s;
356 8 arniml
      else
357 111 arniml
        ext_mem_addr_q <= (others => '0');
358 8 arniml
      end if;
359
    end if;
360
 
361
    if wr_n_s'event and wr_n_s = '1' then
362 103 arniml
      -- write enable for external RAM
363 111 arniml
      if ena_ext_ram_q then
364
        ext_ram_we_q <= '1';
365 103 arniml
      end if;
366
 
367
      -- process external memory selector
368 111 arniml
      if ext_mem_addr_q = "11111111" then
369
        ext_mem_sel_we_q <= true;
370 103 arniml
      end if;
371
 
372 8 arniml
    end if;
373
 
374 10 arniml
    if xtal_s'event and xtal_s = '1' then
375 111 arniml
      ext_ram_we_q     <= '0';
376
      ext_mem_sel_we_q <= false;
377 8 arniml
    end if;
378
 
379 103 arniml
  end process ext_mem;
380 8 arniml
  --
381
  -----------------------------------------------------------------------------
382
 
383 103 arniml
 
384
  -----------------------------------------------------------------------------
385
  -- Process ext_mem_sel
386
  --
387
  -- Purpose:
388
  --   Select external memory address space.
389
  --   This is either
390
  --     + external RAM
391
  --     + testbench peripherals
392
  --
393
  ext_mem_sel: process (res_n_s, xtal_s)
394
  begin
395
    if res_n_s = '0' then
396 111 arniml
      ena_ext_ram_q       <= true;
397
      ena_tb_periph_q     <= false;
398 103 arniml
 
399
    elsif xtal_s'event and xtal_s = '1' then
400 111 arniml
      if ext_mem_sel_we_q then
401 103 arniml
        if bus_s(0) = '1' then
402 111 arniml
          ena_ext_ram_q   <= true;
403 103 arniml
        else
404 111 arniml
          ena_ext_ram_q   <= false;
405 103 arniml
        end if;
406
 
407
        if bus_s(1) = '1' then
408 111 arniml
          ena_tb_periph_q <= true;
409 103 arniml
        else
410 111 arniml
          ena_tb_periph_q <= false;
411 103 arniml
        end if;
412
      end if;
413
 
414
    end if;
415
 
416
  end process ext_mem_sel;
417
  --
418
  -----------------------------------------------------------------------------
419
 
420
 
421
  -----------------------------------------------------------------------------
422
  -- Process tb_periph
423
  --
424
  -- Purpose:
425
  --   Implements the testbenc peripherals driving P1 and P2.
426
  --
427
  tb_periph: process (res_n_s, wr_n_s)
428
 
429
    function oc_f (pX : std_logic_vector) return std_logic_vector is
430
      variable r_v : std_logic_vector(pX'range);
431
    begin
432
      for i in pX'range loop
433
        if pX(i) = '0' then
434
          r_v(i) := '0';
435
        else
436
          r_v(i) := 'H';
437
        end if;
438
      end loop;
439
 
440
      return r_v;
441
    end;
442
 
443
  begin
444
    if res_n_s = '0' then
445
      tb_p1_q <= (others => 'H');
446
      tb_p2_q <= (others => 'H');
447
 
448
    elsif wr_n_s'event and wr_n_s = '1' then
449 111 arniml
      if ena_tb_periph_q then
450
        case ext_mem_addr_q is
451 103 arniml
          -- P1
452
          when "00000000" =>
453
            tb_p1_q <= oc_f(t48_bus_s);
454
 
455
          -- P2
456
          when "00000001" =>
457
            tb_p2_q <= oc_f(t48_bus_s);
458
 
459
          when others =>
460
            null;
461
 
462
        end case;
463
 
464
      end if;
465
 
466
    end if;
467
 
468
  end process tb_periph;
469
  --
470
  -----------------------------------------------------------------------------
471
 
472
  p1_s <= tb_p1_q;
473
  p2_s <= tb_p2_q;
474
 
475
 
476 10 arniml
  xtal_n_s <= not xtal_s;
477
 
478 8 arniml
  -----------------------------------------------------------------------------
479
  -- The clock generator
480
  --
481
  clk_gen: process
482
  begin
483
    xtal_s <= '0';
484
    wait for period_c/2;
485
    xtal_s <= '1';
486
    wait for period_c/2;
487
  end process clk_gen;
488
  --
489
  -----------------------------------------------------------------------------
490
 
491
 
492
  -----------------------------------------------------------------------------
493
  -- The reset generator
494
  --
495
  res_gen: process
496
  begin
497
    res_n_s <= '0';
498
    wait for 5 * period_c;
499
    res_n_s <= '1';
500
    wait;
501
  end process res_gen;
502
  --
503
  -----------------------------------------------------------------------------
504
 
505
 
506
  -----------------------------------------------------------------------------
507
  -- The interrupt generator
508
  --
509
  int_gen: process
510
  begin
511
    int_n_s <= '1';
512
    wait for 750 * period_c;
513
    int_n_s <= '0';
514
    wait for  45 * period_c;
515
  end process int_gen;
516
  --
517
  -----------------------------------------------------------------------------
518
 
519
 
520
  -----------------------------------------------------------------------------
521
  -- End of simulation detection
522
  --
523
  eos: process
524
  begin
525
 
526
    outer: loop
527
      wait on tb_accu_s;
528
      if tb_accu_s = "10101010" then
529
        wait on tb_accu_s;
530
        if tb_accu_s = "01010101" then
531
          wait on tb_accu_s;
532
          if tb_accu_s = "00000001" then
533 56 arniml
            -- wait for instruction strobe of this move
534
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
535
            -- wait for next strobe
536
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
537 8 arniml
            assert false
538 19 arniml
              report "Simulation Result: PASS."
539 8 arniml
              severity note;
540
          else
541
            assert false
542 19 arniml
              report "Simulation Result: FAIL."
543 8 arniml
              severity note;
544
          end if;
545
 
546
          assert false
547
            report "End of simulation reached."
548
            severity failure;
549
 
550
        end if;
551
      end if;
552
    end loop;
553
 
554
  end process eos;
555
  --
556
  -----------------------------------------------------------------------------
557
 
558
end behav;
559
 
560
 
561
-------------------------------------------------------------------------------
562
-- File History:
563
--
564
-- $Log: not supported by cvs2svn $
565 201 arniml
-- Revision 1.11  2005/09/07 17:39:40  arniml
566
-- fix missing assignment to outclock
567
--
568 183 arniml
-- Revision 1.10  2004/05/21 11:24:47  arniml
569
-- split 4k internal ROM into
570
--   + 2k internal ROM
571
--   + 2k external ROM
572
-- EA of t48_core is driven by MSB of internal ROM address
573
-- if upper 2k block is selected, the system switches to EA mode on the fly
574
--
575 111 arniml
-- Revision 1.9  2004/05/17 14:43:33  arniml
576
-- add testbench peripherals for P1 and P2
577
-- this became necessary to observe a difference between externally applied
578
-- port data and internally applied port data
579
--
580 103 arniml
-- Revision 1.8  2004/04/25 20:41:48  arniml
581
-- connect if_timing to P2 output of T48
582
--
583 83 arniml
-- Revision 1.7  2004/04/25 16:23:21  arniml
584
-- added if_timing
585
--
586 80 arniml
-- Revision 1.6  2004/04/14 20:57:44  arniml
587
-- wait for instruction strobe after final end-of-simulation detection
588
-- this ensures that the last mov instruction is part of the dump and
589
-- enables 100% matching with i8039 simulator
590
--
591 56 arniml
-- Revision 1.5  2004/03/29 19:45:15  arniml
592
-- rename pX_limp to pX_low_imp
593
--
594 33 arniml
-- Revision 1.4  2004/03/28 21:30:25  arniml
595
-- connect prog_n_o
596
--
597 30 arniml
-- Revision 1.3  2004/03/26 22:39:28  arniml
598
-- enhance simulation result string
599
--
600 19 arniml
-- Revision 1.2  2004/03/24 23:22:35  arniml
601
-- put ext_ram on falling clock edge to sample the write enable properly
602
--
603 10 arniml
-- Revision 1.1  2004/03/24 21:42:10  arniml
604
-- initial check-in
605
--
606 8 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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