Using as base the periph_crc example that comes with LPCOpen the following code can be used to calculate the frame check sequence of a HDLC frame using the LPC11E68 CRC:
#define HDLC_FRAME_FCS 0xF0B8 // When correct FCS is included in CRC before the compliment and byte swap.
// Chip_CRC_Use_HDLC()
// Configure the CRC Engine for the CRC used for HDLC FCS.
STATIC INLINE void Chip_CRC_Use_HDLC(void)
{
LPC_CRC->MODE = MODE_CFG_CCITT | CRC_MODE_WRDATA_BIT_RVS | CRC_MODE_SUM_BIT_RVS;
LPC_CRC->SEED = CRC_SEED_CCITT;
}
// HdlcCheckFCS()
// Evaluate the HDLC Frame Check Sequence (CRC).
// pBuffer and length refer to the entire frame including the FCS bytes
// after 7E/7D un-byte-stuffing, but not including the start/stop flags.
// Returns true if valid.
// Returns false if not valid.
uint8_t HdlcCheckFCS(uint8_t *pBuffer, uint8_t length)
{
Chip_CRC_Init();
Chip_CRC_Use_HDLC();
uint8_t index = 0;
uint8_t count = 0;
while(count++ < length)
{
Chip_CRC_Write8(pBuffer[index++]);
}
uint32_t sum = Chip_CRC_Sum();
Chip_CRC_Deinit();
return sum == HDLC_FRAME_FCS;
}
The LPCOpen package can be downloaded from this page:
LPCOpen Software for LPC11XX|NXP
Hope it helps!
Best regards,
Carlos Mendoza