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

Subversion Repositories tinycpu

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

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 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
    -- hold reset state for 100 ns.
74 39 earlz
    Reset <= '0';
75
    wait for 10 ns;
76 23 earlz
    Reset <= '1';
77 39 earlz
    wait for 200 ns;
78 40 earlz
    Reset <= '0';
79
    wait for 50 ns;
80
    Port0(1) <= '1';
81
    wait for 100 ns;
82
    assert(Port0(0)='1') report "Toggle app not working" severity error;
83
    wait for 10 ns;
84
    Port0(0) <= '0';
85
    wait for 100 ns;
86
    assert(Port0(0)='0') report "Toggle app not working 2" severity error;
87
 
88
 
89
 
90
 
91
 
92
 
93
 
94
    Reset <= '1';
95
    wait for 100 ns;
96
    wait for 10 ns;
97 23 earlz
    Hold <= '1';
98
    wait for 10 ns;
99
    assert (HoldAck ='1') report "HoldAck not becoming high" severity error;
100
    --load memory image
101
    DMA <= '1';
102
    WriteEnable <= '1';
103
    Address <= x"0100";
104
    Data <= x"0057";
105
    wait for 10 ns;
106
    Address <= x"0102";
107
    Data <= x"00F1";
108
    wait for 10 ns;
109
    Address <= x"0104";
110
    Data <= x"00FF";
111
    wait for 10 ns;
112
    Address <= x"0106";
113
    Data <= x"0063";
114
    wait for 10 ns;
115 25 earlz
    --Address <= x"0108";
116
    --wait for 10 ns;
117 23 earlz
    DMA <= '0';
118
    wait for 10 ns;
119
    Hold <= '0';
120
    wait for 10 ns;
121
 
122
    --start the processor
123
    Reset <= '0';
124
    wait for 30 ns; --wait 3 clock cycles for CPU to execute first instruction
125 28 earlz
    wait for 10 ns; --wait 1 clock cycle for first instruction decode
126 23 earlz
    assert(Debugr0 = x"57") report "R0 is not loaded properly for first instruction" severity error;
127
    wait for 10 ns;
128
    assert(DebugR0 = x"F1") report "R0 is not loaded properly for second instruction" severity error;
129
 
130
 
131
 
132
 
133
 
134
 
135
   assert false
136
   report "Testbench of top completed successfully!"
137
   severity note;
138
 
139
    wait;
140
 
141
    -- insert stimulus here 
142
 
143
    wait;
144
  end process;
145
 
146
 
147
END;

powered by: WebSVN 2.1.0

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