1 ------------------------------------------------------------------------------- 3 --! @brief SPI Slave testbench module 4 ------------------------------------------------------------------------------- 9 --! Using IEEE standard logic components 10 USE ieee.std_logic_1164.
ALL;
12 --! @brief SPI Slave testbench module 14 END ENTITY spi_slave_tb;
16 --! Architecture tb of spi_slave_tb entity 22 -- Signals to unit under test 23 SIGNAL clk : ;
--! Clock 24 SIGNAL rst : ;
--! Asynchronous reset 25 SIGNAL spi_cs : ;
--! SPI chip select input to uut 28 SIGNAL spi_miso : ;
--! SPI MISO output from uut 29 SIGNAL dat_rd_reg : (31 DOWNTO 0);
--! Data read register input to uut 30 SIGNAL dat_wr_reg : (31 DOWNTO 0);
--! Data write register output from uut 34 SIGNAL mosi_wr : (31 DOWNTO 0);
--! SPI MOSI test pattern to drive into uut 35 SIGNAL miso_rd : (31 DOWNTO 0);
--! SPI MISO output pattern driven from uut 39 --! Instantiate spi_slave as unit under test 56 --! @brief Clock generation process 70 --! @brief Stimulus process 71 pr_stimulus :
PROCESS IS 75 spi_cs <= '1';
-- CS: high-idle 80 REPORT "Hold in Reset" SEVERITY note;
83 ASSERT (spi_miso = '0') REPORT "Expected spi_miso low while in reset" SEVERITY error;
84 ASSERT (dat_wr_done = '0') REPORT "Expected dat_wr_done low while in reset" SEVERITY error;
86 -- Release reset for 5 clocks 87 REPORT "Take out of Reset" SEVERITY note;
90 ASSERT (spi_miso = '0') REPORT "Expected spi_miso low while idle" SEVERITY error;
91 ASSERT (dat_wr_done = '0') REPORT "Expected dat_wr_done low while idle" SEVERITY error;
93 -- Provide test pattern 98 REPORT "Start SPI Transfer" SEVERITY note;
102 -- Wait for 5 clocks (CS-to-Start) 106 REPORT "Transfer 32 Bits" SEVERITY note;
107 FOR i IN 31 DOWNTO 0 LOOP 108 -- Drive data and first edge 113 -- Capture data and drive second edge 119 -- Wait for 5 clocks (End-to-CS) 123 REPORT "End SPI Transfer" SEVERITY note;
126 ASSERT (dat_wr_done = '1') REPORT "Expected dat_wr_done high for transfer done" SEVERITY error;
128 -- Wait for 10 clocks 130 ASSERT (dat_wr_done = '0') REPORT "Expected dat_wr_done low after transfer done" SEVERITY error;
132 -- Verify test patterns 133 REPORT "Test Transfer Data" SEVERITY note;
134 ASSERT (dat_wr_reg = mosi_wr) REPORT "Expected dat_wr_reg matches mosi_wr" SEVERITY error;
135 ASSERT (miso_rd = dat_rd_reg) REPORT "Expected miso_rd matches dat_rd_reg" SEVERITY error;
138 REPORT "Finished" SEVERITY note;
140 -- Finish the simulation 143 END PROCESS pr_stimulus;
std_logic_vector( 31 DOWNTO 0) dat_wr_reg
Data write register output from uut.
std_logic_vector( 31 DOWNTO 0) miso_rd
SPI MISO output pattern driven from uut.
in spi_mosi_instd_logic
SPI MOSI.
std_logic spi_mosi
SPI MOSI input to uut.
std_logic dat_wr_done
Data write done output from uut.
out spi_miso_outstd_logic
SPI MISO.
in clk_instd_logic
Clock.
time := 100 ns c_clk_period
Clock period.
in spi_sclk_instd_logic
SPI Clock.
std_logic spi_cs
SPI chip select input to uut.
in dat_rd_reg_instd_logic_vector( size- 1 DOWNTO 0)
Data Read Register value.
std_logic_vector( 31 DOWNTO 0) dat_rd_reg
Data read register input to uut.
std_logic spi_sclk
SPI clock input to uut.
SPI Slave testbench module.
sizenatural range 1 TO natural'high
Size of the SPI data.
out dat_wr_done_outstd_logic
Data Write Done flag.
std_logic rst
Asynchronous reset.
_library_ ieeeieee
Using IEEE library.
in rst_instd_logic
Asynchronous reset.
std_logic_vector( 31 DOWNTO 0) mosi_wr
SPI MOSI test pattern to drive into uut.
in spi_cs_instd_logic
SPI Chip-select.
out dat_wr_reg_outstd_logic_vector( size- 1 DOWNTO 0)
Data Write Register value.
std_logic spi_miso
SPI MISO output from uut.