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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_2_beta/] [bench/] [vhdl/] [tb.vhd] - Blame information for rev 329

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 111 arniml
-- $Id: tb.vhd,v 1.10 2004-05-21 11:24:47 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
      memenab             : in  std_logic;
91
      q                   : out std_logic_vector(LPM_WIDTH-1 downto 0)
92
    );
93
  end component;
94
 
95 8 arniml
  signal xtal_s          : std_logic;
96 10 arniml
  signal xtal_n_s        : std_logic;
97 8 arniml
  signal res_n_s         : std_logic;
98
  signal xtal3_s         : std_logic;
99
  signal int_n_s         : std_logic;
100
  signal ale_s           : std_logic;
101
  signal rom_addr_s      : std_logic_vector(11 downto 0);
102
  signal rom_data_s      : std_logic_vector( 7 downto 0);
103
  signal ram_data_to_s   : std_logic_vector( 7 downto 0);
104
  signal ram_data_from_s : std_logic_vector( 7 downto 0);
105
  signal ram_addr_s      : std_logic_vector( 7 downto 0);
106
  signal ram_we_s        : std_logic;
107
 
108
  signal p1_s            : std_logic_vector( 7 downto 0);
109
  signal t48_p1_s        : std_logic_vector( 7 downto 0);
110 33 arniml
  signal p1_low_imp_s    : std_logic;
111 8 arniml
  signal p2_s            : std_logic_vector( 7 downto 0);
112
  signal t48_p2_s        : std_logic_vector( 7 downto 0);
113 33 arniml
  signal p2_low_imp_s    : std_logic;
114 80 arniml
  signal psen_n_s        : std_logic;
115 30 arniml
  signal prog_n_s        : std_logic;
116 8 arniml
 
117
  signal bus_s           : std_logic_vector( 7 downto 0);
118
  signal t48_bus_s       : std_logic_vector( 7 downto 0);
119
  signal bus_dir_s       : std_logic;
120
 
121 111 arniml
  signal ext_mem_addr_q      : std_logic_vector( 7 downto 0);
122 8 arniml
  signal ext_ram_data_from_s : std_logic_vector( 7 downto 0);
123 111 arniml
  signal ext_ram_we_q        : std_logic;
124 8 arniml
  signal rd_n_s              : std_logic;
125
  signal wr_n_s              : std_logic;
126
 
127 111 arniml
  signal ext_rom_data_s  : std_logic_vector( 7 downto 0);
128
  signal ext_rom_addr_s  : std_logic_vector(11 downto 0);
129
 
130 103 arniml
  signal tb_p1_q : std_logic_vector( 7 downto 0);
131
  signal tb_p2_q : std_logic_vector( 7 downto 0);
132
 
133 111 arniml
  signal ext_mem_sel_we_q : boolean;
134
  signal ena_ext_ram_q    : boolean;
135
  signal ena_tb_periph_q  : boolean;
136 103 arniml
 
137 8 arniml
  signal zero_s          : std_logic;
138
  signal one_s           : std_logic;
139
  signal zero_byte_s     : std_logic_vector( 7 downto 0);
140
 
141
begin
142
 
143
  zero_s      <= '0';
144
  one_s       <= '1';
145
  zero_byte_s <= (others => '0');
146
 
147 111 arniml
  -----------------------------------------------------------------------------
148
  -- Internal ROM, 2k bytes
149
  -- Initialized by file t48_rom.hex.
150
  -----------------------------------------------------------------------------
151
  rom_internal_2k : lpm_rom
152 8 arniml
    generic map (
153 111 arniml
      LPM_WIDTH           => 8,
154
      LPM_TYPE            => "LPM_ROM",
155
      LPM_WIDTHAD         => 11,
156
      LPM_NUMWORDS        => 2 ** 11,
157
      LPM_FILE            => "t48_rom.hex",
158
      LPM_ADDRESS_CONTROL => "REGISTERED",
159
      LPM_OUTDATA         => "UNREGISTERED",
160
      LPM_HINT            => "UNUSED"
161 8 arniml
    )
162
    port map (
163 111 arniml
      address  => rom_addr_s(10 downto 0),
164
      inclock  => xtal_s,
165
      memenab  => one_s,
166
      q        => rom_data_s
167 8 arniml
    );
168
 
169 111 arniml
  -----------------------------------------------------------------------------
170
  -- External ROM, 2k bytes
171
  -- Initialized by file t48_ext_rom.hex.
172
  -----------------------------------------------------------------------------
173
  ext_rom_addr_s(11 downto 8) <= t48_p2_s(3 downto 0);
174
  ext_rom_addr_s( 7 downto 0) <= ext_mem_addr_q;
175
  rom_external_2k : lpm_rom
176
    generic map (
177
      LPM_WIDTH           => 8,
178
      LPM_TYPE            => "LPM_ROM",
179
      LPM_WIDTHAD         => 11,
180
      LPM_NUMWORDS        => 2 ** 11,
181
      LPM_FILE            => "t48_ext_rom.hex",
182
      LPM_ADDRESS_CONTROL => "REGISTERED",
183
      LPM_OUTDATA         => "UNREGISTERED",
184
      LPM_HINT            => "UNUSED"
185
    )
186
    port map (
187
      address  => ext_rom_addr_s(10 downto 0),
188
      inclock  => xtal_s,
189
      memenab  => one_s,
190
      q        => ext_rom_data_s
191
    );
192
 
193
  -----------------------------------------------------------------------------
194
  -- Internal RAM, 256 bytes
195
  -----------------------------------------------------------------------------
196 8 arniml
  ram_256 : syn_ram
197
    generic map (
198
      address_width_g => 8
199
    )
200
    port map (
201
      clk_i      => xtal_s,
202
      res_i      => res_n_s,
203
      ram_addr_i => ram_addr_s,
204
      ram_data_i => ram_data_to_s,
205
      ram_we_i   => ram_we_s,
206
      ram_data_o => ram_data_from_s
207
    );
208
 
209 111 arniml
  -----------------------------------------------------------------------------
210
  -- External RAM, 256 bytes
211
  -----------------------------------------------------------------------------
212 8 arniml
  ext_ram_b : syn_ram
213
    generic map (
214
      address_width_g => 8
215
    )
216
    port map (
217
      clk_i      => xtal_s,
218
      res_i      => res_n_s,
219 111 arniml
      ram_addr_i => ext_mem_addr_q,
220 8 arniml
      ram_data_i => bus_s,
221 111 arniml
      ram_we_i   => ext_ram_we_q,
222 8 arniml
      ram_data_o => ext_ram_data_from_s
223
    );
224
 
225
  t48_core_b : t48_core
226
    generic map (
227
      xtal_div_3_g        => 1,
228
      register_mnemonic_g => 1,
229
      include_port1_g     => 1,
230
      include_port2_g     => 1,
231
      include_bus_g       => 1,
232
      include_timer_g     => 1,
233
      sample_t1_state_g   => 4
234
    )
235
    port map (
236 33 arniml
      xtal_i       => xtal_s,
237
      reset_i      => res_n_s,
238
      t0_i         => p1_s(0),
239
      t0_o         => open,
240
      t0_dir_o     => open,
241
      int_n_i      => int_n_s,
242 111 arniml
      ea_i         => rom_addr_s(11),
243 33 arniml
      rd_n_o       => rd_n_s,
244 80 arniml
      psen_n_o     => psen_n_s,
245 33 arniml
      wr_n_o       => wr_n_s,
246
      ale_o        => ale_s,
247
      db_i         => bus_s,
248
      db_o         => t48_bus_s,
249
      db_dir_o     => bus_dir_s,
250
      t1_i         => p1_s(1),
251
      p2_i         => p2_s,
252
      p2_o         => t48_p2_s,
253
      p2_low_imp_o => p2_low_imp_s,
254
      p1_i         => p1_s,
255
      p1_o         => t48_p1_s,
256
      p1_low_imp_o => p1_low_imp_s,
257
      prog_n_o     => prog_n_s,
258
      clk_i        => xtal_s,
259
      en_clk_i     => xtal3_s,
260
      xtal3_o      => xtal3_s,
261
      dmem_addr_o  => ram_addr_s,
262
      dmem_we_o    => ram_we_s,
263
      dmem_data_i  => ram_data_from_s,
264
      dmem_data_o  => ram_data_to_s,
265
      pmem_addr_o  => rom_addr_s,
266
      pmem_data_i  => rom_data_s
267 8 arniml
    );
268
 
269 80 arniml
  if_timing_b : if_timing
270
    port map (
271
      xtal_i   => xtal_s,
272
      ale_i    => ale_s,
273
      psen_n_i => psen_n_s,
274
      rd_n_i   => rd_n_s,
275
      wr_n_i   => wr_n_s,
276
      prog_n_i => prog_n_s,
277
      db_bus_i => bus_s,
278 83 arniml
      p2_i     => t48_p2_s
279 80 arniml
    );
280 8 arniml
 
281 80 arniml
 
282 8 arniml
  -----------------------------------------------------------------------------
283
  -- Port logic
284
  --
285
  ports: process (t48_p1_s,
286 33 arniml
                  p1_low_imp_s,
287 8 arniml
                  t48_p2_s,
288 33 arniml
                  p2_low_imp_s)
289
    function t48_port_f(t48_p   : std_logic_vector(7 downto 0);
290
                        low_imp : std_logic) return std_logic_vector is
291 8 arniml
      variable p_v : std_logic_vector(7 downto 0);
292
    begin
293 33 arniml
      if low_imp = '1' then
294 8 arniml
        p_v := t48_p;
295
 
296
      else
297
        for i in p_v'range loop
298
          if t48_p(i) = '1' then
299
            p_v(i) := 'H';
300
          else
301
            p_v(i) := t48_p(i);
302
          end if;
303
        end loop;
304
 
305
      end if;
306
 
307
      return p_v;
308
    end;
309
 
310
  begin
311
 
312 33 arniml
    p1_s <= t48_port_f(t48_p   => t48_p1_s,
313
                       low_imp => p1_low_imp_s);
314 8 arniml
 
315 33 arniml
    p2_s <= t48_port_f(t48_p   => t48_p2_s,
316
                       low_imp => p2_low_imp_s);
317 8 arniml
 
318
  end process ports;
319
  --
320
  -----------------------------------------------------------------------------
321
 
322
  bus_s <=   t48_bus_s
323
           when bus_dir_s = '1' else
324
             (others => 'Z');
325
 
326
  bus_s <=   ext_ram_data_from_s
327 111 arniml
           when rd_n_s = '0' and ena_ext_ram_q else
328 8 arniml
             (others => 'Z');
329
 
330 111 arniml
  bus_s <=   ext_rom_data_s
331
           when psen_n_s = '0' else
332
             (others => 'Z');
333 8 arniml
 
334 111 arniml
 
335 8 arniml
  -----------------------------------------------------------------------------
336 103 arniml
  -- External memory access signals
337 8 arniml
  --
338 103 arniml
  ext_mem: process (wr_n_s,
339 111 arniml
                    ext_mem_addr_q,
340
                    ena_ext_ram_q,
341 8 arniml
                    ale_s,
342
                    bus_s,
343
                    xtal_s)
344
  begin
345
    if ale_s'event and ale_s = '0' then
346
      if not is_X(bus_s) then
347 111 arniml
        ext_mem_addr_q <= bus_s;
348 8 arniml
      else
349 111 arniml
        ext_mem_addr_q <= (others => '0');
350 8 arniml
      end if;
351
    end if;
352
 
353
    if wr_n_s'event and wr_n_s = '1' then
354 103 arniml
      -- write enable for external RAM
355 111 arniml
      if ena_ext_ram_q then
356
        ext_ram_we_q <= '1';
357 103 arniml
      end if;
358
 
359
      -- process external memory selector
360 111 arniml
      if ext_mem_addr_q = "11111111" then
361
        ext_mem_sel_we_q <= true;
362 103 arniml
      end if;
363
 
364 8 arniml
    end if;
365
 
366 10 arniml
    if xtal_s'event and xtal_s = '1' then
367 111 arniml
      ext_ram_we_q     <= '0';
368
      ext_mem_sel_we_q <= false;
369 8 arniml
    end if;
370
 
371 103 arniml
  end process ext_mem;
372 8 arniml
  --
373
  -----------------------------------------------------------------------------
374
 
375 103 arniml
 
376
  -----------------------------------------------------------------------------
377
  -- Process ext_mem_sel
378
  --
379
  -- Purpose:
380
  --   Select external memory address space.
381
  --   This is either
382
  --     + external RAM
383
  --     + testbench peripherals
384
  --
385
  ext_mem_sel: process (res_n_s, xtal_s)
386
  begin
387
    if res_n_s = '0' then
388 111 arniml
      ena_ext_ram_q       <= true;
389
      ena_tb_periph_q     <= false;
390 103 arniml
 
391
    elsif xtal_s'event and xtal_s = '1' then
392 111 arniml
      if ext_mem_sel_we_q then
393 103 arniml
        if bus_s(0) = '1' then
394 111 arniml
          ena_ext_ram_q   <= true;
395 103 arniml
        else
396 111 arniml
          ena_ext_ram_q   <= false;
397 103 arniml
        end if;
398
 
399
        if bus_s(1) = '1' then
400 111 arniml
          ena_tb_periph_q <= true;
401 103 arniml
        else
402 111 arniml
          ena_tb_periph_q <= false;
403 103 arniml
        end if;
404
      end if;
405
 
406
    end if;
407
 
408
  end process ext_mem_sel;
409
  --
410
  -----------------------------------------------------------------------------
411
 
412
 
413
  -----------------------------------------------------------------------------
414
  -- Process tb_periph
415
  --
416
  -- Purpose:
417
  --   Implements the testbenc peripherals driving P1 and P2.
418
  --
419
  tb_periph: process (res_n_s, wr_n_s)
420
 
421
    function oc_f (pX : std_logic_vector) return std_logic_vector is
422
      variable r_v : std_logic_vector(pX'range);
423
    begin
424
      for i in pX'range loop
425
        if pX(i) = '0' then
426
          r_v(i) := '0';
427
        else
428
          r_v(i) := 'H';
429
        end if;
430
      end loop;
431
 
432
      return r_v;
433
    end;
434
 
435
  begin
436
    if res_n_s = '0' then
437
      tb_p1_q <= (others => 'H');
438
      tb_p2_q <= (others => 'H');
439
 
440
    elsif wr_n_s'event and wr_n_s = '1' then
441 111 arniml
      if ena_tb_periph_q then
442
        case ext_mem_addr_q is
443 103 arniml
          -- P1
444
          when "00000000" =>
445
            tb_p1_q <= oc_f(t48_bus_s);
446
 
447
          -- P2
448
          when "00000001" =>
449
            tb_p2_q <= oc_f(t48_bus_s);
450
 
451
          when others =>
452
            null;
453
 
454
        end case;
455
 
456
      end if;
457
 
458
    end if;
459
 
460
  end process tb_periph;
461
  --
462
  -----------------------------------------------------------------------------
463
 
464
  p1_s <= tb_p1_q;
465
  p2_s <= tb_p2_q;
466
 
467
 
468 10 arniml
  xtal_n_s <= not xtal_s;
469
 
470 8 arniml
  -----------------------------------------------------------------------------
471
  -- The clock generator
472
  --
473
  clk_gen: process
474
  begin
475
    xtal_s <= '0';
476
    wait for period_c/2;
477
    xtal_s <= '1';
478
    wait for period_c/2;
479
  end process clk_gen;
480
  --
481
  -----------------------------------------------------------------------------
482
 
483
 
484
  -----------------------------------------------------------------------------
485
  -- The reset generator
486
  --
487
  res_gen: process
488
  begin
489
    res_n_s <= '0';
490
    wait for 5 * period_c;
491
    res_n_s <= '1';
492
    wait;
493
  end process res_gen;
494
  --
495
  -----------------------------------------------------------------------------
496
 
497
 
498
  -----------------------------------------------------------------------------
499
  -- The interrupt generator
500
  --
501
  int_gen: process
502
  begin
503
    int_n_s <= '1';
504
    wait for 750 * period_c;
505
    int_n_s <= '0';
506
    wait for  45 * period_c;
507
  end process int_gen;
508
  --
509
  -----------------------------------------------------------------------------
510
 
511
 
512
  -----------------------------------------------------------------------------
513
  -- End of simulation detection
514
  --
515
  eos: process
516
  begin
517
 
518
    outer: loop
519
      wait on tb_accu_s;
520
      if tb_accu_s = "10101010" then
521
        wait on tb_accu_s;
522
        if tb_accu_s = "01010101" then
523
          wait on tb_accu_s;
524
          if tb_accu_s = "00000001" then
525 56 arniml
            -- wait for instruction strobe of this move
526
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
527
            -- wait for next strobe
528
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
529 8 arniml
            assert false
530 19 arniml
              report "Simulation Result: PASS."
531 8 arniml
              severity note;
532
          else
533
            assert false
534 19 arniml
              report "Simulation Result: FAIL."
535 8 arniml
              severity note;
536
          end if;
537
 
538
          assert false
539
            report "End of simulation reached."
540
            severity failure;
541
 
542
        end if;
543
      end if;
544
    end loop;
545
 
546
  end process eos;
547
  --
548
  -----------------------------------------------------------------------------
549
 
550
end behav;
551
 
552
 
553
-------------------------------------------------------------------------------
554
-- File History:
555
--
556
-- $Log: not supported by cvs2svn $
557 111 arniml
-- Revision 1.9  2004/05/17 14:43:33  arniml
558
-- add testbench peripherals for P1 and P2
559
-- this became necessary to observe a difference between externally applied
560
-- port data and internally applied port data
561
--
562 103 arniml
-- Revision 1.8  2004/04/25 20:41:48  arniml
563
-- connect if_timing to P2 output of T48
564
--
565 83 arniml
-- Revision 1.7  2004/04/25 16:23:21  arniml
566
-- added if_timing
567
--
568 80 arniml
-- Revision 1.6  2004/04/14 20:57:44  arniml
569
-- wait for instruction strobe after final end-of-simulation detection
570
-- this ensures that the last mov instruction is part of the dump and
571
-- enables 100% matching with i8039 simulator
572
--
573 56 arniml
-- Revision 1.5  2004/03/29 19:45:15  arniml
574
-- rename pX_limp to pX_low_imp
575
--
576 33 arniml
-- Revision 1.4  2004/03/28 21:30:25  arniml
577
-- connect prog_n_o
578
--
579 30 arniml
-- Revision 1.3  2004/03/26 22:39:28  arniml
580
-- enhance simulation result string
581
--
582 19 arniml
-- Revision 1.2  2004/03/24 23:22:35  arniml
583
-- put ext_ram on falling clock edge to sample the write enable properly
584
--
585 10 arniml
-- Revision 1.1  2004/03/24 21:42:10  arniml
586
-- initial check-in
587
--
588 8 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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