Hi All,
I am using the CRC block in the TMS470M to provide a CRC of flash memory contents to prove code integrity. I am, as part of the programming sequence, calculating, and inserting the known CRC of the code into the hex file to be downloaded.
Has anyone any experience with a suitable algorithm to calculate the CRC? I have written the following C# routine to calculate the CRC (based on a C example from this forum) but I do not get the correct results when compared to the CRC block in the processor, with the same data. Can anyone offer any suggestions? have I made a really simple mistake?
thanks,
Phil
static UInt64 crc = 0;
static UInt64 calc_crc(UInt64 data)
{
UInt64 nextCrc = 0;
for (int i = 63; i >= 0; i--)
{
nextCrc = (nextCrc & 0xfffffffffffffffe) | ((crc >> 63) ^ (data >> i));
for (int j = 1; j < 64; j++)
{
if (j == 1 || j == 3 || j == 4)
{
nextCrc = (nextCrc & ~(1ul << j) ) | ( ( ( (crc >> (j - 1) ) ^ (crc >> 63) ^ (data >> i) ) & 1ul) << j);
}
else
{ // when others =>
nextCrc = (nextCrc & ~(1ul << j)) | (((crc >> (j - 1)) & 1ul) << j);
}
} // end loop;
crc = nextCrc;
} // end loop
Console.WriteLine(crc.ToString("x8"));
return crc;
}