CRC16参考代码如下:
/*
*data:每个功能相关寄存器值的首地址;
*size:该功能相关寄存器个数;
*返回值:校验值
*/
UINT32 check_crc16(UINT8 *data, UINT32 size)
{
UINT16 crc = 0x0000;
UINT32 i, j;
UINT32 tmp;
/* Calculate CRC*/
for (i = 0; i < size; i++) {
tmp = data[i] & 0xff;
for (j = 0; j < 8; j++) {
if (((crc & 0x8000) >> 8) ^ (tmp & 0x80))
crc = (crc << 1) ^ 0x8005;
else
crc = crc << 1;
tmp <<= 1;
}
}
printf("REF_CRC CALC CRC 0x%x \n", crc);
return crc;
}