📄 fastcrc8.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** CUL - fastcrc *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* *
*****************************************************************************
* Author: JOL *
*****************************************************************************
* Revision history: *
* *
* $Log: fastcrc8.c,v $
* Revision 1.1 2002/10/14 12:26:12 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/cul.h>
//----------------------------------------------------------------------------
// CRC-8 LUT
// newCRC = crc8LUT[dataByte ^ oldCRC]
//----------------------------------------------------------------------------
byte code crc8LUT[256] = {
0x00, 0x18, 0x30, 0x28, 0x60, 0x78, 0x50, 0x48,
0xC0, 0xD8, 0xF0, 0xE8, 0xA0, 0xB8, 0x90, 0x88,
0x98, 0x80, 0xA8, 0xB0, 0xF8, 0xE0, 0xC8, 0xD0,
0x58, 0x40, 0x68, 0x70, 0x38, 0x20, 0x08, 0x10,
0x28, 0x30, 0x18, 0x00, 0x48, 0x50, 0x78, 0x60,
0xE8, 0xF0, 0xD8, 0xC0, 0x88, 0x90, 0xB8, 0xA0,
0xB0, 0xA8, 0x80, 0x98, 0xD0, 0xC8, 0xE0, 0xF8,
0x70, 0x68, 0x40, 0x58, 0x10, 0x08, 0x20, 0x38,
0x50, 0x48, 0x60, 0x78, 0x30, 0x28, 0x00, 0x18,
0x90, 0x88, 0xA0, 0xB8, 0xF0, 0xE8, 0xC0, 0xD8,
0xC8, 0xD0, 0xF8, 0xE0, 0xA8, 0xB0, 0x98, 0x80,
0x08, 0x10, 0x38, 0x20, 0x68, 0x70, 0x58, 0x40,
0x78, 0x60, 0x48, 0x50, 0x18, 0x00, 0x28, 0x30,
0xB8, 0xA0, 0x88, 0x90, 0xD8, 0xC0, 0xE8, 0xF0,
0xE0, 0xF8, 0xD0, 0xC8, 0x80, 0x98, 0xB0, 0xA8,
0x20, 0x38, 0x10, 0x08, 0x40, 0x58, 0x70, 0x68,
0xA0, 0xB8, 0x90, 0x88, 0xC0, 0xD8, 0xF0, 0xE8,
0x60, 0x78, 0x50, 0x48, 0x00, 0x18, 0x30, 0x28,
0x38, 0x20, 0x08, 0x10, 0x58, 0x40, 0x68, 0x70,
0xF8, 0xE0, 0xC8, 0xD0, 0x98, 0x80, 0xA8, 0xB0,
0x88, 0x90, 0xB8, 0xA0, 0xE8, 0xF0, 0xD8, 0xC0,
0x48, 0x50, 0x78, 0x60, 0x28, 0x30, 0x18, 0x00,
0x10, 0x08, 0x20, 0x38, 0x70, 0x68, 0x40, 0x58,
0xD0, 0xC8, 0xE0, 0xF8, 0xB0, 0xA8, 0x80, 0x98,
0xF0, 0xE8, 0xC0, 0xD8, 0x90, 0x88, 0xA0, 0xB8,
0x30, 0x28, 0x00, 0x18, 0x50, 0x48, 0x60, 0x78,
0x68, 0x70, 0x58, 0x40, 0x08, 0x10, 0x38, 0x20,
0xA8, 0xB0, 0x98, 0x80, 0xC8, 0xD0, 0xF8, 0xE0,
0xD8, 0xC0, 0xE8, 0xF0, 0xB8, 0xA0, 0x88, 0x90,
0x18, 0x00, 0x28, 0x30, 0x78, 0x60, 0x48, 0x50,
0x40, 0x58, 0x70, 0x68, 0x20, 0x38, 0x10, 0x08,
0x80, 0x98, 0xB0, 0xA8, 0xE0, 0xF8, 0xD0, 0xC8
}; // crc8LUT
//----------------------------------------------------------------------------
// byte culFastCRC8(crcData, crcReg)
//
// Description:
// A CRC-8 (DOW) implementation optimized for fast execution.
// The function should be called once for each byte in the data
// the CRC is to be performed on. Before the invocation on the first byte
// the FAST_CRC8_INIT() macro should be called. This final CRC-value
// should be added at the end of the data to facilitate a later CRC
// check. During checking the check should be performed on all the data
// AND the CRC-8 value appended to it. The data is intact if the value
// returned is 0.
//
// Arguments:
// byte crcData
// The data to perform the CRC-8 operation on.
// byte crcReg
// The current value of the CRC register. For each additional byte
// the value returned for the last invocation should be supplied.
//
// Return value (not for the macro):
// The updated value of the CRC8 register. This corresponds to the
// CRC-8 of the data supplied so far. During CRC checking, after working
// through all the data and the appended CRC-8 value, the value will be
// 0 if the data is intact.
//----------------------------------------------------------------------------
byte culFastCRC8(byte crcData, byte crcReg) {
return crc8LUT[crcData ^ crcReg];
} // culFastCRC8
//----------------------------------------------------------------------------
// byte culFastCRC8Block(byte *crcData, word length, byte crcReg)
//
// Description:
// An implementation of the above function (culFastCRC8) that operates
// on blocks of data instead of single bytes.
//
// Extra arguments:
// word length
// The number of bytes in this block (crcData[]).
//----------------------------------------------------------------------------
byte culFastCRC8Block(byte *crcData, word length, byte crcReg) {
word i;
for (i = 0; i < length; i++) {
crcReg = crc8LUT[crcData[i] ^ crcReg];
}
return crcReg;
} // culFastCRC8Block
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -