Hi Mr Alpha,
You can read: Understanding and implementing CRC (Cyclic Redundancy Check) calculation
seed also calls initial value
Hope it helps!
Best Regards,
Robin
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi,
Seed and poly depends on CRC type. This routine works for 16 bits CRC-CCITT (0x1021 poly):
unsigned int crc16(const void* buf, size_t len)
{
char oddlen;
union{
unsigned char *c;
unsigned short *s;
unsigned long *l;
}ptr;
PCC->PCCn[PCC_CRC_INDEX] |=PCC_PCCn_CGC_MASK;
CRC->CTRL |= CRC_CTRL_TCRC_MASK;
CRC->GPOLY = 0x10210000; // poly <<16
CRC->CTRL |= CRC_CTRL_WAS_MASK;
CRC->DATAu.DATA = 0x0;
CRC->CTRL &= ~CRC_CTRL_WAS_MASK;
ptr.l = (void*)buf;
oddlen = len & 3;
len /= 4u;
while(len--)
{
CRC->DATAu.DATA = __builtin_bswap32(*ptr.l++);;
}
while(oddlen--)
{
CRC->DATAu.DATA_8.LL = *ptr.c++;
}
return CRC->DATAu.DATA_16.H;
}
Edward