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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testControlUnit.vhd] - Blame information for rev 34

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

Line No. Rev Author Line
1 22 leonardoar
--! @file
2
--! @brief Testbench for ControlUnit
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 testControlUnit IS
14 32 leonardoar
generic (n : integer := nBits - 1);                                                                     --! Generic value (Used to easily change the size of the Alu on the package)
15 22 leonardoar
END testControlUnit;
16
 
17
--! @brief ControlUnit Testbench file
18
--! @details Exercise the control unit with a assembly program sample
19
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
20
ARCHITECTURE behavior OF testControlUnit IS
21
 
22
    -- Component Declaration for the Unit Under Test (UUT)
23
 
24
    COMPONENT ControlUnit
25 32 leonardoar
    generic (n : integer := nBits - 1);                                                                 --! Generic value (Used to easily change the size of the Alu on the package)
26
         Port ( reset : in  STD_LOGIC;
27
           clk : in  STD_LOGIC;                                                                                         --! Main system clock
28
           FlagsDp : in  STD_LOGIC_VECTOR (2 downto 0);                          --! Flags comming from the Datapath
29
           DataDp : in  STD_LOGIC_VECTOR (n downto 0);                           --! Data comming from the Datapath
30
                          outEnDp : out  typeEnDis;                                                                             --! Enable/Disable datapath output
31
           MuxDp : out  STD_LOGIC_VECTOR (2 downto 0);                           --! Select on datapath data from (Memory, Imediate, RegFileA, RegFileB, AluOut)
32
                          MuxRegDp : out STD_LOGIC_VECTOR(1 downto 0);                           --! Select Alu InputA (Memory,Imediate,RegFileA)
33
           ImmDp : out  STD_LOGIC_VECTOR (n downto 0);                           --! Imediate value passed to the Datapath
34
           DpAluOp : out  aluOps;                                                                                       --! Alu operations
35
                          DpRegFileWriteAddr : out  generalRegisters;                           --! General register address to write
36
           DpRegFileWriteEn : out  STD_LOGIC;                                                   --! Enable register write
37
           DpRegFileReadAddrA : out  generalRegisters;                          --! General register address to read
38
           DpRegFileReadAddrB : out  generalRegisters;                          --! General register address to read
39
           DpRegFileReadEnA : out  STD_LOGIC;                                                   --! Enable register read (PortA)
40
           DpRegFileReadEnB : out  STD_LOGIC;                                                   --! Enable register read (PortB)
41
           MemoryDataReadEn : out std_logic;                                                            --! Enable Main memory read
42
                          MemoryDataWriteEn: out std_logic;                                                             --! Enable Main memory write
43
                          MemoryDataInput : in  STD_LOGIC_VECTOR (n downto 0);   --! Incoming data from main memory
44
           MemoryDataRdAddr : out  STD_LOGIC_VECTOR (n downto 0);        --! Main memory Read address
45
                          MemoryDataWrAddr : out  STD_LOGIC_VECTOR (n downto 0); --! Main memory Write address
46
           MemoryDataOut : out  STD_LOGIC_VECTOR (n downto 0));  --! Data to write on main memory
47 22 leonardoar
    END COMPONENT;
48
 
49
 
50
   --Inputs
51
   signal reset : std_logic := '0';                                                                                                                      --! Wire to connect Test signal to component
52
   signal clk : std_logic := '0';                                                                                                                        --! Wire to connect Test signal to component
53 32 leonardoar
   signal FlagsDp : std_logic_vector(2 downto 0) := (others => '0');                              --! Wire to connect Test signal to component
54
   signal DataDp : std_logic_vector(n downto 0) := (others => '0');                               --! Wire to connect Test signal to component
55
   signal MemoryDataInput : std_logic_vector(n downto 0) := (others => '0');      --! Wire to connect Test signal to component
56 22 leonardoar
 
57
        --Outputs
58 32 leonardoar
   signal outEnDp : typeEnDis;                                                                                                                          --! Wire to connect Test signal to component
59
        signal MuxDp : std_logic_vector(2 downto 0);                                                                                     --! Wire to connect Test signal to component
60
        signal MuxRegDp : std_logic_vector(1 downto 0);                                                                          --! Wire to connect Test signal to component
61
   signal ImmDp : std_logic_vector(n downto 0);                                                                                  --! Wire to connect Test signal to component
62
        signal DpAluOp : aluOps;                                                                                                                                        --! Wire to connect Test signal to component
63
   signal DpRegFileWriteAddr : generalRegisters;                                                                                --! Wire to connect Test signal to component
64 22 leonardoar
   signal DpRegFileWriteEn : std_logic;                                                                                                 --! Wire to connect Test signal to component
65 32 leonardoar
   signal DpRegFileReadAddrA : generalRegisters;                                                                                --! Wire to connect Test signal to component
66
   signal DpRegFileReadAddrB : generalRegisters;                                                                                --! Wire to connect Test signal to component
67 22 leonardoar
   signal DpRegFileReadEnA : std_logic;                                                                                                 --! Wire to connect Test signal to component
68
   signal DpRegFileReadEnB : std_logic;                                                                                                 --! Wire to connect Test signal to component
69 32 leonardoar
        signal MemoryDataReadEn : std_logic;                                                                                                    --! Wire to connect Test signal to component
70
        signal MemoryDataWriteEn : std_logic;                                                                                                   --! Wire to connect Test signal to component
71
        signal MemoryDataRdAddr : std_logic_vector(n downto 0);                                                  --! Wire to connect Test signal to component
72
   signal MemoryDataWrAddr : std_logic_vector(n downto 0);                                                       --! Wire to connect Test signal to component
73
   signal MemoryDataOut : std_logic_vector(n downto 0);                                                          --! Wire to connect Test signal to component
74 22 leonardoar
 
75
   -- Clock period definitions
76
   constant clk_period : time := 10 ns;
77
 
78
BEGIN
79
 
80
        --! Instantiate the Unit Under Test (ControlUnit)
81 32 leonardoar
   uut: ControlUnit PORT MAP (
82
                        reset => reset,
83
                        clk => clk,
84
                        FlagsDp => FlagsDp,
85
                        DataDp => DataDp,
86
                        outEnDp => outEnDp,
87
                        MuxDp => MuxDp,
88
                        MuxRegDp => MuxRegDp,
89
                        ImmDp => ImmDp,
90
                        DpAluOp => DpAluOp,
91
                        DpRegFileWriteAddr => DpRegFileWriteAddr,
92
                        DpRegFileWriteEn => DpRegFileWriteEn,
93
                        DpRegFileReadAddrA => DpRegFileReadAddrA,
94
                        DpRegFileReadAddrB => DpRegFileReadAddrB,
95
                        DpRegFileReadEnA => DpRegFileReadEnA,
96
                        DpRegFileReadEnB => DpRegFileReadEnB,
97
                        MemoryDataReadEn => MemoryDataReadEn,
98
                        MemoryDataWriteEn => MemoryDataWriteEn,
99
                        MemoryDataInput => MemoryDataInput,
100
                        MemoryDataRdAddr => MemoryDataRdAddr,
101
                        MemoryDataWrAddr => MemoryDataWrAddr,
102
                        MemoryDataOut => MemoryDataOut
103 22 leonardoar
        );
104
 
105
   -- Clock process definitions
106
   clk_process :process
107
   begin
108
                clk <= '0';
109
                wait for clk_period/2;
110
                clk <= '1';
111
                wait for clk_period/2;
112
   end process;
113
 
114
 
115
   -- Stimulus process
116
   stim_proc: process
117 32 leonardoar
   begin
118
                -- Reset operation
119
                REPORT "RESET" SEVERITY NOTE;
120
                reset <= '1';
121
      wait for 2 ns;
122
                reset <= '0';
123
                wait for 2 ns;
124 22 leonardoar
 
125 33 leonardoar
      -- MOV r0,10d (Compare control unit outputs with Datapath)--------------------------------------
126 32 leonardoar
                REPORT "MOV r0,10" SEVERITY NOTE;
127 33 leonardoar
                MemoryDataInput <= mov_val & conv_std_logic_vector(reg2Num(r0),4) & conv_std_logic_vector(10, 22);
128
                wait for CLK_period;    -- Fetch
129
                wait for CLK_period;    -- Decode
130
                wait for CLK_period;    -- Execute
131 34 leonardoar
 
132
                -- Verify if signals for the datapath are valid
133
                assert ImmDp = conv_std_logic_vector(10, nBits) report "Invalid value" severity FAILURE;
134
                assert DpRegFileWriteAddr = r0 report "Invalid value" severity FAILURE;
135
      assert DpAluOp = alu_pass report "Invalid value" severity FAILURE;
136
                assert MuxDp = muxPos(fromImediate) report "Invalid value" severity FAILURE;
137
 
138 33 leonardoar
                wait for CLK_period;    -- Executing ... 1
139
 
140 34 leonardoar
                -- State writing on the registers
141
                assert DpRegFileWriteEn = '1' report "Invalid value" severity FAILURE;
142
 
143
                wait for CLK_period;    -- Executing ...2 (Releasing lines.... (Next instruction should come...)                                
144
 
145
                -- Verify if all lines are unasserted
146
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
147
                assert DpRegFileReadEnB = '0' report "Invalid value" severity FAILURE;
148
                assert DpRegFileReadEnA = '0' report "Invalid value" severity FAILURE;
149
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
150
                assert outEnDp = disable report "Invalid value" severity FAILURE;
151
                -------------------------------------------------------------------------------------------------
152
 
153 33 leonardoar
                -- MOV r1,20d (Compare control unit outputs with Datapath)--------------------------------------
154
                REPORT "MOV r1,20" SEVERITY NOTE;
155
                MemoryDataInput <= mov_val & conv_std_logic_vector(reg2Num(r1),4) & conv_std_logic_vector(20, 22);
156
                wait for CLK_period;    -- Fetch
157
                wait for CLK_period;    -- Decode
158
                wait for CLK_period;    -- Execute
159 34 leonardoar
 
160
                -- Verify if signals for the datapath are valid
161
                assert ImmDp = conv_std_logic_vector(20, nBits) report "Invalid value" severity FAILURE;
162
                assert DpRegFileWriteAddr = r1 report "Invalid value" severity FAILURE;
163
      assert DpAluOp = alu_pass report "Invalid value" severity FAILURE;
164
                assert MuxDp = muxPos(fromImediate) report "Invalid value" severity FAILURE;
165
 
166 33 leonardoar
                wait for CLK_period;    -- Executing ... 1
167 34 leonardoar
 
168
                -- State writing on the registers
169
                assert DpRegFileWriteEn = '1' report "Invalid value" severity FAILURE;
170
 
171
                wait for CLK_period;    -- Executing ...2 (Releasing lines.... (Next instruction should come...)                                
172
 
173
                -- Verify if all lines are unasserted
174
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
175
                assert DpRegFileReadEnB = '0' report "Invalid value" severity FAILURE;
176
                assert DpRegFileReadEnA = '0' report "Invalid value" severity FAILURE;
177
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
178
                assert outEnDp = disable report "Invalid value" severity FAILURE;
179
                -------------------------------------------------------------------------------------------------
180
 
181
                -- MOV r2,r1 (Compare control unit outputs with Datapath)--------------------------------------
182
                REPORT "MOV r2,r1" SEVERITY NOTE;
183
                MemoryDataInput <= mov_reg & conv_std_logic_vector(reg2Num(r2),4) & conv_std_logic_vector(reg2Num(r1),4) & "000000000000000000";
184
                wait for CLK_period;    -- Fetch
185
                wait for CLK_period;    -- Decode
186
                wait for CLK_period;    -- Execute
187
 
188
                -- Verify if signals for the datapath are valid         
189
                assert DpRegFileReadAddrB = r1 report "Invalid value" severity FAILURE;
190
                assert DpRegFileWriteAddr = r2 report "Invalid value" severity FAILURE;
191
                assert MuxDp = muxPos(fromRegFileB) report "Invalid value" severity FAILURE;
192
                assert DpRegFileReadEnB = '1' report "Invalid value" severity FAILURE;
193
                wait for CLK_period;    -- Executing ... 1
194
 
195
                -- State writing on the registers
196
                assert DpRegFileWriteEn = '1' report "Invalid value" severity FAILURE;
197
 
198
                wait for CLK_period;    -- Executing ...2 (Releasing lines.... (Next instruction should come...)                                
199
 
200
                -- Verify if all lines are unasserted
201
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
202
                assert DpRegFileReadEnB = '0' report "Invalid value" severity FAILURE;
203
                assert DpRegFileReadEnA = '0' report "Invalid value" severity FAILURE;
204
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
205
                assert outEnDp = disable report "Invalid value" severity FAILURE;
206
                -------------------------------------------------------------------------------------------------
207
 
208
                -- ADD r2,r0 (Compare control unit outputs with Datapath)--------------------------------------
209
                REPORT "ADD r2,r0" SEVERITY NOTE;
210
                MemoryDataInput <= add_reg & conv_std_logic_vector(reg2Num(r2),4) & conv_std_logic_vector(reg2Num(r0),4) & "000000000000000000";
211
                wait for CLK_period;    -- Fetch
212
                wait for CLK_period;    -- Decode
213
                wait for CLK_period;    -- Execute
214
 
215
                -- Verify if signals for the datapath are valid         
216
                assert DpRegFileReadAddrB = r0 report "Invalid value" severity FAILURE;
217
                assert DpRegFileReadAddrA = r2 report "Invalid value" severity FAILURE;
218
                assert DpRegFileWriteAddr = r2 report "Invalid value" severity FAILURE;
219
                assert MuxDp = muxPos(fromAlu) report "Invalid value" severity FAILURE;
220
                assert DpAluOp = alu_sum report "Invalid value" severity FAILURE;
221
                assert DpRegFileReadEnB = '1' report "Invalid value" severity FAILURE;
222
                assert DpRegFileReadEnA = '1' report "Invalid value" severity FAILURE;
223
                assert MuxRegDp = muxRegPos(fromRegFileA) report "Invalid value" severity FAILURE;
224
                wait for CLK_period;    -- Executing ... 1
225
 
226
                -- State writing on the registers
227
                assert DpRegFileWriteEn = '1' report "Invalid value" severity FAILURE;
228
 
229
                wait for CLK_period;    -- Executing ...2 (Releasing lines.... (Next instruction should come...)                                
230
 
231
                -- Verify if all lines are unasserted
232
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
233
                assert DpRegFileReadEnB = '0' report "Invalid value" severity FAILURE;
234
                assert DpRegFileReadEnA = '0' report "Invalid value" severity FAILURE;
235
                assert DpRegFileWriteEn = '0' report "Invalid value" severity FAILURE;
236
                assert outEnDp = disable report "Invalid value" severity FAILURE;
237
                -------------------------------------------------------------------------------------------------
238 22 leonardoar
 
239 34 leonardoar
      -- Finish simulation
240
                assert false report "NONE. End of simulation." severity failure;
241
                wait;
242 22 leonardoar
   end process;
243
 
244
END;

powered by: WebSVN 2.1.0

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