--! @file
|
--! @file
|
--! @brief Testbench for OpenCpu top design
|
--! @brief Testbench for OpenCpu top design
|
|
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
|
LIBRARY ieee;
|
LIBRARY ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_arith.all;
|
use ieee.std_logic_arith.all;
|
|
|
--! Use CPU Definitions package
|
--! Use CPU Definitions package
|
use work.pkgOpenCPU32.all;
|
use work.pkgOpenCPU32.all;
|
|
|
--! Adding library for File I/O (Synposys Text I/O package)
|
--! Adding library for File I/O
|
|
-- More information on this site:
|
|
-- http://eesun.free.fr/DOC/vhdlref/refguide/language_overview/test_benches/reading_and_writing_files_with_text_i_o.htm
|
use std.textio.ALL;
|
use std.textio.ALL;
|
use ieee.std_logic_textio.all;
|
use ieee.std_logic_textio.all;
|
|
|
ENTITY testOpenCpu IS
|
ENTITY testOpenCpu IS
|
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
END testOpenCpu;
|
END testOpenCpu;
|
|
|
--! @brief openCpu Testbench file
|
--! @brief openCpu Testbench file
|
--! @details This is the top-level test...
|
--! @details This is the top-level test...
|
ARCHITECTURE behavior OF testOpenCpu IS
|
ARCHITECTURE behavior OF testOpenCpu IS
|
|
|
--! Component declaration to instantiate the Multiplexer circuit
|
--! Component declaration to instantiate the Multiplexer circuit
|
COMPONENT openCpu
|
COMPONENT openCpu
|
PORT(
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
rst : IN std_logic;
|
Port ( rst : in STD_LOGIC; --! Reset signal
|
clk : IN std_logic;
|
clk : in STD_LOGIC; --! Clock signal
|
mem_rd : OUT std_logic;
|
mem_rd : out STD_LOGIC; --! Main memory Read enable
|
mem_rd_addr : OUT std_logic_vector(31 downto 0);
|
mem_rd_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Read address
|
mem_wr : OUT std_logic;
|
mem_wr : out STD_LOGIC; --! Main memory Write enable
|
mem_wr_addr : OUT std_logic_vector(31 downto 0);
|
mem_wr_addr : out STD_LOGIC_VECTOR (n downto 0); --! Main memory Write address
|
mem_data_in : IN std_logic_vector(31 downto 0);
|
mem_data_in : in STD_LOGIC_VECTOR (n downto 0); --! Data comming from main memory
|
mem_data_out : OUT std_logic_vector(31 downto 0)
|
mem_data_out : out STD_LOGIC_VECTOR (n downto 0) --! Data to main memory
|
);
|
);
|
END COMPONENT;
|
END COMPONENT;
|
|
|
|
|
--Inputs
|
--Inputs
|
signal rst : std_logic := '0';
|
signal rst : std_logic := '0'; --! Wire to connect Test signal to component
|
signal clk : std_logic := '0';
|
signal clk : std_logic := '0'; --! Wire to connect Test signal to component
|
signal mem_data_in : std_logic_vector(31 downto 0) := (others => '0');
|
signal mem_data_in : std_logic_vector(n downto 0) := (others => '0'); --! Wire to connect Test signal to component
|
|
|
--Outputs
|
--Outputs
|
signal mem_rd : std_logic;
|
signal mem_rd : std_logic; --! Wire to connect Test signal to component
|
signal mem_rd_addr : std_logic_vector(31 downto 0);
|
signal mem_rd_addr : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
signal mem_wr : std_logic;
|
signal mem_wr : std_logic; --! Wire to connect Test signal to component
|
signal mem_wr_addr : std_logic_vector(31 downto 0);
|
signal mem_wr_addr : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
signal mem_data_out : std_logic_vector(31 downto 0);
|
signal mem_data_out : std_logic_vector(n downto 0); --! Wire to connect Test signal to component
|
|
|
-- Clock period definitions
|
-- Clock period definitions
|
constant clk_period : time := 10 ns;
|
constant clk_period : time := 10 ns;
|
|
|
BEGIN
|
BEGIN
|
|
|
--!Instantiate the Unit Under Test (openCpu) (Doxygen bug if it's not commented!)
|
--! Instantiate the Unit Under Test (openCpu) (Doxygen bug if it's not commented!)
|
uut: openCpu PORT MAP (
|
uut: openCpu PORT MAP (
|
rst => rst,
|
rst => rst,
|
clk => clk,
|
clk => clk,
|
mem_rd => mem_rd,
|
mem_rd => mem_rd,
|
mem_rd_addr => mem_rd_addr,
|
mem_rd_addr => mem_rd_addr,
|
mem_wr => mem_wr,
|
mem_wr => mem_wr,
|
mem_wr_addr => mem_wr_addr,
|
mem_wr_addr => mem_wr_addr,
|
mem_data_in => mem_data_in,
|
mem_data_in => mem_data_in,
|
mem_data_out => mem_data_out
|
mem_data_out => mem_data_out
|
);
|
);
|
|
|
-- Clock process definitions
|
-- Clock process definitions
|
clk_process :process
|
clk_process :process
|
begin
|
begin
|
clk <= '0';
|
clk <= '0';
|
wait for clk_period/2;
|
wait for clk_period/2;
|
clk <= '1';
|
clk <= '1';
|
wait for clk_period/2;
|
wait for clk_period/2;
|
end process;
|
end process;
|
|
|
|
|
-- Stimulus process
|
-- Stimulus process
|
stim_proc: process
|
stim_proc: process
|
begin
|
begin
|
-- Reset operation
|
-- Reset operation
|
REPORT "RESET" SEVERITY NOTE;
|
REPORT "RESET" SEVERITY NOTE;
|
rst <= '1';
|
rst <= '1';
|
wait for 2 ns;
|
wait for 2 ns;
|
rst <= '0';
|
rst <= '0';
|
wait for 2 ns;
|
wait for 2 ns;
|
|
|
wait for clk_period*10;
|
wait for clk_period*10;
|
|
|
-- insert stimulus here
|
-- insert stimulus here
|
|
|
-- Finish simulation
|
-- Finish simulation
|
assert false report "NONE. End of simulation." severity failure;
|
assert false report "NONE. End of simulation." severity failure;
|
wait;
|
wait;
|
end process;
|
end process;
|
|
|
END;
|
END;
|
|
|