mor1kx-bemicrocv/bench/bench_flashrom_controller.vhd

160 lines
4.2 KiB
VHDL
Raw Permalink Normal View History

2016-08-04 19:22:38 +02:00
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
library design;
use design.all;
use design.flashrom_pkg.all;
entity bench_flashrom_controller is
end entity bench_flashrom_controller;
architecture rtl of bench_flashrom_controller is
signal clk : std_logic;
signal rst : std_logic;
procedure waitclk is
begin
wait until rising_edge(clk);
end procedure waitclk;
procedure waitnclk(n : integer) is
begin
for i in 1 to n loop
wait until rising_edge(clk);
end loop;
end procedure waitnclk;
procedure strobe(signal s : out std_logic) is
begin
s <= '1';
waitclk;
s <= '0';
waitclk;
end procedure strobe;
signal clr : std_logic;
signal ready : std_logic;
2016-12-10 20:48:43 +01:00
signal page : std_logic_vector(FLASHROM_PAGE_ADDR_WIDTH - 1 downto 0);
2016-08-04 19:22:38 +02:00
signal sync_stb : std_logic;
signal load_stb : std_logic;
signal status_update_stb : std_logic;
2016-12-04 18:00:31 +01:00
signal status : std_logic_vector(7 downto 0);
2016-08-04 19:22:38 +02:00
signal info : std_logic_vector(31 downto 0);
signal data_in : std_logic_vector(7 downto 0) := x"00";
signal data_in_next : std_logic;
2016-08-04 19:22:38 +02:00
signal data_out : std_logic_vector(7 downto 0);
signal data_out_valid : std_logic;
signal spi_si : std_logic;
signal spi_so : std_logic;
signal spi_sck : std_logic;
signal spi_reset_n : std_logic;
signal spi_cs_n : std_logic;
signal spi_wp_n : std_logic;
signal spi_busy : std_logic;
signal spi_clk_cnt : integer := 0;
2016-08-04 19:22:38 +02:00
begin
DataFlash_inst : entity work.DataFlash
generic map(
flashmemory => "devicemodels/memory.txt",
Rapid_interface => true,
fsck => 66,
2016-12-04 18:00:31 +01:00
DEVICE => "AT45DB011D", --AT45DB011D
Tsck => 13.6 ns)
port map(
SI => spi_si,
CSB => spi_cs_n,
SCK => spi_sck,
WPB => spi_wp_n,
RESETB => spi_reset_n,
SO => spi_so,
RDYBSY => spi_busy
);
2016-08-04 19:22:38 +02:00
flashrom_controller_inst : entity design.flashrom_controller
port map(
clk => clk,
rst => rst,
clr => clr,
ready => ready,
page => page,
sync_stb => sync_stb,
load_stb => load_stb,
status_update_stb => status_update_stb,
status => status,
info => info,
data_in => data_in,
data_in_next => data_in_next,
2016-08-04 19:22:38 +02:00
data_out => data_out,
data_out_valid => data_out_valid,
spi_si => spi_si,
spi_so => spi_so,
spi_sck => spi_sck,
spi_reset_n => spi_reset_n,
spi_cs_n => spi_cs_n,
spi_wp_n => spi_wp_n
);
-- clock driver
clock_driver : process
constant PERIOD : time := 10 ns;
begin
clk <= '0';
wait for PERIOD / 2;
clk <= '1';
wait for PERIOD / 2;
end process clock_driver;
--testbench
bench : process is
begin
2016-12-05 20:37:04 +01:00
rst <= '1';
clr <= '0';
status_update_stb <= '0';
load_stb <= '0';
page <= (others => '0');
2016-08-04 19:22:38 +02:00
wait for 10 ns * 2;
wait until (rising_edge(clk));
rst <= '0';
wait for 10 ns * 2;
wait until (rising_edge(clk));
-- bench code here
2016-12-04 18:00:31 +01:00
wait until ready = '1';
2016-12-05 20:37:04 +01:00
strobe(status_update_stb);
wait until ready = '1';
strobe(status_update_stb);
2016-12-04 18:27:58 +01:00
2016-12-04 18:00:31 +01:00
wait until ready = '1';
wait for 100 us;
strobe(sync_stb); -- Make sure background_op_enable is '1' in device model (power up delay)
2016-12-04 18:27:58 +01:00
2016-12-04 18:00:31 +01:00
wait until ready = '1';
strobe(status_update_stb);
2016-12-04 18:27:58 +01:00
wait until ready = '1';
wait until spi_busy = '1';
wait for 100 us;
2016-12-04 18:27:58 +01:00
strobe(status_update_stb);
wait until ready = '1';
strobe(load_stb);
2016-12-05 20:37:04 +01:00
2016-08-04 19:22:38 +02:00
wait;
end process bench;
2016-12-04 18:00:31 +01:00
spiclkcounter : process is
begin
wait until data_out_valid = '1';
2016-12-04 18:00:31 +01:00
spi_clk_cnt <= spi_clk_cnt + 1;
end process spiclkcounter;
data_provider : process is
begin
wait until data_in_next = '1';
--wait until data_in_next = '1';
data_in <= std_logic_vector(unsigned(data_in) + 1);
end process data_provider;
2016-08-04 19:22:38 +02:00
end architecture rtl;