
APPENDIX
Download Protocol
140
2.10
•
19.01.2007
5.5.3 Computation of CRC
The following short piece of C-code describes the computation of a CRC for a block of bytes
to be applied for firmware download:
unsigned short CalculateCRC (
unsigned char *Block,
/* array of bytes */
unsigned int BlockLen
/* length of Block in bytes */
)
{
unsigned short crc = 0; /* CRC initialised with zero */
unsigned char BitPos;
/* counter for bit level loop */
while (BlockLen != 0)
/* main loop over all bytes */
{
crc ^= ( (unsigned short) *Block++ << 8)
/* modulo-2 add a byte */
for (BitPos=0; BitPos<8; +)
/* loop over all bits of byte */
{
if (crc & 0x8000)
crc = (crc << 1) ^ 0x1021
else
crc <<= 1;
/* apply generator polynomial */
}
BlockLen--;
/* decrement loop counter */
}
return crc
}