Hi,
I am wishing to use the RM48's CRC module to generate a CRC16 (polynomial 0x1021).
I have software based libraries working well for years, however can not get the hardware CRC module to produce the same results.
Here is my input array and the function call:
Luint8 u8Buffer[] = {0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x01, 0x02}; u16HWCRC = u166RM4_CRC__Calculate_CRC16((const Luint16*)&u8Buffer[0], 8, 0x1021);
Here is my hardware CRC code:
Luint16 u166RM4_CRC__Calculate_CRC16(const Luint16 * pu16Data, Luint32 u32CRCLengthBytes, Luint16 u16CRC_Seed) { Luint32 u32Counter; Luint32 u32LengthWords; union { Luint16 u16[2]; Luint32 u32; }unT; //reset the module crcREG->CTRL0 = 0x00000001U; crcREG->CTRL0 = 0x00000000U; //clear control reg2 and set into full CPU mode crcREG->CTRL2 = 0x00000000U; crcREG->CTRL2 |= CRC_FULL_CPU; //place the seed in the PSA register Low unT.u16[1] = 0; unT.u16[0] = u16CRC_Seed; crcREG->PSA_SIGREGL1 = unT.u32; //write the groups of U16's to the register u32LengthWords = u32CRCLengthBytes >> 1; for(u32Counter = 0; u32Counter < u32LengthWords; u32Counter++) { //update only the lower word of the REGL unT.u16[1] = 0; unT.u16[0] = pu16Data[u32Counter]; crcREG->PSA_SIGREGL1 = unT.u32; } //return with the CRC unT.u32 = crcREG->PSA_SIGREGL1; return (Luint16)unT.u16[0]; }
The result from the CRC across the data array should be 0x6DD2, however I get 0xFEF8. Can anyone please help to show what I am doing wrong?
Note: I am using Full CPU mode for the time being.
Thanks
Stomp.