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

Subversion Repositories opencpu32

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

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

powered by: WebSVN 2.1.0

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