1 |
36 |
leonardoar |
--! @file
|
2 |
|
|
--! @brief Testbench for OpenCpu top design
|
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 |
37 |
leonardoar |
--! Adding library for File I/O
|
14 |
|
|
-- More information on this site:
|
15 |
|
|
-- http://eesun.free.fr/DOC/vhdlref/refguide/language_overview/test_benches/reading_and_writing_files_with_text_i_o.htm
|
16 |
36 |
leonardoar |
use std.textio.ALL;
|
17 |
|
|
use ieee.std_logic_textio.all;
|
18 |
|
|
|
19 |
|
|
ENTITY testOpenCpu IS
|
20 |
37 |
leonardoar |
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
21 |
36 |
leonardoar |
END testOpenCpu;
|
22 |
|
|
|
23 |
|
|
--! @brief openCpu Testbench file
|
24 |
|
|
--! @details This is the top-level test...
|
25 |
|
|
ARCHITECTURE behavior OF testOpenCpu IS
|
26 |
|
|
|
27 |
|
|
--! Component declaration to instantiate the Multiplexer circuit
|
28 |
|
|
COMPONENT openCpu
|
29 |
37 |
leonardoar |
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
30 |
|
|
Port ( rst : in STD_LOGIC; --! Reset signal
|
31 |
|
|
clk : in STD_LOGIC; --! Clock signal
|
32 |
|
|
mem_rd : out STD_LOGIC; --! Main memory Read enable
|
33 |
|
|
mem_rd_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Read address
|
34 |
|
|
mem_wr : out STD_LOGIC; --! Main memory Write enable
|
35 |
|
|
mem_wr_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Write address
|
36 |
|
|
mem_data_in : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from main memory
|
37 |
|
|
mem_data_out : out STD_LOGIC_VECTOR (n downto 0) --! Data to main memory
|
38 |
|
|
);
|
39 |
36 |
leonardoar |
END COMPONENT;
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
--Inputs
|
43 |
37 |
leonardoar |
signal rst : std_logic := '0'; --! Wire to connect Test signal to component
|
44 |
|
|
signal clk : std_logic := '0'; --! Wire to connect Test signal to component
|
45 |
|
|
signal mem_data_in : std_logic_vector(n downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
46 |
36 |
leonardoar |
|
47 |
|
|
--Outputs
|
48 |
37 |
leonardoar |
signal mem_rd : std_logic; --! Wire to connect Test signal to component
|
49 |
|
|
signal mem_rd_addr : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
50 |
|
|
signal mem_wr : std_logic; --! Wire to connect Test signal to component
|
51 |
|
|
signal mem_wr_addr : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
52 |
|
|
signal mem_data_out : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
53 |
36 |
leonardoar |
|
54 |
|
|
-- Clock period definitions
|
55 |
|
|
constant clk_period : time := 10 ns;
|
56 |
|
|
|
57 |
|
|
BEGIN
|
58 |
|
|
|
59 |
37 |
leonardoar |
--! Instantiate the Unit Under Test (openCpu) (Doxygen bug if it's not commented!)
|
60 |
36 |
leonardoar |
uut: openCpu PORT MAP (
|
61 |
|
|
rst => rst,
|
62 |
|
|
clk => clk,
|
63 |
|
|
mem_rd => mem_rd,
|
64 |
|
|
mem_rd_addr => mem_rd_addr,
|
65 |
|
|
mem_wr => mem_wr,
|
66 |
|
|
mem_wr_addr => mem_wr_addr,
|
67 |
|
|
mem_data_in => mem_data_in,
|
68 |
|
|
mem_data_out => mem_data_out
|
69 |
|
|
);
|
70 |
|
|
|
71 |
|
|
-- Clock process definitions
|
72 |
|
|
clk_process :process
|
73 |
|
|
begin
|
74 |
|
|
clk <= '0';
|
75 |
|
|
wait for clk_period/2;
|
76 |
|
|
clk <= '1';
|
77 |
|
|
wait for clk_period/2;
|
78 |
|
|
end process;
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
-- Stimulus process
|
82 |
39 |
leonardoar |
stim_proc: process
|
83 |
|
|
file cmdfile: TEXT; -- Define the file 'handle'
|
84 |
|
|
variable line_in,line_out: Line; -- Line buffer
|
85 |
|
|
variable good: boolean; -- Flag to detect a good line read
|
86 |
|
|
variable instructionCode : std_logic_vector(n downto 0);
|
87 |
36 |
leonardoar |
begin
|
88 |
|
|
-- Reset operation
|
89 |
39 |
leonardoar |
REPORT "RESET" SEVERITY NOTE;
|
90 |
|
|
-- Open source file
|
91 |
|
|
FILE_OPEN(cmdfile,"testCode/testCodeBin.dat",READ_MODE);
|
92 |
|
|
|
93 |
|
|
-- Check end of file
|
94 |
|
|
if endfile(cmdfile) then
|
95 |
|
|
assert false report "End of file found..." severity failure;
|
96 |
|
|
end if;
|
97 |
|
|
|
98 |
36 |
leonardoar |
rst <= '1';
|
99 |
|
|
wait for 2 ns;
|
100 |
|
|
rst <= '0';
|
101 |
|
|
wait for 2 ns;
|
102 |
|
|
|
103 |
39 |
leonardoar |
wait until mem_rd = '1';
|
104 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
105 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
106 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
107 |
|
|
mem_data_in <= instructionCode;
|
108 |
|
|
|
109 |
|
|
wait for CLK_period;
|
110 |
|
|
|
111 |
|
|
wait until mem_rd = '1';
|
112 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
113 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
114 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
115 |
|
|
mem_data_in <= instructionCode;
|
116 |
36 |
leonardoar |
|
117 |
39 |
leonardoar |
wait for CLK_period;
|
118 |
|
|
|
119 |
|
|
wait until mem_rd = '1';
|
120 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
121 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
122 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
123 |
|
|
mem_data_in <= instructionCode;
|
124 |
|
|
|
125 |
|
|
wait for CLK_period;
|
126 |
|
|
|
127 |
|
|
wait until mem_rd = '1';
|
128 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
129 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
130 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
131 |
|
|
mem_data_in <= instructionCode;
|
132 |
|
|
|
133 |
|
|
wait for CLK_period;
|
134 |
|
|
|
135 |
|
|
wait until mem_rd = '1';
|
136 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
137 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
138 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
139 |
|
|
mem_data_in <= instructionCode;
|
140 |
|
|
|
141 |
|
|
wait for CLK_period;
|
142 |
|
|
|
143 |
|
|
wait until mem_rd = '1';
|
144 |
|
|
readline(cmdfile,line_in); -- Read a line from the file
|
145 |
|
|
read(line_in,instructionCode,good); -- Read the CI input
|
146 |
|
|
assert good report "Could not parse the line" severity ERROR;
|
147 |
|
|
mem_data_in <= instructionCode;
|
148 |
|
|
|
149 |
|
|
wait for CLK_period;
|
150 |
36 |
leonardoar |
|
151 |
|
|
-- Finish simulation
|
152 |
|
|
assert false report "NONE. End of simulation." severity failure;
|
153 |
|
|
wait;
|
154 |
|
|
end process;
|
155 |
|
|
|
156 |
|
|
END;
|