#include "crc.h"
#include <stdint.h>
//------------------------------------------------------------------------------------------------
-------
// uint16 crcCalc(uint16 crcReg, uint8 crcData)
//
// DESCRIPTION:
// Calculates the 16-bit CRC. The function requires that the CRC_POLYNOM
// is defined, which gives the wanted CRC polynom.
//
// ARGUMENTS:
// uint8 crcData - Data to perform the CRC-16 operation on.
// uint16 crcReg - Current or initial value of the CRC calculation
//
// RETURN:
// The value returned is the 16-bit CRC (of the data supplied so far).
//------------------------------------------------------------------------------------------------
-------
uint16_t crcCalc(uint16_t crcReg, uint8_t crcData)
{
uint8_t i;
for (i = 0; i < 8; i++)
{
// If upper most bit is 1
if (((crcReg & 0x8000) >> 8) ^ (crcData & 0x80))
crcReg = (crcReg << 1) ^ CRC_POLYNOM;
else
crcReg = (crcReg << 1);
crcData <<= 1;
}
return crcReg;
}
// CRC_POLYNOM 0x3D65
|