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
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;
}
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