| 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 |
16 |
leonardoar |
signal Read_A_En : std_logic := 'X'; --! Wire to connect Test signal to component
|
| 42 |
14 |
leonardoar |
signal Read_A_Addr : generalRegisters := r0; --! Wire to connect Test signal to component
|
| 43 |
16 |
leonardoar |
signal Read_B_En : std_logic := 'X'; --! Wire to connect Test signal to component
|
| 44 |
14 |
leonardoar |
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 |
16 |
leonardoar |
-- r0=1 ... r15=16---------------------------------------------------------------------------
|
| 73 |
|
|
for i in 0 to (numGenRegs-1) loop
|
| 74 |
|
|
clk <= '0';
|
| 75 |
|
|
REPORT "Write r0 := 1" SEVERITY NOTE;
|
| 76 |
|
|
writeEn <= '1';
|
| 77 |
|
|
writeAddr <= Num2reg(i);
|
| 78 |
|
|
input <= conv_std_logic_vector(i+1, nBits);
|
| 79 |
|
|
wait for 1 ns;
|
| 80 |
|
|
clk <= '1';
|
| 81 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
| 82 |
|
|
end loop;
|
| 83 |
|
|
|
| 84 |
|
|
-- Mark write end....
|
| 85 |
14 |
leonardoar |
clk <= '0';
|
| 86 |
|
|
writeEn <= '0';
|
| 87 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
| 88 |
16 |
leonardoar |
|
| 89 |
|
|
-- Read r0..r15 PortA-------------------------------------------------------------------------
|
| 90 |
|
|
for i in 0 to (numGenRegs-1) loop
|
| 91 |
|
|
REPORT "Check r0 = 1" SEVERITY NOTE;
|
| 92 |
|
|
Read_A_En <= '1';
|
| 93 |
|
|
Read_A_Addr <= Num2reg(i);
|
| 94 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
| 95 |
|
|
assert A_Out = conv_std_logic_vector(i+1, nBits) report "Invalid value r0" severity FAILURE;
|
| 96 |
|
|
assert B_Out = allZ report "PortB should be high impedance" severity FAILURE;
|
| 97 |
|
|
end loop;
|
| 98 |
|
|
|
| 99 |
|
|
-- Mark read A end
|
| 100 |
|
|
Read_A_En <= 'X';
|
| 101 |
|
|
|
| 102 |
|
|
-- Read r0..r15 PortB-------------------------------------------------------------------------
|
| 103 |
|
|
for i in 0 to (numGenRegs-1) loop
|
| 104 |
|
|
REPORT "Check r0 = 1" SEVERITY NOTE;
|
| 105 |
|
|
Read_B_En <= '1';
|
| 106 |
|
|
Read_B_Addr <= Num2reg(i);
|
| 107 |
|
|
wait for 1 ns; -- Wait to stabilize the response
|
| 108 |
|
|
assert B_Out = conv_std_logic_vector(i+1, nBits) report "Invalid value r0" severity FAILURE;
|
| 109 |
|
|
assert A_Out = allZ report "PortB should be high impedance" severity FAILURE;
|
| 110 |
|
|
end loop;
|
| 111 |
|
|
|
| 112 |
|
|
-- Mark read B end
|
| 113 |
|
|
Read_B_En <= 'X';
|
| 114 |
18 |
leonardoar |
|
| 115 |
|
|
|
| 116 |
|
|
-- Finish simulation
|
| 117 |
|
|
assert false report "NONE. End of simulation." severity failure;
|
| 118 |
14 |
leonardoar |
end process;
|
| 119 |
|
|
|
| 120 |
|
|
END;
|