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

Subversion Repositories tinycpu

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

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 23 earlz
    Hold <= '1';
79
    wait for 10 ns;
80
    assert (HoldAck ='1') report "HoldAck not becoming high" severity error;
81
    --load memory image
82
    DMA <= '1';
83
    WriteEnable <= '1';
84
    Address <= x"0100";
85
    Data <= x"0057";
86
    wait for 10 ns;
87
    Address <= x"0102";
88
    Data <= x"00F1";
89
    wait for 10 ns;
90
    Address <= x"0104";
91
    Data <= x"00FF";
92
    wait for 10 ns;
93
    Address <= x"0106";
94
    Data <= x"0063";
95
    wait for 10 ns;
96 25 earlz
    --Address <= x"0108";
97
    --wait for 10 ns;
98 23 earlz
    DMA <= '0';
99
    wait for 10 ns;
100
    Hold <= '0';
101
    wait for 10 ns;
102
 
103
    --start the processor
104
    Reset <= '0';
105
    wait for 30 ns; --wait 3 clock cycles for CPU to execute first instruction
106 28 earlz
    wait for 10 ns; --wait 1 clock cycle for first instruction decode
107 23 earlz
    assert(Debugr0 = x"57") report "R0 is not loaded properly for first instruction" severity error;
108
    wait for 10 ns;
109
    assert(DebugR0 = x"F1") report "R0 is not loaded properly for second instruction" severity error;
110
 
111
 
112
 
113
 
114
 
115
 
116
   assert false
117
   report "Testbench of top completed successfully!"
118
   severity note;
119
 
120
    wait;
121
 
122
    -- insert stimulus here 
123
 
124
    wait;
125
  end process;
126
 
127
 
128
END;

powered by: WebSVN 2.1.0

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