⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cul.h

📁 无线龙ZigBee模块CC1010的接收-发送程序。
💻 H
📖 第 1 页 / 共 3 页
字号:
//	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
//      ENDIAN byte order. (Use the CRC16Append(...) function for this.)
//
//	Arguments:
//		byte* crcData
//			A pointer to the block of data to perform the CRC-16 operation on.
//      lword length
//          The number of bytes in this block.
//		word crcReg
//			The current value of the CRC register. For the first block the
//			value CRC16_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 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 culSmallCRC16Block(byte* crcData, word length, word crcReg);


//----------------------------------------------------------------------------
//  void culCRC16Append(...)
//
//	Description:
//	    Appends a CRC value to a block of data in BIG ENDIAN byte order.
//
//	Arguments:
//		byte* dataPtr
//			A pointer to where to insert the CRC value.
//		word crcValue
//			The CRC value to insert.
//
//	Return value:
//      void
//----------------------------------------------------------------------------
void culCRC16Append(byte* dataPtr, word crcValue);


/****************************************************************************/




/*****************************************************************************
 *****************************************************************************
 *                                                                           *
 *     00000  00000  00000                                                   *
 *     0      0   0  0   0                                                   *
 *     00000  00000  00000          - SIMPLE PACKET PROTOCOL -               *
 *         0  0      0                                                       *
 *     00000  0      0                                                       *
 *                                                                           *
 *****************************************************************************
 *****************************************************************************
 * The CUL SPP provides a way to transmit and receive radio packets.         *
 * Higher protocol layers or applications can access the physical layer      *
 * using the simple SPP- interface. The interface consists of functions and  *
 * macros for                                                                *
 *   - Setup of the radio and modem hardware, including RF (re)calibration.  *
 *   - Transmitting and receiving data packets (with timeouts).              *
 *   - Resetting the transceiver (aborting a transmission or reception).     *
 *   - Getting the current transmission/reception status.                    *
 *   - A packet sequence bit which can be used to guarantee that packets are * 
 *     received only once (The bit is toggled after a successfull            *
 *     transmission).                                                        *
 *   - Two free timed callbacks with a precission of 10 msecs.               *
 *   - Getting the current time from a 16-bit 10-msec resolution counter.    *
 *                                                                           *
 * Other features:                                                           *
 * 	 - 255 physical network addresses, and a special broadcast address       *
 *     (SPP_BROADCAST). Packet acknowledging is not supported for broadcasts.*
 * 	 - Error detection through CRC8 (message header) and CRC16 (data)        *
 *   - Automatic retransmissions (variable)                                  *
 *   - Reception timeouts (variable)                                         *
 *                                                                           *
 * How to use the SPP:                                                       *
 *   - Include this file, <chipcon/cul.h>                                    *
 *   - Declare: SPP_SETTINGS, RF_RXTXPAIR_SETTINGS, RF_RXTXPAIR_CALDATA,     *
 *     SPP_RX_INFO and SPP_TX_INFO                                           *
 *   - Initialize SPP_SETTINGS and RF_RXTXPAIR_SETTINGS (Use SmartRF Studio) *
 *   - Call sppSetupRF(...)                                                  *
 *   - For each transmission:                                                *
 *       - Prepare SPP_TX_INFO                                               *
 *       - Call sppSend(...)                                                 *
 *       - Poll the transmission status by using the SPP_STATUS() macro      *
 *   - For each reception:                                                   *
 *       - Prepare SPP_RX_INFO                                               *
 *       - Call sppReceive(...)                                              *
 *       - Poll the reception status by using the SPP_STATUS() macro         *
 *****************************************************************************
 * Author:              JOL                                                  *
 * Current Revision:                                                         *
 * Last Changed:        2002/06/17                                           *
 *****************************************************************************
 * Revision history:                                                         *
 * 1.0  2002/06/17      First Public Release                                 *
 ****************************************************************************/



/*****************************************************************************
 *****************************************************************************
 *************                      Setup                        *************
 *****************************************************************************
 ****************************************************************************/

// Local settings
typedef struct {
	byte myAddress;				// The address of this network node
	word rxTimeout;				// Receive timeout (10s of msecs)
	word txAckTimeout;			// Ack receive timeout (10s of msecs)
	byte txAttempts;			// Transmission attempts (applies only to ack'ed messages)
	byte txPreambleByteCount;	// Number of transmitted preamble bytes
} SPP_SETTINGS;

extern SPP_SETTINGS xdata sppSettings;

// The broadcast address
#define SPP_BROADCAST 0




//----------------------------------------------------------------------------
//  void sppSetupRF (...)
//
//  Description:
//      Set up SPP for transmission or reception.
//		Call this function to (re)calibrate the radio, or to switch between
//		different RF settings.
//
//  Arguments:
//      RF_RXTXPAIR_SETTINGS code* pRF_SETTINGS
//			RF settings (frequencies, modem settings, etc.)
//
//      RF_RXTXPAIR_CALDATA xdata* pRF_CALDATA
//			Calibration results
//
//		word clkFreq
//			The XOSC clock frequency in kHz.
//
//		bool calibrate
//			Calibrate now. *pRF_CALDATA is written to when calibrate = TRUE,
//			and read from otherwise. *pRF_CALDATA must always be valid.
//
//	Note: This function also enables timeouts, using timer 3.
//----------------------------------------------------------------------------
void sppSetupRF (
	RF_RXTXPAIR_SETTINGS code* pRF_SETTINGS, 
	RF_RXTXPAIR_CALDATA xdata* pRF_CALDATA,
	word clkFreq,
	bool calibrate
);

// RF constants
#define SPP_PREAMBLE_SENSE_BITS	16	 // Number of preamble bits to sense before RX (use min. 16)
#define SPP_ZEROPAD_COUNT 		2	 // Number of trailing zero paddings




/*****************************************************************************
 *****************************************************************************
 *************                  Communication                    *************
 *****************************************************************************
 ****************************************************************************/

// Return values from sppSend() and sppReceive()
#define SPP_BUSY				0
#define SPP_RX_STARTED			1
#define SPP_TX_STARTED			1 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -