Here you go, The first code is a CRC checker in VHDL the second is a psudo
random
packet generator with a CRC append. You can just use the part that
calculates teh FCS/CRC
i think it is clearly marked.
-----------------------------------------------------------------------
-- Code Starts here ---------------------------------------------------
-----------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE ieee.std_logic_unsigned.ALL;
ENTITY prp_recieve IS
PORT (
t_clk : IN std_logic;
Reset_n : IN std_logic;
TxDataValid : IN std_logic;
QuadRxData : IN std_logic_vector(3 DOWNTO 0));
SIGNAL BadPacketReg : std_logic_vector(20 DOWNTO 0);
SIGNAL PacketCntReg : std_logic_vector(20 DOWNTO 0);
BEGIN
QuadPumpPrpsRx: PROCESS (t_clk, Reset_n)
VARIABLE QuadCRCReg : std_logic_vector(31 DOWNTO 0);
VARIABLE XorEnCRC : std_logic_vector(31 DOWNTO 1);
BEGIN
IF Reset_n = '0' THEN
QuadCRCReg := (OTHERS => '1');
XorEnCRC := (OTHERS => QuadCRCReg(31));
BadPacketReg <= (OTHERS => '0');
PacketCntReg <= (OTHERS => '0');
ELSIF t_clk'event AND t_clk = '1' THEN
CASE PRPRec_State IS
WHEN Idle =>
QuadCRCReg := (OTHERS => '1');
IF TxDataValid = '1' AND QuadRxData = x"D" THEN
PRPRec_State <= CRC_Calc;
END IF;
WHEN CRC_Calc =>
IF TxDataValid = '1' THEN
-- Calculate the CRC for bit 0
XorEnCRC := (OTHERS => (QuadRxData(0) XOR QuadCRCReg(31)));
QuadCRCReg := (QuadCRCReg(30 DOWNTO 0) XOR
(CRCPoly(31 DOWNTO 1) AND XorEnCRC))
& (QuadRxData(0) XOR QuadCRCReg(31));
-- Calculate the CRC for bit 1
XorEnCRC := (OTHERS => (QuadRxData(1) XOR QuadCRCReg(31)));
QuadCRCReg := (QuadCRCReg(30 DOWNTO 0) XOR
(CRCPoly(31 DOWNTO 1) AND XorEnCRC))
& (QuadRxData(1) XOR QuadCRCReg(31));
-- Calculate the CRC for bit 2
XorEnCRC := (OTHERS => (QuadRxData(2) XOR QuadCRCReg(31)));
QuadCRCReg := (QuadCRCReg(30 DOWNTO 0) XOR
(CRCPoly(31 DOWNTO 1) AND XorEnCRC))
& (QuadRxData(2) XOR QuadCRCReg(31));
-- Calculate the CRC for bit 3
XorEnCRC := (OTHERS => (QuadRxData(3) XOR QuadCRCReg(31)));
QuadCRCReg := (QuadCRCReg(30 DOWNTO 0) XOR
(CRCPoly(31 DOWNTO 1) AND XorEnCRC))
& (QuadRxData(3) XOR QuadCRCReg(31));
ELSE
IF QuadCRCReg /= MagicNum THEN
BadPacketReg <= BadPacketReg + '1';
END IF;
PacketCntReg <= PacketCntReg + '1';
PRPRec_State <= Idle;
END IF;
WHEN OTHERS => NULL;
END CASE;
END IF;
END PROCESS QuadPumpPrpsRx;
END behav;
----------------------------------------------------------------------------
--
-- End of Code
----------------------------------------------------------------------------
--
-----------------------------------------------------------------------
-- Code Starts here ---------------------------------------------------
-----------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL;
USE ieee.std_logic_arith.ALL;
ENTITY prp_generate IS
PORT (
m_clk : IN std_logic;
Reset_n : IN std_logic;
Tx_Packet : IN std_logic;
Rx_Data_Valid : OUT std_logic;
QuadTxData : OUT std_logic_vector(3 DOWNTO 0));
-- Pump the PRPS Generator once to randomize the bits
XorEnTx := (OTHERS => QuadSftRegTx(15));
QuadSftRegTx := (QuadSftRegTx(14 DOWNTO 0) XOR
(PRPSPoly(15 DOWNTO 1) AND XorEnTx))
& QuadSftRegTx(15);
END IF;
-----------------------------------------------------------------------
-- ************** Time Delay **************
-----------------------------------------------------------------------
WHEN Time_Delay =>
IF TimeDelay_Reg /= 0 THEN
TimeDelay_Reg <= TimeDelay_Reg - '1';
ELSE
PRPGen_State <= Premble_Gen;
PacketLength_Reg <= QuadSftRegTx(15 DOWNTO 7) & '0';
--PacketLength_Reg <= "0010000000";
-- Pump the PRPS Generator once to randomize the bits
XorEnTx := (OTHERS => QuadSftRegTx(15));
QuadSftRegTx := (QuadSftRegTx(14 DOWNTO 0) XOR
(PRPSPoly(15 DOWNTO 1) AND XorEnTx))
& QuadSftRegTx(15);
END IF;
-----------------------------------------------------------------------
-- ************ Premble Gen *************
-----------------------------------------------------------------------
WHEN Premble_Gen =>
Rx_Data_Valid <= '1';
IF PrembleLength /= 1 THEN
PrembleLength <= PrembleLength - '1';
QuadTxData <= "0101";
ELSE
QuadTxData <= "1101";
PrembleLength <= "1111";
PRPGen_State <= Data_Gen;
END IF;
-----------------------------------------------------------------------
-- ************** Data Gen **************
-----------------------------------------------------------------------
WHEN Data_Gen =>
IF PacketLength_Reg /= 0 THEN
PacketLength_Reg <= PacketLength_Reg - '1';
------------------------------------------------------------------
-- This will do 4 calculations of Prbs data in one clock.
-- The MAC Core wants bit 0 first
-------------------------------------------------------------------
-- Now append FCS/CRC
-------------------------------------------------------------------
ELSIF FCSApndCnt /= 0 THEN
QuadTxData(0) <= NOT QuadCRCReg((FCSApndCnt*4-1));
QuadTxData(1) <= NOT QuadCRCReg((FCSApndCnt*4-2));
QuadTxData(2) <= NOT QuadCRCReg((FCSApndCnt*4-3));
QuadTxData(3) <= NOT QuadCRCReg((FCSApndCnt*4-4));
FCSApndCnt <= FCSApndCnt - 1;
ELSE
FCSApndCnt <= 8;
PRPGen_State <= Idle;
Rx_Data_Valid <= '0';
--PacketTxCnt <= PacketTxCnt + 1;
END IF;
WHEN OTHERS => NULL;
END CASE;
END IF;
END PROCESS QuadPumpPrbsTx;
END behav;
----------------------------------------------------------------------------
--
-- End of Code
----------------------------------------------------------------------------
--
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.