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

Subversion Repositories tinycpu

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

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 37 earlz
      Port0: inout std_logic_vector(7 downto 0);
23 23 earlz
      --debug ports
24
      DebugR0: out std_logic_vector(7 downto 0)
25
    );
26
  end component;
27
 
28
 
29
  signal Reset:std_logic:='0';
30
  signal Hold: std_logic:='0';
31
  signal HoldAck: std_logic;
32
  signal DMA: std_logic:='0'; --when high, Address, WriteEnable, and Data are connected to memory
33
  signal Address: std_logic_vector(15 downto 0):=x"0000"; --memory address (in bytes)
34
  signal WriteEnable: std_logic:='0';
35
  signal Data: std_logic_vector(15 downto 0):=x"0000";
36 37 earlz
  signal Port0: std_logic_vector(7 downto 0);
37 23 earlz
  --debug ports
38
  signal DebugR0: std_logic_vector(7 downto 0);
39
 
40
  signal Clock: std_logic;
41
  constant clock_period : time := 10 ns;
42
 
43
BEGIN
44
 
45
  -- Instantiate the Unit Under Test (UUT)
46
  uut: top PORT MAP (
47
    Reset => Reset,
48
    Hold => Hold,
49
    HoldAck => HoldAck,
50
    Clock => Clock,
51
    DMA => DMA,
52
    Address => Address,
53
    WriteEnable => WriteEnable,
54
    Data => Data,
55 37 earlz
    DebugR0 => DebugR0,
56
    Port0 => Port0
57 23 earlz
  );
58
 
59
  -- Clock process definitions
60
  clock_process :process
61
  begin
62
    Clock <= '0';
63
    wait for clock_period/2;
64
    Clock <= '1';
65
    wait for clock_period/2;
66
  end process;
67
 
68
 
69
  -- Stimulus process
70
  stim_proc: process
71
    variable err_cnt: integer :=0;
72
  begin
73 41 earlz
    Port0 <= "ZZZZZZZZ";
74 23 earlz
    -- hold reset state for 100 ns.
75 39 earlz
    Reset <= '0';
76
    wait for 10 ns;
77 23 earlz
    Reset <= '1';
78 39 earlz
    wait for 200 ns;
79 40 earlz
    Reset <= '0';
80
    wait for 50 ns;
81
    Port0(1) <= '1';
82 41 earlz
    wait for 200 ns;
83 40 earlz
    assert(Port0(0)='1') report "Toggle app not working" severity error;
84
    wait for 10 ns;
85 41 earlz
    Port0(1) <= '0';
86
    wait for 200 ns;
87 40 earlz
    assert(Port0(0)='0') report "Toggle app not working 2" severity error;
88
 
89
 
90
 
91
 
92
 
93
 
94
 
95
    Reset <= '1';
96
    wait for 100 ns;
97
    wait for 10 ns;
98 23 earlz
    Hold <= '1';
99
    wait for 10 ns;
100
    assert (HoldAck ='1') report "HoldAck not becoming high" severity error;
101
    --load memory image
102
    DMA <= '1';
103
    WriteEnable <= '1';
104
    Address <= x"0100";
105
    Data <= x"0057";
106
    wait for 10 ns;
107
    Address <= x"0102";
108
    Data <= x"00F1";
109
    wait for 10 ns;
110
    Address <= x"0104";
111
    Data <= x"00FF";
112
    wait for 10 ns;
113
    Address <= x"0106";
114
    Data <= x"0063";
115
    wait for 10 ns;
116 25 earlz
    --Address <= x"0108";
117
    --wait for 10 ns;
118 23 earlz
    DMA <= '0';
119
    wait for 10 ns;
120
    Hold <= '0';
121
    wait for 10 ns;
122
 
123
    --start the processor
124
    Reset <= '0';
125
    wait for 30 ns; --wait 3 clock cycles for CPU to execute first instruction
126 28 earlz
    wait for 10 ns; --wait 1 clock cycle for first instruction decode
127 23 earlz
    assert(Debugr0 = x"57") report "R0 is not loaded properly for first instruction" severity error;
128
    wait for 10 ns;
129
    assert(DebugR0 = x"F1") report "R0 is not loaded properly for second instruction" severity error;
130
 
131
 
132
 
133
 
134
 
135
 
136
   assert false
137
   report "Testbench of top completed successfully!"
138
   severity note;
139
 
140
    wait;
141
 
142
    -- insert stimulus here 
143
 
144
    wait;
145
  end process;
146
 
147
 
148
END;

powered by: WebSVN 2.1.0

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