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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_0/] [bench/] [vhdl/] [tb_t8243.vhd] - Blame information for rev 292

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 248 arniml
-------------------------------------------------------------------------------
2
--
3
-- The testbench for t8243 core.
4
--
5
-- $Id: tb_t8243.vhd,v 1.1 2006-07-14 01:02:47 arniml Exp $
6
--
7
-- Copyright (c) 2006, 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_t8243 is
50
 
51
end tb_t8243;
52
 
53
 
54
use work.t48_core_comp_pack.all;
55
use work.t8243_comp_pack.t8243_sync_notri;
56
 
57
use work.t48_tb_pack.all;
58
 
59
architecture behav of tb_t8243 is
60
 
61
  -- clock period, 11 MHz
62
  constant period_c : time := 90 ns;
63
 
64
  component if_timing
65
    port(
66
      xtal_i   : in std_logic;
67
      ale_i    : in std_logic;
68
      psen_n_i : in std_logic;
69
      rd_n_i   : in std_logic;
70
      wr_n_i   : in std_logic;
71
      prog_n_i : in std_logic;
72
      db_bus_i : in std_logic_vector(7 downto 0);
73
      p2_i     : in std_logic_vector(7 downto 0)
74
    );
75
  end component;
76
 
77
  component lpm_rom
78
    generic (
79
      LPM_WIDTH           : positive;
80
      LPM_TYPE            : string    := "LPM_ROM";
81
      LPM_WIDTHAD         : positive;
82
      LPM_NUMWORDS        : natural   := 0;
83
      LPM_FILE            : string;
84
      LPM_ADDRESS_CONTROL : string    := "REGISTERED";
85
      LPM_OUTDATA         : string    := "REGISTERED";
86
      LPM_HINT            : string    := "UNUSED"
87
    );
88
    port (
89
      address             : in  std_logic_vector(LPM_WIDTHAD-1 downto 0);
90
      inclock             : in  std_logic;
91
      outclock            : in  std_logic;
92
      memenab             : in  std_logic;
93
      q                   : out std_logic_vector(LPM_WIDTH-1 downto 0)
94
    );
95
  end component;
96
 
97
  signal xtal_s          : std_logic;
98
  signal xtal_n_s        : std_logic;
99
  signal res_n_s         : std_logic;
100
  signal xtal3_s         : std_logic;
101
  signal int_n_s         : std_logic;
102
  signal ale_s           : std_logic;
103
  signal rom_addr_s      : std_logic_vector(11 downto 0);
104
  signal rom_data_s      : std_logic_vector( 7 downto 0);
105
  signal ram_data_to_s   : std_logic_vector( 7 downto 0);
106
  signal ram_data_from_s : std_logic_vector( 7 downto 0);
107
  signal ram_addr_s      : std_logic_vector( 7 downto 0);
108
  signal ram_we_s        : std_logic;
109
 
110
  signal p1_s            : std_logic_vector( 7 downto 0);
111
  signal t48_p1_s        : std_logic_vector( 7 downto 0);
112
  signal p1_low_imp_s    : std_logic;
113
  signal p2_s            : std_logic_vector( 7 downto 0);
114
  signal t48_p2_s        : std_logic_vector( 7 downto 0);
115
  signal p2l_low_imp_s   : std_logic;
116
  signal p2h_low_imp_s   : std_logic;
117
  signal psen_n_s        : std_logic;
118
  signal prog_n_s        : std_logic;
119
 
120
  signal bus_s           : std_logic_vector( 7 downto 0);
121
  signal t48_bus_s       : std_logic_vector( 7 downto 0);
122
  signal bus_dir_s       : std_logic;
123
 
124
  signal ext_mem_addr_q      : std_logic_vector( 7 downto 0);
125
  signal ext_ram_data_from_s : std_logic_vector( 7 downto 0);
126
  signal ext_ram_we_q        : std_logic;
127
  signal rd_n_s              : std_logic;
128
  signal wr_n_s              : std_logic;
129
 
130
  signal ext_rom_data_s  : std_logic_vector( 7 downto 0);
131
  signal ext_rom_addr_s  : std_logic_vector(11 downto 0);
132
 
133
  signal tb_p1_q : std_logic_vector( 7 downto 0);
134
  signal tb_p2_q : std_logic_vector( 7 downto 0);
135
 
136
  signal ext_mem_sel_we_q : boolean;
137
  signal ena_ext_ram_q    : boolean;
138
  signal ena_tb_periph_q  : boolean;
139
 
140
  signal t8243_p2_s       : std_logic_vector(3 downto 0);
141
  signal t8243_p2_en_s    : std_logic;
142
  signal p4_s,
143
         p5_s,
144
         p6_s,
145
         p7_s             : std_logic_vector(3 downto 0);
146
  signal p4_p6_s,
147
         p5_p7_s          : std_logic_vector(3 downto 0);
148
  signal p4_en_s,
149
         p5_en_s,
150
         p6_en_s,
151
         p7_en_s         : std_logic;
152
 
153
  signal zero_s          : std_logic;
154
  signal one_s           : std_logic;
155
  signal zero_byte_s     : std_logic_vector( 7 downto 0);
156
 
157
begin
158
 
159
  zero_s      <= '0';
160
  one_s       <= '1';
161
  zero_byte_s <= (others => '0');
162
 
163
  -----------------------------------------------------------------------------
164
  -- Internal ROM, 2k bytes
165
  -- Initialized by file rom_t49.hex.
166
  -----------------------------------------------------------------------------
167
  rom_internal_2k : lpm_rom
168
    generic map (
169
      LPM_WIDTH           => 8,
170
      LPM_TYPE            => "LPM_ROM",
171
      LPM_WIDTHAD         => 11,
172
      LPM_NUMWORDS        => 2 ** 11,
173
      LPM_FILE            => "rom_t49.hex",
174
      LPM_ADDRESS_CONTROL => "REGISTERED",
175
      LPM_OUTDATA         => "UNREGISTERED",
176
      LPM_HINT            => "UNUSED"
177
    )
178
    port map (
179
      address  => rom_addr_s(10 downto 0),
180
      inclock  => xtal_s,
181
      outclock => zero_s,               -- unused
182
      memenab  => one_s,
183
      q        => rom_data_s
184
    );
185
 
186
  -----------------------------------------------------------------------------
187
  -- External ROM, 2k bytes
188
  -- Initialized by file rom_t49_ext.hex.
189
  -----------------------------------------------------------------------------
190
  ext_rom_addr_s(11 downto 8) <= t48_p2_s(3 downto 0);
191
  ext_rom_addr_s( 7 downto 0) <= ext_mem_addr_q;
192
  rom_external_2k : lpm_rom
193
    generic map (
194
      LPM_WIDTH           => 8,
195
      LPM_TYPE            => "LPM_ROM",
196
      LPM_WIDTHAD         => 11,
197
      LPM_NUMWORDS        => 2 ** 11,
198
      LPM_FILE            => "rom_t49_ext.hex",
199
      LPM_ADDRESS_CONTROL => "REGISTERED",
200
      LPM_OUTDATA         => "UNREGISTERED",
201
      LPM_HINT            => "UNUSED"
202
    )
203
    port map (
204
      address  => ext_rom_addr_s(10 downto 0),
205
      inclock  => xtal_s,
206
      outclock => zero_s,               -- unused
207
      memenab  => one_s,
208
      q        => ext_rom_data_s
209
    );
210
 
211
  -----------------------------------------------------------------------------
212
  -- Internal RAM, 256 bytes
213
  -----------------------------------------------------------------------------
214
  ram_256 : generic_ram_ena
215
    generic map (
216
      addr_width_g => 8,
217
      data_width_g => 8
218
    )
219
    port map (
220
      clk_i => xtal_s,
221
      a_i   => ram_addr_s,
222
      we_i  => ram_we_s,
223
      ena_i => one_s,
224
      d_i   => ram_data_to_s,
225
      d_o   => ram_data_from_s
226
    );
227
 
228
  -----------------------------------------------------------------------------
229
  -- External RAM, 256 bytes
230
  -----------------------------------------------------------------------------
231
  ext_ram_b : generic_ram_ena
232
    generic map (
233
      addr_width_g => 8,
234
      data_width_g => 8
235
    )
236
    port map (
237
      clk_i => xtal_s,
238
      a_i   => ext_mem_addr_q,
239
      we_i  => ext_ram_we_q,
240
      ena_i => one_s,
241
      d_i   => bus_s,
242
      d_o   => ext_ram_data_from_s
243
    );
244
 
245
  t48_core_b : t48_core
246
    generic map (
247
      xtal_div_3_g        => 1,
248
      register_mnemonic_g => 1,
249
      include_port1_g     => 1,
250
      include_port2_g     => 1,
251
      include_bus_g       => 1,
252
      include_timer_g     => 1,
253
      sample_t1_state_g   => 4
254
    )
255
    port map (
256
      xtal_i        => xtal_s,
257
      xtal_en_i     => one_s,
258
      reset_i       => res_n_s,
259
      t0_i          => p1_s(0),
260
      t0_o          => open,
261
      t0_dir_o      => open,
262
      int_n_i       => int_n_s,
263
      ea_i          => rom_addr_s(11),
264
      rd_n_o        => rd_n_s,
265
      psen_n_o      => psen_n_s,
266
      wr_n_o        => wr_n_s,
267
      ale_o         => ale_s,
268
      db_i          => bus_s,
269
      db_o          => t48_bus_s,
270
      db_dir_o      => bus_dir_s,
271
      t1_i          => p1_s(1),
272
      p2_i          => p2_s,
273
      p2_o          => t48_p2_s,
274
      p2l_low_imp_o => p2l_low_imp_s,
275
      p2h_low_imp_o => p2h_low_imp_s,
276
      p1_i          => p1_s,
277
      p1_o          => t48_p1_s,
278
      p1_low_imp_o  => p1_low_imp_s,
279
      prog_n_o      => prog_n_s,
280
      clk_i         => xtal_s,
281
      en_clk_i      => xtal3_s,
282
      xtal3_o       => xtal3_s,
283
      dmem_addr_o   => ram_addr_s,
284
      dmem_we_o     => ram_we_s,
285
      dmem_data_i   => ram_data_from_s,
286
      dmem_data_o   => ram_data_to_s,
287
      pmem_addr_o   => rom_addr_s,
288
      pmem_data_i   => rom_data_s
289
    );
290
 
291
  if_timing_b : if_timing
292
    port map (
293
      xtal_i   => xtal_s,
294
      ale_i    => ale_s,
295
      psen_n_i => psen_n_s,
296
      rd_n_i   => rd_n_s,
297
      wr_n_i   => wr_n_s,
298
      prog_n_i => prog_n_s,
299
      db_bus_i => bus_s,
300
      p2_i     => t48_p2_s
301
    );
302
 
303
 
304
  t8243_sync_notri_b : t8243_sync_notri
305
    port map (
306
      clk_i     => xtal_s,
307
      clk_en_i  => one_s,
308
      reset_n_i => one_s,
309
      cs_n_i    => zero_s,
310
      prog_n_i  => prog_n_s,
311
      p2_i      => t48_p2_s(3 downto 0),
312
      p2_o      => t8243_p2_s,
313
      p2_en_o   => t8243_p2_en_s,
314
      p4_i      => p4_p6_s,
315
      p4_o      => p4_s,
316
      p4_en_o   => p4_en_s,
317
      p5_i      => p5_p7_s,
318
      p5_o      => p5_s,
319
      p5_en_o   => p5_en_s,
320
      p6_i      => p4_p6_s,
321
      p6_o      => p6_s,
322
      p6_en_o   => p6_en_s,
323
      p7_i      => p5_p7_s,
324
      p7_o      => p7_s,
325
      p7_en_o   => p7_en_s
326
    );
327
  p4_p6_s <=   p4_s
328
             when p4_en_s = '1' else
329
               (others => 'Z');
330
  p5_p7_s <=   p5_s
331
             when p5_en_s = '1' else
332
               (others => 'Z');
333
  p4_p6_s <=   p6_s
334
             when p6_en_s = '1' else
335
               (others => 'Z');
336
  p5_p7_s <=   p7_s
337
             when p7_en_s = '1' else
338
               (others => 'Z');
339
 
340
 
341
 
342
  -----------------------------------------------------------------------------
343
  -- Port logic
344
  --
345
  ports: process (t48_p1_s,
346
                  p1_low_imp_s,
347
                  t48_p2_s,
348
                  p2l_low_imp_s,
349
                  p2h_low_imp_s)
350
    function t48_port_f(t48_p   : std_logic_vector;
351
                        low_imp : std_logic) return std_logic_vector is
352
      variable p_v : std_logic_vector(t48_p'range);
353
    begin
354
      if low_imp = '1' then
355
        p_v := t48_p;
356
 
357
      else
358
        for i in p_v'range loop
359
          if t48_p(i) = '1' then
360
            p_v(i) := 'H';
361
          else
362
            p_v(i) := t48_p(i);
363
          end if;
364
        end loop;
365
 
366
      end if;
367
 
368
      return p_v;
369
    end;
370
 
371
  begin
372
 
373
    p1_s <= t48_port_f(t48_p   => t48_p1_s,
374
                       low_imp => p1_low_imp_s);
375
 
376
    p2_s(3 downto 0) <= t48_port_f(t48_p   => t48_p2_s(3 downto 0),
377
                                   low_imp => p2l_low_imp_s);
378
    p2_s(7 downto 4) <= t48_port_f(t48_p   => t48_p2_s(7 downto 4),
379
                                   low_imp => p2h_low_imp_s);
380
 
381
  end process ports;
382
  --
383
  -----------------------------------------------------------------------------
384
 
385
  t8243_p2: process (t8243_p2_s,
386
                     t8243_p2_en_s)
387
  begin
388
    p2_s <= (others => 'Z');
389
 
390
    if t8243_p2_en_s = '1' then
391
      p2_s(3 downto 0) <= t8243_p2_s;
392
    end if;
393
  end process t8243_p2;
394
 
395
 
396
  bus_s <=   t48_bus_s
397
           when bus_dir_s = '1' else
398
             (others => 'Z');
399
 
400
  bus_s <=   ext_ram_data_from_s
401
           when rd_n_s = '0' and ena_ext_ram_q else
402
             (others => 'Z');
403
 
404
  bus_s <=   ext_rom_data_s
405
           when psen_n_s = '0' else
406
             (others => 'Z');
407
 
408
 
409
  -----------------------------------------------------------------------------
410
  -- External memory access signals
411
  --
412
  ext_mem: process (wr_n_s,
413
                    ext_mem_addr_q,
414
                    ena_ext_ram_q,
415
                    ale_s,
416
                    bus_s,
417
                    xtal_s)
418
  begin
419
    if ale_s'event and ale_s = '0' then
420
      if not is_X(bus_s) then
421
        ext_mem_addr_q <= bus_s;
422
      else
423
        ext_mem_addr_q <= (others => '0');
424
      end if;
425
    end if;
426
 
427
    if wr_n_s'event and wr_n_s = '1' then
428
      -- write enable for external RAM
429
      if ena_ext_ram_q then
430
        ext_ram_we_q <= '1';
431
      end if;
432
 
433
      -- process external memory selector
434
      if ext_mem_addr_q = "11111111" then
435
        ext_mem_sel_we_q <= true;
436
      end if;
437
 
438
    end if;
439
 
440
    if xtal_s'event and xtal_s = '1' then
441
      ext_ram_we_q     <= '0';
442
      ext_mem_sel_we_q <= false;
443
    end if;
444
 
445
  end process ext_mem;
446
  --
447
  -----------------------------------------------------------------------------
448
 
449
 
450
  -----------------------------------------------------------------------------
451
  -- Process ext_mem_sel
452
  --
453
  -- Purpose:
454
  --   Select external memory address space.
455
  --   This is either
456
  --     + external RAM
457
  --     + testbench peripherals
458
  --
459
  ext_mem_sel: process (res_n_s, xtal_s)
460
  begin
461
    if res_n_s = '0' then
462
      ena_ext_ram_q       <= true;
463
      ena_tb_periph_q     <= false;
464
 
465
    elsif xtal_s'event and xtal_s = '1' then
466
      if ext_mem_sel_we_q then
467
        if bus_s(0) = '1' then
468
          ena_ext_ram_q   <= true;
469
        else
470
          ena_ext_ram_q   <= false;
471
        end if;
472
 
473
        if bus_s(1) = '1' then
474
          ena_tb_periph_q <= true;
475
        else
476
          ena_tb_periph_q <= false;
477
        end if;
478
      end if;
479
 
480
    end if;
481
 
482
  end process ext_mem_sel;
483
  --
484
  -----------------------------------------------------------------------------
485
 
486
 
487
  -----------------------------------------------------------------------------
488
  -- Process tb_periph
489
  --
490
  -- Purpose:
491
  --   Implements the testbenc peripherals driving P1 and P2.
492
  --
493
  tb_periph: process (res_n_s, wr_n_s)
494
 
495
    function oc_f (pX : std_logic_vector) return std_logic_vector is
496
      variable r_v : std_logic_vector(pX'range);
497
    begin
498
      for i in pX'range loop
499
        if pX(i) = '0' then
500
          r_v(i) := '0';
501
        else
502
          r_v(i) := 'H';
503
        end if;
504
      end loop;
505
 
506
      return r_v;
507
    end;
508
 
509
  begin
510
    if res_n_s = '0' then
511
      tb_p1_q <= (others => 'H');
512
      tb_p2_q <= (others => 'H');
513
 
514
    elsif wr_n_s'event and wr_n_s = '1' then
515
      if ena_tb_periph_q then
516
        case ext_mem_addr_q is
517
          -- P1
518
          when "00000000" =>
519
            tb_p1_q <= oc_f(t48_bus_s);
520
 
521
          -- P2
522
          when "00000001" =>
523
            tb_p2_q <= oc_f(t48_bus_s);
524
 
525
          when others =>
526
            null;
527
 
528
        end case;
529
 
530
      end if;
531
 
532
    end if;
533
 
534
  end process tb_periph;
535
  --
536
  -----------------------------------------------------------------------------
537
 
538
  p1_s <= tb_p1_q;
539
  p2_s <= tb_p2_q;
540
 
541
 
542
  xtal_n_s <= not xtal_s;
543
 
544
  -----------------------------------------------------------------------------
545
  -- The clock generator
546
  --
547
  clk_gen: process
548
  begin
549
    xtal_s <= '0';
550
    wait for period_c/2;
551
    xtal_s <= '1';
552
    wait for period_c/2;
553
  end process clk_gen;
554
  --
555
  -----------------------------------------------------------------------------
556
 
557
 
558
  -----------------------------------------------------------------------------
559
  -- The reset generator
560
  --
561
  res_gen: process
562
  begin
563
    res_n_s <= '0';
564
    wait for 5 * period_c;
565
    res_n_s <= '1';
566
    wait;
567
  end process res_gen;
568
  --
569
  -----------------------------------------------------------------------------
570
 
571
 
572
  -----------------------------------------------------------------------------
573
  -- The interrupt generator
574
  --
575
  int_gen: process
576
  begin
577
    int_n_s <= '1';
578
    wait for 750 * period_c;
579
    int_n_s <= '0';
580
    wait for  45 * period_c;
581
  end process int_gen;
582
  --
583
  -----------------------------------------------------------------------------
584
 
585
 
586
  -----------------------------------------------------------------------------
587
  -- End of simulation detection
588
  --
589
  eos: process
590
  begin
591
 
592
    outer: loop
593
      wait on tb_accu_s;
594
      if tb_accu_s = "10101010" then
595
        wait on tb_accu_s;
596
        if tb_accu_s = "01010101" then
597
          wait on tb_accu_s;
598
          if tb_accu_s = "00000001" then
599
            -- wait for instruction strobe of this move
600
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
601
            -- wait for next strobe
602
            wait until tb_istrobe_s'event and tb_istrobe_s = '1';
603
            assert false
604
              report "Simulation Result: PASS."
605
              severity note;
606
          else
607
            assert false
608
              report "Simulation Result: FAIL."
609
              severity note;
610
          end if;
611
 
612
          assert false
613
            report "End of simulation reached."
614
            severity failure;
615
 
616
        end if;
617
      end if;
618
    end loop;
619
 
620
  end process eos;
621
  --
622
  -----------------------------------------------------------------------------
623
 
624
end behav;
625
 
626
 
627
-------------------------------------------------------------------------------
628
-- File History:
629
--
630
-- $Log: not supported by cvs2svn $
631
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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