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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testRegisterFile.vhd] - Blame information for rev 15

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

Line No. Rev Author Line
1 14 leonardoar
--! @file
2
--! @brief Testbench for Alu
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5
LIBRARY ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9
 
10
--! Use CPU Definitions package
11
use work.pkgOpenCPU32.all;
12
 
13
ENTITY testRegisterFile IS
14
END testRegisterFile;
15
 
16
--! @brief testRegisterFile Testbench file
17
--! @details Test read/write on the registers, testing also the dual port reading feature...
18
ARCHITECTURE behavior OF testRegisterFile IS
19
 
20
        --! Component declaration to instantiate the testRegisterFile circuit
21
    COMPONENT RegisterFile
22
    generic (n : integer := nBits - 1);                                         --! Generic value (Used to easily change the size of the registers)
23
         Port ( clk : in  STD_LOGIC;                                                                    --! Clock signal
24
           writeEn : in  STD_LOGIC;                                                             --! Write enable
25
           writeAddr : in  generalRegisters;                                    --! Write Adress
26
           input : in  STD_LOGIC_VECTOR (n downto 0);            --! Input 
27
           Read_A_En : in  STD_LOGIC;                                                   --! Enable read A
28
           Read_A_Addr : in  generalRegisters;                          --! Read A adress
29
           Read_B_En : in  STD_LOGIC;                                                   --! Enable read A
30
           Read_B_Addr : in  generalRegisters;                          --! Read B adress
31
           A_Out : out  STD_LOGIC_VECTOR (n downto 0);   --! Output A
32
           B_Out : out  STD_LOGIC_VECTOR (n downto 0));  --! Output B
33
    END COMPONENT;
34
 
35
 
36
   --Inputs
37
   signal clk : std_logic := '0';                                                                                                                        --! Wire to connect Test signal to component
38
   signal writeEn : std_logic := '0';                                                                                                            --! Wire to connect Test signal to component
39
   signal writeAddr : generalRegisters := r0;                                                                                   --! Wire to connect Test signal to component
40
   signal input : std_logic_vector((nBits - 1) downto 0) := (others => '0');      --! Wire to connect Test signal to component
41
   signal Read_A_En : std_logic := '0';                                                                                                  --! Wire to connect Test signal to component
42
   signal Read_A_Addr : generalRegisters := r0;                                                                                 --! Wire to connect Test signal to component
43
   signal Read_B_En : std_logic := '0';                                                                                                  --! Wire to connect Test signal to component
44
   signal Read_B_Addr : generalRegisters := r0;                                                                                 --! Wire to connect Test signal to component
45
 
46
        --Outputs
47
   signal A_Out : std_logic_vector((nBits - 1) downto 0);                                                        --! Wire to connect Test signal to component
48
   signal B_Out : std_logic_vector((nBits - 1) downto 0);                                                --! Wire to connect Test signal to component
49
 
50
        constant num_cycles : integer := 320;                                                                                                   --! Number of clock iterations
51
 
52
BEGIN
53
 
54
        --! Instantiate the Unit Under Test (RegisterFile) (Doxygen bug if it's not commented!)
55
   uut: RegisterFile PORT MAP (
56
          clk => clk,
57
          writeEn => writeEn,
58
          writeAddr => writeAddr,
59
          input => input,
60
          Read_A_En => Read_A_En,
61
          Read_A_Addr => Read_A_Addr,
62
          Read_B_En => Read_B_En,
63
          Read_B_Addr => Read_B_Addr,
64
          A_Out => A_Out,
65
          B_Out => B_Out
66
        );
67
 
68
   --! Process that will stimulate all register assignments, and reads...
69
   stim_proc: process
70 15 leonardoar
        variable allZ : std_logic_vector((nBits - 1) downto 0) := (others => 'Z');
71 14 leonardoar
   begin
72
                -- r0=1 ... r15=16---------------------------------------------------------------------------
73
                clk <= '0';
74
                REPORT "Write r0 := 1" SEVERITY NOTE;
75
                writeEn <= '1';
76
                writeAddr <= r0;
77
                input <= conv_std_logic_vector(1, nBits);
78
                wait for 1 ns;
79
                clk <= '1';
80
                wait for 1 ns;  -- Wait to stabilize the response
81
 
82
                clk <= '0';
83
                REPORT "Write r1 := 2" SEVERITY NOTE;
84
                writeEn <= '1';
85
                writeAddr <= r1;
86
                input <= conv_std_logic_vector(2, nBits);
87
                wait for 1 ns;
88
                clk <= '1';
89
                wait for 1 ns;  -- Wait to stabilize the response
90
 
91
                clk <= '0';
92
                REPORT "Write r2 := 3" SEVERITY NOTE;
93
                writeEn <= '1';
94
                writeAddr <= r2;
95
                input <= conv_std_logic_vector(3, nBits);
96
                wait for 1 ns;
97
                clk <= '1';
98
                wait for 1 ns;  -- Wait to stabilize the response
99
 
100
                clk <= '0';
101
                REPORT "Write r3 := 4" SEVERITY NOTE;
102
                writeEn <= '1';
103
                writeAddr <= r3;
104
                input <= conv_std_logic_vector(4, nBits);
105
                wait for 1 ns;
106
                clk <= '1';
107
                wait for 1 ns;  -- Wait to stabilize the response
108
 
109
                clk <= '0';
110
                REPORT "Write r4 := 5" SEVERITY NOTE;
111
                writeEn <= '1';
112
                writeAddr <= r4;
113
                input <= conv_std_logic_vector(5, nBits);
114
                wait for 1 ns;
115
                clk <= '1';
116
                wait for 1 ns;  -- Wait to stabilize the response
117
 
118
                clk <= '0';
119
                writeEn <= '0';
120
                wait for 1 ns;  -- Wait to stabilize the response               
121
                -- Read r0..r15 PortA-------------------------------------------------------------------------
122
                REPORT "Check r0 = 1" SEVERITY NOTE;
123
                Read_A_En <= '1';
124
                Read_A_Addr <= r0;
125
                wait for 1 ns;  -- Wait to stabilize the response
126
                assert A_Out = conv_std_logic_vector(1, nBits) report "Invalid value r0" severity FAILURE;
127 15 leonardoar
                assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
128 14 leonardoar
 
129
                REPORT "Check r1 = 2" SEVERITY NOTE;
130
                Read_A_En <= '1';
131
                Read_A_Addr <= r1;
132
                wait for 1 ns;  -- Wait to stabilize the response
133
                assert A_Out = conv_std_logic_vector(2, nBits) report "Invalid value r1" severity FAILURE;
134 15 leonardoar
                assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
135 14 leonardoar
 
136
                REPORT "Check r2 = 3" SEVERITY NOTE;
137
                Read_A_En <= '1';
138
                Read_A_Addr <= r2;
139
                wait for 1 ns;  -- Wait to stabilize the response
140
                assert A_Out = conv_std_logic_vector(3, nBits) report "Invalid value r2" severity FAILURE;
141 15 leonardoar
                assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
142 14 leonardoar
 
143
                REPORT "Check r3 = 4" SEVERITY NOTE;
144
                Read_A_En <= '1';
145
                Read_A_Addr <= r3;
146
                wait for 1 ns;  -- Wait to stabilize the response
147
                assert A_Out = conv_std_logic_vector(4, nBits) report "Invalid value r3" severity FAILURE;
148 15 leonardoar
                assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
149 14 leonardoar
 
150
                REPORT "Check r4 = 5" SEVERITY NOTE;
151
                Read_A_En <= '1';
152
                Read_A_Addr <= r4;
153
                wait for 1 ns;  -- Wait to stabilize the response
154
                assert A_Out = conv_std_logic_vector(5, nBits) report "Invalid value r4" severity FAILURE;
155 15 leonardoar
                assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
156 14 leonardoar
 
157
      wait;
158
   end process;
159
 
160
END;

powered by: WebSVN 2.1.0

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