Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

32 bit CRC

Has anyone ever created a 32 bit CRC such as the "Ethernet standard"?

Thanks

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes - 'anyone ever' is a bit open!

    Loosely there are three ways of calculating CRCs:

    1) Bit by bit shift register, this probably uses the least logic, but will be slow.

    2) Byte by byte lookup table (usually 256 entries).

    3) Byte by byte combinational logic.

    For the usual 16bit crc used for hdlc the following C will work:

    static __inline__ uint32_t
    crc_step(uint32_t crc, uint32_t byte_val)
    {
        uint32_t t = crc ^ (byte_val & 0xff);
        t = (t ^ t << 4) & 0xff;
        return crc >> 8 ^ t << 8 ^ t << 3 ^ t >> 4;
    }

    I don't know if the ethernet crc reduces that well. I actually use a custom instruction based on the above.

    The vhdl compiler might manage to optimise a loop to the above, and might do something sensible for the 32bit version - but that might generate a massive amount of logic.

    Possibly a combinatorial version using a 4-bit lookup nested twice might work. The fewer bits you need to process at once the better.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The other huge problem that goes along with this is that I have to compare it with a CRC checksum generated with matlab and loaded at the end of the written data. I need to read this out and ensure that it is the same as the HDL generated CRC.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Generally you CRC the whole block (including the generated CRC) and then check for a specific pattern.

    This does require the CRC to be written with the correct bit order though.

    Also, CRC algorithms tend to either work, or be very badly wrong!