Files
es-abschlussprojekt/Hardware/axis_crc_16.vhd
T
2025-02-02 05:17:10 +01:00

79 lines
2.4 KiB
VHDL

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity axis_crc is
port (
CLK : in std_logic;
RESETN : in std_logic;
-- for crc calculation
initial_value : in std_logic_vector(31 downto 0);
polynomial : in std_logic_vector(31 downto 0);
-- AXI Streaming Target Port
S_AXIS_TVALID : in std_logic;
S_AXIS_TDATA : in std_logic_vector(16 downto 0);
S_AXIS_TLAST : in std_logic := '0';
S_AXIS_TREADY : out std_logic;
-- AXI Streaming Initiator Port
M_AXIS_TVALID : out std_logic;
M_AXIS_TDATA : out std_logic_vector(16 downto 0);
M_AXIS_TLAST : out std_logic;
M_AXIS_TREADY : in std_logic
);
end entity;
architecture rtl of axis_audio_filter3 is
signal m_valid_sig : std_logic := '0';
begin
S_AXIS_TREADY <= M_AXIS_TREADY or (not m_valid_sig);
process
-- fuer CRC-Berechnung
variable CRC : std_logic_vector(31 downto 0);
variable MSB : std_logic;
variable data : std_logic_vector(31 downto 0);
variable last : std_logic;
begin
wait until rising_edge(AXIS_ACLK);
if RESETN = '0' then
CRC := initial_value;
else
if M_AXIS_TREADY = '1' or m_valid_sig = '0' then
M_AXIS_TVALID <= S_AXIS_TVALID;
if HAS_LAST then
M_AXIS_TLAST <= S_AXIS_TLAST;
end if;
m_valid_sig <= S_AXIS_TVALID;
if S_AXIS_TVALID = '1' then
-- 16 Bit in die CRC Summe reinrechnen
for i in 31 downto 16 loop
-- Pruefen ob MSB gesetzt ist
MSB := CRC(CRC'length-1);
-- neues Bit reinschieben
CRC := CRC(CRC'length-2 downto 0) & data(i);
-- XOR Verknuepfung
if MSB = '1' then
CRC := CRC XOR polynomial;
end if;
end loop;
S_AXIS_TREADY <= '0';
state <= SECOND_HALF;
end if;
M_AXIS_TDATA <= std_logic_vector(res(SHIFT+15 downto SHIFT));
end if;
end if;
end if;
end process;
end;