Forum Discussion
4 Replies
- Altera_Forum
Honored Contributor
From scratch not really, but this website has helped me a lot when it comes to CRC's
http://www.easics.com/webtools/crctool. It will generate CRC HDL for pretty much any CRC. - Altera_Forum
Honored 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:
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.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; } - Altera_Forum
Honored 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
Honored 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!