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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_4_beta/] [bench/] [vhdl/] [tb.vhd] - Blame information for rev 103

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

powered by: WebSVN 2.1.0

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