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

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [testbench/] [top_tb.vhd] - Blame information for rev 23

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

Line No. Rev Author Line
1 23 earlz
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
 
5
ENTITY top_tb IS
6
END top_tb;
7
 
8
ARCHITECTURE behavior OF top_tb IS
9
 
10
-- Component Declaration for the Unit Under Test (UUT)
11
 
12
  component top is
13
    port(
14
      Reset: in std_logic;
15
      Hold: in std_logic;
16
      HoldAck: out std_logic;
17
      Clock: in std_logic;
18
      DMA: in std_logic; --when high, Address, WriteEnable, and Data are connected to memory
19
      Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
20
      WriteEnable: in std_logic;
21
      Data: inout std_logic_vector(15 downto 0);
22
      --debug ports
23
      DebugR0: out std_logic_vector(7 downto 0)
24
    );
25
  end component;
26
 
27
 
28
  signal Reset:std_logic:='0';
29
  signal Hold: std_logic:='0';
30
  signal HoldAck: std_logic;
31
  signal DMA: std_logic:='0'; --when high, Address, WriteEnable, and Data are connected to memory
32
  signal Address: std_logic_vector(15 downto 0):=x"0000"; --memory address (in bytes)
33
  signal WriteEnable: std_logic:='0';
34
  signal Data: std_logic_vector(15 downto 0):=x"0000";
35
  --debug ports
36
  signal DebugR0: std_logic_vector(7 downto 0);
37
 
38
  signal Clock: std_logic;
39
  constant clock_period : time := 10 ns;
40
 
41
BEGIN
42
 
43
  -- Instantiate the Unit Under Test (UUT)
44
  uut: top PORT MAP (
45
    Reset => Reset,
46
    Hold => Hold,
47
    HoldAck => HoldAck,
48
    Clock => Clock,
49
    DMA => DMA,
50
    Address => Address,
51
    WriteEnable => WriteEnable,
52
    Data => Data,
53
    DebugR0 => DebugR0
54
  );
55
 
56
  -- Clock process definitions
57
  clock_process :process
58
  begin
59
    Clock <= '0';
60
    wait for clock_period/2;
61
    Clock <= '1';
62
    wait for clock_period/2;
63
  end process;
64
 
65
 
66
  -- Stimulus process
67
  stim_proc: process
68
    variable err_cnt: integer :=0;
69
  begin
70
    -- hold reset state for 100 ns.
71
    Reset <= '1';
72
    wait for 20 ns;
73
    Hold <= '1';
74
    wait for 10 ns;
75
    assert (HoldAck ='1') report "HoldAck not becoming high" severity error;
76
    --load memory image
77
    DMA <= '1';
78
    WriteEnable <= '1';
79
    Address <= x"0100";
80
    Data <= x"0057";
81
    wait for 10 ns;
82
    Address <= x"0102";
83
    Data <= x"00F1";
84
    wait for 10 ns;
85
    Address <= x"0104";
86
    Data <= x"00FF";
87
    wait for 10 ns;
88
    Address <= x"0106";
89
    Data <= x"0063";
90
    wait for 10 ns;
91
    DMA <= '0';
92
    wait for 10 ns;
93
    Hold <= '0';
94
    wait for 10 ns;
95
 
96
    --start the processor
97
    Reset <= '0';
98
    wait for 30 ns; --wait 3 clock cycles for CPU to execute first instruction
99
    wait for 20 ns; --wait 2 clock cycle for first instruction decode and register write to complete
100
    assert(Debugr0 = x"57") report "R0 is not loaded properly for first instruction" severity error;
101
    wait for 10 ns;
102
    assert(DebugR0 = x"F1") report "R0 is not loaded properly for second instruction" severity error;
103
 
104
 
105
 
106
 
107
 
108
 
109
   assert false
110
   report "Testbench of top completed successfully!"
111
   severity note;
112
 
113
    wait;
114
 
115
    -- insert stimulus here 
116
 
117
    wait;
118
  end process;
119
 
120
 
121
END;

powered by: WebSVN 2.1.0

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