On 16 Mar 2005 21:02:07 -0000, [email protected] wrote:
>Hi all,
>I want to add a sort of checksum in my F1612 to be able to verify the code
>integrity each time it is power-up. I wonder if someone has already
>experience this problem. I'd like to know few things like:
>> 1- Which algorithm you use to obtain good performance without using a too
>> big function code size
<<snip>>
Usually at startup, speed is not that much of an issue, while on an MSP,
flash & RAM space can be. On a previous, large scale project using a
small MSP (1121, IIRC) we used a CCITT CRC calculated bit-wise for
communications packet verification. The code follows.
Regards
-Bill Knight
R O SoftWare
uint16 calcCRC(register uint16 crc,
register const uint8 *ptr,
register uint16 count)
int i;
do
{
i = 8;
crc = crc ^ (uint16)*ptr++ << 8;
do
{
if ((int16)crc < 0) // if (crc & 0x8000)
crc = crc << 1 ^ 0x1021;
else
crc = crc << 1;
}
while (--i);
}
while (--count);
return (crc);