CRC-16 Component
Posted: Sun Aug 20, 2023 12:33 pm
The current project I'm currently working on needs a CRC-16 calculating for a block of data.
Given the polynomial (0x8005 in my case) - who knew that there was such a wide range of possible CRC calculations possible. For the given polynomial there were several possible CRC 'functions' possible - and my first attempt gave the wrong result.
So - I wrote a small component - this allows the user to set the polynomial, initial CRC, whether it is 'reversed' (refIn and refOut = true - note this only supports refin == refout) and a final value to XOR the result with. I've tested a range of values against https://crccalc.com/ - and seems to work correctly (more testing please ~:-) )
The initialise macro generates the lookup table for the given polynomial.
It would be possible to extend to CRC-32 if anyone needs this?
There is also a very simple test program - run in simulation - that generates the CRC for a small (5 byte) block of data.
It only supports data blocks up to 255 bytes - this could be extended if needed?
Martin
Given the polynomial (0x8005 in my case) - who knew that there was such a wide range of possible CRC calculations possible. For the given polynomial there were several possible CRC 'functions' possible - and my first attempt gave the wrong result.
So - I wrote a small component - this allows the user to set the polynomial, initial CRC, whether it is 'reversed' (refIn and refOut = true - note this only supports refin == refout) and a final value to XOR the result with. I've tested a range of values against https://crccalc.com/ - and seems to work correctly (more testing please ~:-) )
The initialise macro generates the lookup table for the given polynomial.
It would be possible to extend to CRC-32 if anyone needs this?
There is also a very simple test program - run in simulation - that generates the CRC for a small (5 byte) block of data.
It only supports data blocks up to 255 bytes - this could be extended if needed?
Martin