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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testDataPath.vhd] - Blame information for rev 42

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

Line No. Rev Author Line
1 17 leonardoar
--! @file
2 20 leonardoar
--! @brief Testbench for Datapath
3 17 leonardoar
 
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 testDataPath IS
14 32 leonardoar
generic (n : integer := nBits - 1);                                                                             --! Generic value (Used to easily change the size of the Alu on the package)
15 17 leonardoar
END testDataPath;
16
 
17 20 leonardoar
--! @brief Datapath Testbench file
18
--! @details Attention to this testbench because it will give you hints on how the control circuit must work....
19 17 leonardoar
--! for more information: http://vhdlguru.blogspot.com/2010/03/how-to-write-testbench.html
20
ARCHITECTURE behavior OF testDataPath IS
21
 
22
         --! Component declaration to instantiate the Alu circuit
23
    COMPONENT DataPath
24
    generic (n : integer := nBits - 1);                                                                 --! Generic value (Used to easily change the size of the Alu on the package)
25
         Port ( inputMm : in  STD_LOGIC_VECTOR (n downto 0);                     --! Input of Datapath from main memory       
26
                          inputImm : in  STD_LOGIC_VECTOR (n downto 0);                  --! Input of Datapath from imediate value (instructions...)
27
                          clk : in  STD_LOGIC;                                                                                          --! Clock signal
28
           outEn : in  typeEnDis;                                                                                       --! Enable/Disable datapath output
29
           aluOp : in  aluOps;                                                                                          --! Alu operations
30 42 leonardoar
           muxSel : in  dpMuxInputs;                                                                            --! Select inputs from dataPath(Memory,Imediate,RegisterFile,Alu)
31 27 leonardoar
                          muxRegFile : in STD_LOGIC_VECTOR(1 downto 0);                          --! Select Alu InputA (Memory,Imediate,RegFileA)
32 17 leonardoar
           regFileWriteAddr : in  generalRegisters;                                     --! General register write address
33
           regFileWriteEn : in  STD_LOGIC;                                                              --! RegisterFile write enable signal
34
           regFileReadAddrA : in  generalRegisters;                                     --! General register read address (PortA)
35
           regFileReadAddrB : in  generalRegisters;                                     --! General register read address (PortB)
36
           regFileEnA : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortA
37
           regFileEnB : in  STD_LOGIC;                                                                          --! Enable RegisterFile PortB
38
                          outputDp : out  STD_LOGIC_VECTOR (n downto 0);                 --! DataPath Output
39 29 leonardoar
           dpFlags : out  STD_LOGIC_VECTOR (2 downto 0));                        --! Alu Flags
40 17 leonardoar
    END COMPONENT;
41
 
42
 
43
   --Inputs
44 32 leonardoar
   signal inputMm : std_logic_vector(n downto 0) := (others => 'U');             --! Wire to connect Test signal to component
45
   signal inputImm : std_logic_vector(n downto 0) := (others => 'U');    --! Wire to connect Test signal to component
46 17 leonardoar
   signal clk : std_logic := '0';                                                                                                        --! Wire to connect Test signal to component
47 20 leonardoar
   signal outEn : typeEnDis := disable;                                                                                 --! Wire to connect Test signal to component
48
   signal aluOp : aluOps := alu_pass;                                                                                           --! Wire to connect Test signal to component
49 42 leonardoar
   signal muxSel : dpMuxInputs := fromMemory;                                                                   --! Wire to connect Test signal to component
50 27 leonardoar
        signal muxRegFile : std_logic_vector(1 downto 0) := (others => 'U'); --! Wire to connect Test signal to component
51 20 leonardoar
   signal regFileWriteAddr : generalRegisters := r0;                                                    --! Wire to connect Test signal to component
52 17 leonardoar
   signal regFileWriteEn : std_logic := '0';                                                                             --! Wire to connect Test signal to component
53 20 leonardoar
   signal regFileReadAddrA : generalRegisters := r0;                                                    --! Wire to connect Test signal to component
54
        signal regFileReadAddrB : generalRegisters := r0;                                                       --! Wire to connect Test signal to component   
55 17 leonardoar
   signal regFileEnA : std_logic := '0';                                                                                 --! Wire to connect Test signal to component
56
   signal regFileEnB : std_logic := '0';                                                                                 --! Wire to connect Test signal to component
57
 
58
        --Outputs
59 32 leonardoar
   signal outputDp : std_logic_vector(n downto 0);                                                               --! Wire to connect Test signal to component
60 29 leonardoar
   signal dpFlags : std_logic_vector(2 downto 0);                                                                --! Wire to connect Test signal to component
61 17 leonardoar
 
62 20 leonardoar
        -- Clock period definitions
63
   constant CLK_period : time := 10 ns;
64 17 leonardoar
 
65
BEGIN
66
 
67
        --! Instantiate the Unit Under Test (Alu) (Doxygen bug if it's not commented!)
68
   uut: DataPath PORT MAP (
69
          inputMm => inputMm,
70
          inputImm => inputImm,
71
          clk => clk,
72
          outEn => outEn,
73
          aluOp => aluOp,
74
          muxSel => muxSel,
75 27 leonardoar
                         muxRegFile => muxRegFile,
76 17 leonardoar
          regFileWriteAddr => regFileWriteAddr,
77
          regFileWriteEn => regFileWriteEn,
78
          regFileReadAddrA => regFileReadAddrA,
79
          regFileReadAddrB => regFileReadAddrB,
80
          regFileEnA => regFileEnA,
81
          regFileEnB => regFileEnB,
82
          outputDp => outputDp,
83
          dpFlags => dpFlags
84
        );
85 20 leonardoar
 
86
        -- Clock process definitions
87
   CLK_process :process
88
   begin
89
                CLK <= '0';
90
                wait for CLK_period/2;
91
                CLK <= '1';
92
                wait for CLK_period/2;
93
   end process;
94 17 leonardoar
 
95
   -- Stimulus process
96
   stim_proc: process
97
   begin
98 20 leonardoar
      -- MOV r0,10d ---------------------------------------------------------------------------------
99
                REPORT "MOV r0,10" SEVERITY NOTE;
100
                inputImm <= conv_std_logic_vector(10, nBits);
101
                regFileWriteAddr <= r0;
102
      aluOp <= alu_pass;
103 42 leonardoar
                muxSel <= fromImediate;
104 27 leonardoar
                muxRegFile <= muxRegPos(fromRegFileA);
105 20 leonardoar
                regFileWriteEn <= '1';
106
                wait for CLK_period;    -- Wait for clock cycle to latch some data to the register file
107
                -- Read value in r0 to verify if is equal to 20
108
                regFileWriteEn <= '0';
109
                inputImm <= (others => 'U');
110 42 leonardoar
                muxSel <= fromRegFileA;
111 20 leonardoar
                regFileReadAddrA <= r0; -- Read data from r0 and verify if it's 10
112
                regFileEnA <= '1';
113
                outEn <= enable;
114
                wait for 1 ns;  -- Wait for data to settle
115
                assert outputDp = conv_std_logic_vector(10, nBits) report "Invalid value" severity FAILURE;
116
                wait for 1 ns;  -- Finish test case
117 42 leonardoar
                muxSel <= fromMemory;
118 20 leonardoar
                regFileEnA <= '0';
119
                outEn <= disable;
120
 
121
 
122
                -- MOV r1,20d ---------------------------------------------------------------------------------
123
                REPORT "MOV r1,20" SEVERITY NOTE;
124
                inputImm <= conv_std_logic_vector(20, nBits);
125
                regFileWriteAddr <= r1;
126
      aluOp <= alu_pass;
127 42 leonardoar
                muxSel <= fromImediate;
128 27 leonardoar
                muxRegFile <= muxRegPos(fromRegFileA);
129 20 leonardoar
                regFileWriteEn <= '1';
130
                wait for CLK_period;    -- Wait for clock cycle to latch some data to the register file
131
                -- Read value in r1 to verify if is equal to 20
132
                regFileWriteEn <= '0';
133
                inputImm <= (others => 'U');
134 42 leonardoar
                muxSel <= fromRegFileA;
135 20 leonardoar
                regFileReadAddrA <= r1; -- Read data from r0 and verify if it's 10
136
                regFileEnA <= '1';
137
                outEn <= enable;
138
                wait for 1 ns;  -- Wait for data to settle
139
                assert outputDp = conv_std_logic_vector(20, nBits) report "Invalid value" severity FAILURE;
140
                wait for 1 ns;  -- Finish test case
141 42 leonardoar
                muxSel <= fromMemory;
142 20 leonardoar
                regFileEnA <= '0';
143
                outEn <= disable;
144
 
145 21 leonardoar
 
146 20 leonardoar
                -- MOV r2,r1 (r2 <= r1) --------------------------------------------------------------------
147
                REPORT "MOV r2,r1" SEVERITY NOTE;
148
                regFileReadAddrB <= r1; -- Read data from r1 
149
                regFileEnB <= '1';
150
                regFileWriteAddr <= r2; -- Write data in r2
151 42 leonardoar
                muxSel <= fromRegFileB; -- Select the PortB output from regFile
152 27 leonardoar
                muxRegFile <= muxRegPos(fromRegFileA);
153 20 leonardoar
                regFileWriteEn <= '1';
154
                wait for CLK_period;    -- Wait for clock cycle to write into r2
155
                -- Read value in r2 to verify if is equal to r1(20)
156
                regFileWriteEn <= '0';
157
                inputImm <= (others => 'U');
158 42 leonardoar
                muxSel <= fromRegFileA;
159 20 leonardoar
                regFileReadAddrA <= r2; -- Read data from r0 and verify if it's 10
160
                regFileEnA <= '1';
161
                outEn <= enable;
162
                wait for 1 ns;  -- Wait for data to settle
163
                assert outputDp = conv_std_logic_vector(20, nBits) report "Invalid value" severity FAILURE;
164
                wait for 1 ns;  -- Finish test case
165 42 leonardoar
                muxSel <= fromMemory;
166 20 leonardoar
                regFileEnA <= '0';
167
                outEn <= disable;
168 21 leonardoar
                wait for 1 ns;  -- Finish test case
169 20 leonardoar
 
170
                -- ADD r2,r0 (r2 <= r2+r0)
171
                REPORT "ADD r2,r0" SEVERITY NOTE;
172
                regFileReadAddrA <= r2; -- Read data from r2
173
                regFileEnA <= '1';
174
                regFileReadAddrB <= r0; -- Read data from r0 
175
                regFileEnB <= '1';
176
                aluOp <= alu_sum;
177
                regFileWriteAddr <= r2; -- Write data in r2
178 42 leonardoar
                muxSel <= fromAlu;      -- Select the Alu output
179 27 leonardoar
                muxRegFile <= muxRegPos(fromRegFileA);
180 20 leonardoar
                regFileWriteEn <= '1';
181
                wait for CLK_period;    -- Wait for clock cycle to write into r2
182
                -- Read value in r2 to verify if is equal to 30(10+20)
183
                regFileWriteEn <= '0';
184
                inputImm <= (others => 'U');
185 42 leonardoar
                muxSel <= fromRegFileB; -- Must access from other Port otherwise you will need an extra cycle to change it's address
186 20 leonardoar
                regFileReadAddrB <= r2; -- Read data from r0 and verify if it's 10
187
                regFileEnB <= '1';
188
                outEn <= enable;
189
                wait for 1 ns;  -- Wait for data to settle
190
                assert outputDp = conv_std_logic_vector(30, nBits) report "Invalid value" severity FAILURE;
191
                wait for 1 ns;  -- Finish test case
192 42 leonardoar
                muxSel <= fromMemory;
193 20 leonardoar
                regFileEnA <= '0';
194 21 leonardoar
                regFileEnB <= '0';
195 20 leonardoar
                outEn <= disable;
196 21 leonardoar
                wait for 1 ns;  -- If you don't use this wait the signals will not change...! (Take care of this when implementing the ControlUnit)
197 20 leonardoar
 
198 21 leonardoar
                -- ADD r3,r2,r0 (r3 <= r2+r0)
199
                REPORT "ADD r3,r2,r0" SEVERITY NOTE;
200
                regFileReadAddrA <= r2; -- Read data from r2
201
                regFileEnA <= '1';
202
                regFileReadAddrB <= r0; -- Read data from r0 
203
                regFileEnB <= '1';
204
                aluOp <= alu_sum;
205
                regFileWriteAddr <= r3; -- Write data in r2
206 42 leonardoar
                muxSel <= fromAlu;      -- Select the Alu output
207 27 leonardoar
                muxRegFile <= muxRegPos(fromRegFileA);
208 21 leonardoar
                regFileWriteEn <= '1';
209
                wait for CLK_period;    -- Wait for clock cycle to write into r2
210
                -- Read value in r2 to verify if is equal to 30(10+20)
211
                regFileWriteEn <= '0';
212
                inputImm <= (others => 'U');
213 42 leonardoar
                muxSel <= fromRegFileB; -- Must access from other Port otherwise you will need an extra cycle to change it's address
214 21 leonardoar
                regFileReadAddrB <= r3; -- Read data from r0 and verify if it's 10
215
                regFileEnB <= '1';
216
                outEn <= enable;
217
                wait for 1 ns;  -- Wait for data to settle
218
                assert outputDp = conv_std_logic_vector(40, nBits) report "Invalid value" severity FAILURE;
219
                wait for 1 ns;  -- Finish test case
220 42 leonardoar
                muxSel <= fromMemory;
221 21 leonardoar
                regFileEnA <= '0';
222
                regFileEnB <= '0';
223
                outEn <= disable;
224
 
225 27 leonardoar
                -- ADD r3,2 (r2 <= r2+2)
226
                REPORT "ADD r3,2" SEVERITY NOTE;
227
                inputImm <= conv_std_logic_vector(2, nBits);
228
                regFileReadAddrB <= r3; -- Read data from r2
229
                regFileEnB <= '1';
230
                regFileWriteAddr <= r3;
231
                muxRegFile <= muxRegPos(fromImediate);
232
      aluOp <= alu_sum;
233 42 leonardoar
                muxSel <= fromAlu;      -- Select the Alu output                
234 27 leonardoar
                regFileWriteEn <= '1';
235
                wait for CLK_period;    -- Wait for clock cycle to write into r2
236
                -- Read value in r2 to verify if is equal to 42(40+2)
237
                regFileWriteEn <= '0';
238
                inputImm <= (others => 'U');
239 42 leonardoar
                muxSel <= fromRegFileA; -- Must access from other Port otherwise you will need an extra cycle to change it's address
240 27 leonardoar
                regFileReadAddrA <= r3; -- Read data from r0 and verify if it's 10
241
                regFileEnA <= '1';
242
                outEn <= enable;
243
                wait for 1 ns;  -- Wait for data to settle
244
                assert outputDp = conv_std_logic_vector(42, nBits) report "Invalid value" severity FAILURE;
245
                wait for 1 ns;  -- Finish test case
246 42 leonardoar
                muxSel <= fromMemory;
247 27 leonardoar
                regFileEnA <= '0';
248
                regFileEnB <= '0';
249
                outEn <= disable;
250
                wait for 1 ns;  -- If you don't use this wait the signals will not change...! (Take care of this when implementing the ControlUnit)
251
 
252 17 leonardoar
 
253 20 leonardoar
      -- Finish simulation
254
                assert false report "NONE. End of simulation." severity failure;
255
                wait;
256 17 leonardoar
   end process;
257
 
258
END;

powered by: WebSVN 2.1.0

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