Line 12... |
Line 12... |
use work.pp_utilities.all;
|
use work.pp_utilities.all;
|
|
|
--! @brief Testbench providing a full SoC architecture connected with a Wishbone bus.
|
--! @brief Testbench providing a full SoC architecture connected with a Wishbone bus.
|
entity tb_soc is
|
entity tb_soc is
|
generic(
|
generic(
|
IMEM_SIZE : natural := 2048; --! Size of the instruction memory in bytes.
|
IMEM_SIZE : natural := 4096; --! Size of the instruction memory in bytes.
|
DMEM_SIZE : natural := 2048; --! Size of the data memory in bytes.
|
DMEM_SIZE : natural := 4096; --! Size of the data memory in bytes.
|
|
RESET_ADDRESS : std_logic_vector := x"00000200"; --! Processor reset address
|
|
IMEM_START_ADDR : std_logic_vector := x"00000100"; --! Instruction memory start address
|
IMEM_FILENAME : string := "imem_testfile.hex"; --! File containing the contents of instruction memory.
|
IMEM_FILENAME : string := "imem_testfile.hex"; --! File containing the contents of instruction memory.
|
DMEM_FILENAME : string := "dmem_testfile.hex" --! File containing the contents of data memory.
|
DMEM_FILENAME : string := "dmem_testfile.hex" --! File containing the contents of data memory.
|
);
|
);
|
end entity tb_soc;
|
end entity tb_soc;
|
|
|
Line 25... |
Line 27... |
|
|
-- Clock signals:
|
-- Clock signals:
|
signal clk : std_logic;
|
signal clk : std_logic;
|
constant clk_period : time := 10 ns;
|
constant clk_period : time := 10 ns;
|
|
|
|
signal timer_clk : std_logic;
|
|
constant timer_clk_period : time := 100 ns;
|
|
|
-- Reset:
|
-- Reset:
|
signal reset : std_logic := '1';
|
signal reset : std_logic := '1';
|
|
|
-- Interrupts:
|
-- Interrupts:
|
signal irq : std_logic_vector(7 downto 0) := (others => '0');
|
signal irq : std_logic_vector(7 downto 0) := (others => '0');
|
Line 91... |
Line 96... |
signal simulation_finished : boolean := false;
|
signal simulation_finished : boolean := false;
|
|
|
begin
|
begin
|
|
|
processor: entity work.pp_potato
|
processor: entity work.pp_potato
|
port map(
|
generic map(
|
|
RESET_ADDRESS => RESET_ADDRESS
|
|
) port map(
|
clk => clk,
|
clk => clk,
|
reset => processor_reset,
|
reset => processor_reset,
|
|
timer_clk => timer_clk,
|
irq => irq,
|
irq => irq,
|
fromhost_data => fromhost_data,
|
fromhost_data => fromhost_data,
|
fromhost_updated => fromhost_updated,
|
fromhost_updated => fromhost_updated,
|
tohost_data => tohost_data,
|
tohost_data => tohost_data,
|
tohost_updated => tohost_updated,
|
tohost_updated => tohost_updated,
|
Line 198... |
Line 206... |
variable input_line : line;
|
variable input_line : line;
|
variable input_index : natural;
|
variable input_index : natural;
|
variable input_value : std_logic_vector(31 downto 0);
|
variable input_value : std_logic_vector(31 downto 0);
|
variable temp : std_logic_vector(31 downto 0);
|
variable temp : std_logic_vector(31 downto 0);
|
|
|
constant DMEM_START : natural := IMEM_SIZE;
|
constant DMEM_START_ADDR : natural := IMEM_SIZE;
|
begin
|
begin
|
if not initialized then
|
if not initialized then
|
-- Read the instruction memory file:
|
-- Read the instruction memory file:
|
for i in 0 to IMEM_SIZE loop
|
for i in 0 to (IMEM_SIZE / 4) - 1 loop
|
exit when endfile(imem_file);
|
exit when endfile(imem_file);
|
|
|
readline(imem_file, input_line);
|
readline(imem_file, input_line);
|
hread(input_line, input_value);
|
hread(input_line, input_value);
|
|
|
init_adr_out <= std_logic_vector(to_unsigned(i * 4, init_adr_out'length));
|
init_adr_out <= std_logic_vector(to_unsigned(to_integer(unsigned(IMEM_START_ADDR)) + (i * 4),
|
|
init_adr_out'length));
|
init_dat_out <= input_value;
|
init_dat_out <= input_value;
|
init_cyc_out <= '1';
|
init_cyc_out <= '1';
|
init_stb_out <= '1';
|
init_stb_out <= '1';
|
wait until imem_ack_out = '1';
|
wait until imem_ack_out = '1';
|
wait for clk_period;
|
wait for clk_period;
|
Line 224... |
Line 233... |
init_cyc_out <= '0';
|
init_cyc_out <= '0';
|
init_stb_out <= '0';
|
init_stb_out <= '0';
|
wait for clk_period;
|
wait for clk_period;
|
|
|
-- Read the data memory file:
|
-- Read the data memory file:
|
for i in 0 to DMEM_SIZE loop
|
for i in 0 to (DMEM_SIZE / 4) - 1 loop
|
exit when endfile(dmem_file);
|
exit when endfile(dmem_file);
|
|
|
readline(dmem_file, input_line);
|
readline(dmem_file, input_line);
|
hread(input_line, input_value);
|
hread(input_line, input_value);
|
|
|
|
|
-- Swap endianness, TODO: prevent this, fix scripts/extract_hex.sh
|
-- Swap endianness, TODO: prevent this, fix scripts/extract_hex.sh
|
temp(7 downto 0) := input_value(31 downto 24);
|
temp(7 downto 0) := input_value(31 downto 24);
|
temp(15 downto 8) := input_value(23 downto 16);
|
temp(15 downto 8) := input_value(23 downto 16);
|
temp(23 downto 16) := input_value(15 downto 8);
|
temp(23 downto 16) := input_value(15 downto 8);
|
temp(31 downto 24) := input_value(7 downto 0);
|
temp(31 downto 24) := input_value(7 downto 0);
|
|
|
input_value := temp;
|
input_value := temp;
|
|
|
init_adr_out <= std_logic_vector(to_unsigned(DMEM_START + (i * 4), init_adr_out'length));
|
init_adr_out <= std_logic_vector(to_unsigned(DMEM_START_ADDR + (i * 4), init_adr_out'length));
|
init_dat_out <= input_value;
|
init_dat_out <= input_value;
|
init_cyc_out <= '1';
|
init_cyc_out <= '1';
|
init_stb_out <= '1';
|
init_stb_out <= '1';
|
wait until dmem_ack_out = '1';
|
wait until dmem_ack_out = '1';
|
wait for clk_period;
|
wait for clk_period;
|
Line 271... |
Line 279... |
if simulation_finished then
|
if simulation_finished then
|
wait;
|
wait;
|
end if;
|
end if;
|
end process clock;
|
end process clock;
|
|
|
|
timer_clock: process
|
|
begin
|
|
timer_clk <= '1';
|
|
wait for timer_clk_period / 2;
|
|
timer_clk <= '0';
|
|
wait for timer_clk_period / 2;
|
|
|
|
if simulation_finished then
|
|
wait;
|
|
end if;
|
|
end process timer_clock;
|
|
|
stimulus: process
|
stimulus: process
|
begin
|
begin
|
wait for clk_period * 2;
|
wait for clk_period * 2;
|
reset <= '0';
|
reset <= '0';
|
|
|