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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_1_beta/] [bench/] [vhdl/] [tb.vhd] - Blame information for rev 304

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 83 arniml
-- $Id: tb.vhd,v 1.8 2004-04-25 20:41: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 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
  signal ext_ram_addr_s      : std_logic_vector( 7 downto 0);
103
  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
  signal zero_s          : std_logic;
109
  signal one_s           : std_logic;
110
  signal zero_byte_s     : std_logic_vector( 7 downto 0);
111
 
112
begin
113
 
114
  zero_s      <= '0';
115
  one_s       <= '1';
116
  zero_byte_s <= (others => '0');
117
 
118
  rom_4k : syn_rom
119
    generic map (
120
      address_width_g => 12
121
    )
122
    port map (
123
      clk_i      => xtal_s,
124
      rom_addr_i => rom_addr_s,
125
      rom_data_o => rom_data_s
126
    );
127
 
128
  ram_256 : syn_ram
129
    generic map (
130
      address_width_g => 8
131
    )
132
    port map (
133
      clk_i      => xtal_s,
134
      res_i      => res_n_s,
135
      ram_addr_i => ram_addr_s,
136
      ram_data_i => ram_data_to_s,
137
      ram_we_i   => ram_we_s,
138
      ram_data_o => ram_data_from_s
139
    );
140
 
141
  ext_ram_b : syn_ram
142
    generic map (
143
      address_width_g => 8
144
    )
145
    port map (
146
      clk_i      => xtal_s,
147
      res_i      => res_n_s,
148
      ram_addr_i => ext_ram_addr_s,
149
      ram_data_i => bus_s,
150
      ram_we_i   => ext_ram_we_s,
151
      ram_data_o => ext_ram_data_from_s
152
    );
153
 
154
  t48_core_b : t48_core
155
    generic map (
156
      xtal_div_3_g        => 1,
157
      register_mnemonic_g => 1,
158
      include_port1_g     => 1,
159
      include_port2_g     => 1,
160
      include_bus_g       => 1,
161
      include_timer_g     => 1,
162
      sample_t1_state_g   => 4
163
    )
164
    port map (
165 33 arniml
      xtal_i       => xtal_s,
166
      reset_i      => res_n_s,
167
      t0_i         => p1_s(0),
168
      t0_o         => open,
169
      t0_dir_o     => open,
170
      int_n_i      => int_n_s,
171
      ea_i         => zero_s,
172
      rd_n_o       => rd_n_s,
173 80 arniml
      psen_n_o     => psen_n_s,
174 33 arniml
      wr_n_o       => wr_n_s,
175
      ale_o        => ale_s,
176
      db_i         => bus_s,
177
      db_o         => t48_bus_s,
178
      db_dir_o     => bus_dir_s,
179
      t1_i         => p1_s(1),
180
      p2_i         => p2_s,
181
      p2_o         => t48_p2_s,
182
      p2_low_imp_o => p2_low_imp_s,
183
      p1_i         => p1_s,
184
      p1_o         => t48_p1_s,
185
      p1_low_imp_o => p1_low_imp_s,
186
      prog_n_o     => prog_n_s,
187
      clk_i        => xtal_s,
188
      en_clk_i     => xtal3_s,
189
      xtal3_o      => xtal3_s,
190
      dmem_addr_o  => ram_addr_s,
191
      dmem_we_o    => ram_we_s,
192
      dmem_data_i  => ram_data_from_s,
193
      dmem_data_o  => ram_data_to_s,
194
      pmem_addr_o  => rom_addr_s,
195
      pmem_data_i  => rom_data_s
196 8 arniml
    );
197
 
198 80 arniml
  if_timing_b : if_timing
199
    port map (
200
      xtal_i   => xtal_s,
201
      ale_i    => ale_s,
202
      psen_n_i => psen_n_s,
203
      rd_n_i   => rd_n_s,
204
      wr_n_i   => wr_n_s,
205
      prog_n_i => prog_n_s,
206
      db_bus_i => bus_s,
207 83 arniml
      p2_i     => t48_p2_s
208 80 arniml
    );
209 8 arniml
 
210 80 arniml
 
211 8 arniml
  -----------------------------------------------------------------------------
212
  -- Port logic
213
  --
214
  ports: process (t48_p1_s,
215 33 arniml
                  p1_low_imp_s,
216 8 arniml
                  t48_p2_s,
217 33 arniml
                  p2_low_imp_s)
218
    function t48_port_f(t48_p   : std_logic_vector(7 downto 0);
219
                        low_imp : std_logic) return std_logic_vector is
220 8 arniml
      variable p_v : std_logic_vector(7 downto 0);
221
    begin
222 33 arniml
      if low_imp = '1' then
223 8 arniml
        p_v := t48_p;
224
 
225
      else
226
        for i in p_v'range loop
227
          if t48_p(i) = '1' then
228
            p_v(i) := 'H';
229
          else
230
            p_v(i) := t48_p(i);
231
          end if;
232
        end loop;
233
 
234
      end if;
235
 
236
      return p_v;
237
    end;
238
 
239
  begin
240
 
241 33 arniml
    p1_s <= t48_port_f(t48_p   => t48_p1_s,
242
                       low_imp => p1_low_imp_s);
243 8 arniml
 
244 33 arniml
    p2_s <= t48_port_f(t48_p   => t48_p2_s,
245
                       low_imp => p2_low_imp_s);
246 8 arniml
 
247
  end process ports;
248
  --
249
  -----------------------------------------------------------------------------
250
 
251
  bus_s <=   t48_bus_s
252
           when bus_dir_s = '1' else
253
             (others => 'Z');
254
 
255
  bus_s <=   ext_ram_data_from_s
256
           when rd_n_s = '0' else
257
             (others => 'Z');
258
 
259
 
260
  -----------------------------------------------------------------------------
261
  -- External RAM access signals
262
  --
263
  ext_ram: process (wr_n_s,
264
                    ext_ram_addr_s,
265
                    ale_s,
266
                    bus_s,
267
                    xtal_s)
268
  begin
269
    if ale_s'event and ale_s = '0' then
270
      if not is_X(bus_s) then
271
        ext_ram_addr_s <= bus_s;
272
      else
273
        ext_ram_addr_s <= (others => '0');
274
      end if;
275
    end if;
276
 
277
    if wr_n_s'event and wr_n_s = '1' then
278
      ext_ram_we_s <= '1';
279
    end if;
280
 
281 10 arniml
    if xtal_s'event and xtal_s = '1' then
282 8 arniml
      ext_ram_we_s <= '0';
283
    end if;
284
 
285
  end process ext_ram;
286
  --
287
  -----------------------------------------------------------------------------
288
 
289 10 arniml
  xtal_n_s <= not xtal_s;
290
 
291 8 arniml
  -----------------------------------------------------------------------------
292
  -- The clock generator
293
  --
294
  clk_gen: process
295
  begin
296
    xtal_s <= '0';
297
    wait for period_c/2;
298
    xtal_s <= '1';
299
    wait for period_c/2;
300
  end process clk_gen;
301
  --
302
  -----------------------------------------------------------------------------
303
 
304
 
305
  -----------------------------------------------------------------------------
306
  -- The reset generator
307
  --
308
  res_gen: process
309
  begin
310
    res_n_s <= '0';
311
    wait for 5 * period_c;
312
    res_n_s <= '1';
313
    wait;
314
  end process res_gen;
315
  --
316
  -----------------------------------------------------------------------------
317
 
318
 
319
  -----------------------------------------------------------------------------
320
  -- The interrupt generator
321
  --
322
  int_gen: process
323
  begin
324
    int_n_s <= '1';
325
    wait for 750 * period_c;
326
    int_n_s <= '0';
327
    wait for  45 * period_c;
328
  end process int_gen;
329
  --
330
  -----------------------------------------------------------------------------
331
 
332
 
333
  -----------------------------------------------------------------------------
334
  -- End of simulation detection
335
  --
336
  eos: process
337
  begin
338
 
339
    outer: loop
340
      wait on tb_accu_s;
341
      if tb_accu_s = "10101010" then
342
        wait on tb_accu_s;
343
        if tb_accu_s = "01010101" then
344
          wait on tb_accu_s;
345
          if tb_accu_s = "00000001" then
346 56 arniml
            -- wait for instruction strobe of this move
347
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
348
            -- wait for next strobe
349
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
350 8 arniml
            assert false
351 19 arniml
              report "Simulation Result: PASS."
352 8 arniml
              severity note;
353
          else
354
            assert false
355 19 arniml
              report "Simulation Result: FAIL."
356 8 arniml
              severity note;
357
          end if;
358
 
359
          assert false
360
            report "End of simulation reached."
361
            severity failure;
362
 
363
        end if;
364
      end if;
365
    end loop;
366
 
367
  end process eos;
368
  --
369
  -----------------------------------------------------------------------------
370
 
371
end behav;
372
 
373
 
374
-------------------------------------------------------------------------------
375
-- File History:
376
--
377
-- $Log: not supported by cvs2svn $
378 83 arniml
-- Revision 1.7  2004/04/25 16:23:21  arniml
379
-- added if_timing
380
--
381 80 arniml
-- Revision 1.6  2004/04/14 20:57:44  arniml
382
-- wait for instruction strobe after final end-of-simulation detection
383
-- this ensures that the last mov instruction is part of the dump and
384
-- enables 100% matching with i8039 simulator
385
--
386 56 arniml
-- Revision 1.5  2004/03/29 19:45:15  arniml
387
-- rename pX_limp to pX_low_imp
388
--
389 33 arniml
-- Revision 1.4  2004/03/28 21:30:25  arniml
390
-- connect prog_n_o
391
--
392 30 arniml
-- Revision 1.3  2004/03/26 22:39:28  arniml
393
-- enhance simulation result string
394
--
395 19 arniml
-- Revision 1.2  2004/03/24 23:22:35  arniml
396
-- put ext_ram on falling clock edge to sample the write enable properly
397
--
398 10 arniml
-- Revision 1.1  2004/03/24 21:42:10  arniml
399
-- initial check-in
400
--
401 8 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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