📄 cul.h
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** CHIPCON UTILITY LIBRARY *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* The Chipcon Utility Library is a collection of functions and macros which *
* implement various basic components that are useful when building RF *
* applications on the CC1010. *
*****************************************************************************
* Author: ROH, JOL, OGR *
*****************************************************************************
* Revision history: *
* 1.0 2002/08/13 First Public Release *
* *
* $Log: cul.h,v $
* Revision 1.4 2003/07/29 11:22:14 tos
* Introduced support for frequency hopping.
*
* Revision 1.3 2003/04/03 12:38:59 tos
* Using sppSetupRF to recalibrate caused the custom callbacks to be reset.
* Removed timer initialization from sppSetupRF (including the clkFreq argument)
* sppStartTimer(...) and SPP_INIT_TIMEOUTS() must now be called manually at startup
*
* Revision 1.2 2002/11/21 10:51:41 tos
* Cosmetic change: corrected inconsistent header text.
*
* Revision 1.1 2002/10/14 11:49:08 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#ifndef CUL_H
#define CUL_H
#include <chipcon/reg1010.h>
#include <chipcon/hal.h>
/*****************************************************************************
*****************************************************************************
* *
* 00000 00000 00000 *
* 0 0 0 0 *
* 0 00000 0 - CYCLIC REDUNDANCY CODE - *
* 0 0 0 0 *
* 00000 0 0 00000 *
* *
*****************************************************************************
*****************************************************************************
* CRC-8 (DOW) and CRC-16 (CCITT) functions that operate on data bytewise *
* and in blocks are defined below along with helpful constants. *
* *
* Versions: *
* Fast: Using lookup tables (256 bytes for CRC-8, 512 bytes for CRC-16) *
* Small: For-loop (5-6 times slower than the fast implementation) *
*****************************************************************************
* Author: JOL *
****************************************************************************/
/*****************************************************************************
*****************************************************************************
************* COMMON CRC DEFINITIONS *************
*****************************************************************************
****************************************************************************/
// Constants used by the CRC algorithms
#define CRC16_POLY 0x1021
#define CRC16_INIT 0xFFFF
#define CRC8_POLY 0x18
#define CRC8_INIT 0xFF
// A constant which can be used to check if a CRC check succeeded, e.g.:
// if (culSmallCRC8(lastDataByte, crcReg) == CRC_OK) ...
#define CRC_OK 0
/*****************************************************************************
*****************************************************************************
************* FAST CRC-8 *************
*****************************************************************************
****************************************************************************/
// CRC8 LUT (newCRC = crc8LUT[dataByte ^ oldCRC])
extern byte code crc8LUT[256];
//----------------------------------------------------------------------------
// byte culFastCRC8(crcData, crcReg)
// Macro FAST_CRC8(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);
#define FAST_CRC8(crcData, crcReg) (crcReg = crc8LUT[crcData ^ crcReg])
#define FAST_CRC8_INIT(crcReg) (crcReg = CRC8_INIT)
#define FAST_CRC8_BLOCK
//----------------------------------------------------------------------------
// 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);
/*****************************************************************************
*****************************************************************************
************* SMALL CRC-8 *************
*****************************************************************************
****************************************************************************/
//----------------------------------------------------------------------------
// byte culSmallCRC8(...)
//
// Description:
// A CRC-8 (DOW) implementation optimized for small code size.
// The function should be called once for each byte in the data
// the CRC is to be performed on. For the invocation on the first byte
// the value CRC8_INIT should be given for _crcReg_. The value returned
// is the CRC-8 of the data supplied so far. This 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-16
// 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 the first byte the
// value CRC8_INIT should be supplied. For each additional byte the
// value returned for the last invocation should be supplied.
//
// Return value:
// 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 culSmallCRC8(byte crcData, byte crcReg);
//----------------------------------------------------------------------------
// byte culSmallCRC8Block(...)
//
// Description:
// A CRC-8 (DOW) implementation optimized for small code size on blocks
// of data. For the invocation on the first and/or only block the value
// CRC8_INIT should be given for _crcReg_. The value returned
// is the CRC-8 of the data supplied so far. This 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
// A pointer to the block of data to perform the CRC-8 operation on.
// word length
// The number of bytes in this block.
// byte crcReg
// The current value of the CRC register. For the first block the
// value CRC8_INIT should be supplied. For each additional block the
// value returned for the last invocation should be supplied.
//
// Return value:
// 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 culSmallCRC8Block(byte* crcData, word length, byte crcReg);
/*****************************************************************************
*****************************************************************************
************* FAST CRC-16 *************
*****************************************************************************
****************************************************************************/
extern word code crc16LUT[256];
//----------------------------------------------------------------------------
// word culFastCRC16(crcData, crcReg)
// Macro FAST_CRC16(crcData, crcReg)
//
// Description:
// A CRC-16 (CCITT) 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_CRC16_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-16 value appended to it. The data is intact if the value
// returned is 0.
//
// Arguments:
// byte crcData
// The data to perform the CRC-16 operation on.
// word crcReg
// The current value of the CRC register. For each additional byte
// the value returned for the last invocation should be supplied.
//
// Return value:
// The updated value of the CRC16 register. This corresponds to the
// CRC-16 of the data supplied so far. During CRC checking, after working
// through all the data and the appended CRC-16 value, the value will be
// 0 if the data is intact.
//----------------------------------------------------------------------------
word culFastCRC16(byte crcData, word crcReg);
#define FAST_CRC16(crcData, crcReg) (crcReg = (crcReg << 8) ^ crc16LUT[((byte)(crcReg >> 8)) ^ crcData])
#define FAST_CRC16_INIT(crcReg) (crcReg = CRC16_INIT)
//----------------------------------------------------------------------------
// word culFastCRC16Block(byte *crcData, word length, word crcReg)
//
// Description:
// An implementation of the above function (culFastCRC16) that operates
// on blocks of data instead of single bytes.
//
// Extra arguments:
// word length
// The number of bytes in this block (crcData[]).
//----------------------------------------------------------------------------
word culFastCRC16Block(byte *crcData, word length, word crcReg);
/*****************************************************************************
*****************************************************************************
************* SMALL CRC-16 *************
*****************************************************************************
****************************************************************************/
//----------------------------------------------------------------------------
// word culSmallCRC16(...)
//
// Description:
// A CRC-16/CCITT implementation optimized for small code size.
// The function should be called once for each byte in the data
// the CRC is to be performed on. For the invocation on the first byte
// the value CRC16_INIT should be given for _crcReg_. The value returned
// is the CRC-16 of the data supplied so far. This 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-16
// value appended to it. The data is intact if the value returned is 0.
//
// Arguments:
// byte crcData
// The data to perform the CRC-16 operation on.
// word crcReg
// The current value of the CRC register. For the first byte the
// value CRC16_INIT should be supplied. For each additional byte the
// value returned for the last invocation should be supplied.
//
// Return value:
// The updated value of the CRC16 register. This corresponds to the
// CRC-16 of the data supplied so far. During CRC checking, after working
// through all the data and the appended CRC-16 value, the value will be
// 0 if the data is intact.
//----------------------------------------------------------------------------
word culSmallCRC16(byte crcData, word crcReg);
//----------------------------------------------------------------------------
// word culSmallCRC16Block(...)
//
// Description:
// A CRC-16/CCITT implementation optimized for small code size on blocks
// of data. For the invocation on the first and/or only block the value
// CRC16_INIT should be given for _crcReg_. The value returned
// is the CRC-16 of the data supplied so far. This 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-16
// value appended to it. The data is intact if the value returned is 0.
// It is important that the CRC value is appended to the data in BIG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -