133 lines
4.0 KiB
VHDL
133 lines
4.0 KiB
VHDL
library ieee;
|
|
use ieee.std_logic_1164.all;
|
|
use ieee.numeric_std.all;
|
|
|
|
entity axis_crc_tb is
|
|
end entity;
|
|
|
|
architecture testbench of axis_crc_tb is
|
|
|
|
-- Signal Definitions
|
|
signal CLK : std_logic := '0';
|
|
signal RESETN : std_logic := '0';
|
|
|
|
signal initial_value : std_logic_vector(31 downto 0) := x"00000000";
|
|
signal polynomial : std_logic_vector(31 downto 0) := x"04C11DB7"; -- Standard CRC-32 Poly
|
|
|
|
-- AXIS Input Signals (Stimulus)
|
|
signal S_AXIS_TVALID : std_logic := '0';
|
|
signal S_AXIS_TDATA : std_logic_vector(31 downto 0) := (others => '0');
|
|
signal S_AXIS_TLAST : std_logic := '0';
|
|
signal S_AXIS_TREADY : std_logic;
|
|
|
|
-- AXIS Output Signals (DUT Response)
|
|
signal M_AXIS_TVALID : std_logic;
|
|
signal M_AXIS_TDATA : std_logic_vector(31 downto 0);
|
|
signal M_AXIS_TLAST : std_logic;
|
|
signal M_AXIS_TREADY : std_logic := '1';
|
|
|
|
-- Clock Process (100 MHz)
|
|
constant CLK_PERIOD : time := 10 ns;
|
|
signal done : boolean := false;
|
|
|
|
type data_array is array (natural range <>) of std_logic_vector(31 downto 0);
|
|
constant test_data : data_array := (
|
|
x"11223344", -- Test Value 1
|
|
x"55667788" -- Test Value 2
|
|
-- x"AABBCCDD", -- Test Value 3
|
|
-- x"11223344" -- Test Value 4
|
|
);
|
|
|
|
|
|
|
|
begin
|
|
|
|
-- DUT Instantiation
|
|
uut: entity work.axis_crc
|
|
port map (
|
|
CLK => CLK,
|
|
RESETN => RESETN,
|
|
initial_value => initial_value,
|
|
polynomial => polynomial,
|
|
|
|
-- AXI Streaming Target (Input)
|
|
S_AXIS_TVALID => S_AXIS_TVALID,
|
|
S_AXIS_TDATA => S_AXIS_TDATA,
|
|
S_AXIS_TLAST => S_AXIS_TLAST,
|
|
S_AXIS_TREADY => S_AXIS_TREADY,
|
|
|
|
-- AXI Streaming Initiator (Output)
|
|
M_AXIS_TVALID => M_AXIS_TVALID,
|
|
M_AXIS_TDATA => M_AXIS_TDATA,
|
|
M_AXIS_TLAST => M_AXIS_TLAST,
|
|
M_AXIS_TREADY => M_AXIS_TREADY
|
|
);
|
|
|
|
-- Clock Process
|
|
clk_process : process
|
|
begin
|
|
while not done loop
|
|
CLK <= '0';
|
|
wait for CLK_PERIOD / 2;
|
|
CLK <= '1';
|
|
wait for CLK_PERIOD / 2;
|
|
end loop;
|
|
wait;
|
|
end process;
|
|
|
|
-- Test Process
|
|
test_process : process
|
|
|
|
variable received_crc : std_logic_vector(31 downto 0);
|
|
|
|
begin
|
|
-- Reset Sequence
|
|
RESETN <= '0';
|
|
wait for 50 ns;
|
|
RESETN <= '1';
|
|
wait for 50 ns;
|
|
|
|
-- Send Data over S_AXIS
|
|
for i in test_data'range loop
|
|
S_AXIS_TDATA <= test_data(i);
|
|
S_AXIS_TVALID <= '1';
|
|
S_AXIS_TLAST <= '0';
|
|
wait until rising_edge(CLK) and S_AXIS_TREADY = '1';
|
|
S_AXIS_TVALID <= '0';
|
|
end loop;
|
|
|
|
-- Send TLAST with Last Data
|
|
S_AXIS_TDATA <= test_data(3);
|
|
S_AXIS_TVALID <= '1';
|
|
S_AXIS_TLAST <= '1';
|
|
wait until rising_edge(CLK) and S_AXIS_TREADY = '1';
|
|
S_AXIS_TVALID <= '0';
|
|
S_AXIS_TLAST <= '0';
|
|
|
|
-- Wait for M_AXIS Data
|
|
for i in test_data'range loop
|
|
wait until rising_edge(CLK) and M_AXIS_TVALID = '1';
|
|
assert M_AXIS_DATA = test_data(i) report "ERROR: Mismatched Data at index " & integer'image(i) severity failure;
|
|
end loop;
|
|
|
|
-- Wait for CRC
|
|
wait until rising_edge(CLK) and M_AXIS_TVALID = '1' and M_AXIS_TLAST = '1';
|
|
received_crc := M_AXIS_TDATA;
|
|
|
|
-- Check Data
|
|
for i in 0 to 3 loop
|
|
assert received_data(i) = test_data(i)
|
|
report "ERROR: Mismatched Data at index " & integer'image(i)
|
|
severity failure;
|
|
end loop;
|
|
|
|
-- Print Results
|
|
report "All data matches expected values!";
|
|
report "Received CRC: " & integer'image(to_integer(unsigned(received_crc)));
|
|
|
|
done <= true;
|
|
wait;
|
|
end process;
|
|
|
|
end architecture;
|