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

📄 cul.h

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 H
📖 第 1 页 / 共 4 页
字号:
//      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                                                  *
 ****************************************************************************/



/*****************************************************************************
 *****************************************************************************
 *************                      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
//
//		bool calibrate
//			Calibrate now. *pRF_CALDATA is written to when calibrate = TRUE,
//			and read from otherwise. Use FALSE if *pRF_CALDATA is valid.
//----------------------------------------------------------------------------
void sppSetupRF (RF_RXTXPAIR_SETTINGS code *pRF_SETTINGS, RF_RXTXPAIR_CALDATA xdata *pRF_CALDATA, 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 

// SPP_TX_INFO/SPP_RX_INFO.flags
#define SPP_ACK_REQ				0x01 // Acknowledge request
#define SPP_ACK					0x02 // Ack flag (used internally)
#define SPP_ENCRYPTED_DATA		0x04 // The packet data is encrypted
#define SPP_SEQUENCE_BIT		0x08 // Toggled when a transmission finishes successfully




//----------------------------------------------------------------------------
// The transmit struct
typedef struct {
	byte destination;				 // The destination of the packet
	byte flags;						 // Flags
	byte dataLen;					 // The length of the transmitted data
	byte xdata *pDataBuffer;		 // The transmitted data
	byte status;					 // The transmission status (result)
} SPP_TX_INFO;

// SPP_TX_INFO.status:
#define SPP_TX_TRANSMITTING		0x01 // The packet is being transmitted
#define SPP_TX_WAITING_FOR_ACK	0x02 // Waiting for the ack packet
#define SPP_TX_ACK_INVALID		0x04 // An invalid ack was received
#define SPP_TX_ACK_TIMEOUT		0x08 // No response
#define SPP_TX_FINISHED			0x10 // OK!
#define SPP_TX_RESET			0x20 // Reset by sppReset()


//----------------------------------------------------------------------------
//  byte sppSend (SPP_TX_INFO xdata *pTXInfo)
//
//  Description:
//      If the transceiver is ready (in idle mode), the transmit section will
//		be powered up and the RF interrupt enabled. The RF ISR will then 
//		transmit the packet (pTXInfo) and receive the ack (if requested). If
//		requested (sppSettings.txAttempts = n), the packet will be re-
//		transmitted (n-1) times, until the ack is received. When finished the 
//		transmit section will be powered down.
//		
//		This function will return immediately and the application can 
//		continue while the ISR transmits the packet. When finished, 
//		sppStatus() will return IDLE_MODE. During the transmission it will 
//		return TX_MODE or TXACK_MODE.
//
//		After the transmission: Use pTXInfo->status to find out what happened:
//			SPP_TX_ACK_INVALID = Something was received, but not the ack
//			SPP_TX_ACK_TIMEOUT = No response
//			SPP_TX_FINISHED
//
//		sppSettings.txAckTimeout gives the ack timeout in msecs.
//
//  Arguments:
//      SPP_TX_INFO xdata *pTXInfo
//			An SPP_TX_INFO struct must be prepared before the transmission,
//			including the following values:
//				destination (SPP_BROADCAST or 1-255)
//				flags (SPP_ACK_REQ | SPP_ENCRYPTED_DATA)
//				dataLen (Length of *pDataBuffer, 0-255)
//				pDataBuffer (pointer to the transmission data buffer)
//
//  Return value:
//		byte
//      	SPP_TX_STARTED if OK
//			SPP_BUSY if not ready
//----------------------------------------------------------------------------
byte sppSend (SPP_TX_INFO xdata *pTXInfo);




//----------------------------------------------------------------------------
// The receive struct:
typedef struct {
	byte source;				 // The packet source address
	byte flags;					 // Flags
	byte maxDataLen;			 // Maximum data length (size of *pDataBuffer)
	byte dataLen;				 // The length of the received data
	byte xdata *pDataBuffer;	 // The received data
	byte status;				 // The reception status (result)
} SPP_RX_INFO;

// SPP_RX_INFO.status:
#define SPP_RX_WAITING	 	0x01 // Waiting for packet
#define SPP_RX_RECEIVING 	0x02 // Receiving packet
#define SPP_RX_ACKING		0x04 // Transmitting ack
#define SPP_RX_TIMEOUT 		0x08 // Reception timed out
#define SPP_RX_TOO_LONG		0x10 // The packet data was longer than the given maximum length (the buffer was not updated)
#define SPP_RX_FINISHED		0x20 // OK!
#define SPP_RX_RESET		0x40 // Reset by sppReset()

//----------------------------------------------------------------------------
//  byte sppReceive (SPP_RX_INFO xdata* pRXInfo)
//
//  Description:
//      If the transceiver is ready (in idle mode), the receive section will
//		be powered up and the RF interrupt enabled. The RF ISR will then 
//		receive the packet and transmit an ack if requested to. When finished,
//		the receive section will be powered down.
//		
//		This function will return immediately and the application can 
//		continue while the ISR receives the packet. When finished, sppStatus() 
//		will return SPP_IDLE_MODE. During the transmission it will 
//		return RX_MODE or RXACK_MODE.
//
//		After the reception: Use pRXInfo->status to find out what happened:
//			SPP_RX_TIMEOUT =   Timeout (nothing received).
//			SPP_RX_TOO_LONG =  dataLen > maxDataLen (the buffer is invalid).
//			SPP_RX_FINISHED	=  source, dataLen and *pDataBuffer in *pRXInfo  
//			                   are valid.
//
//  Arguments:
//      SPP_RX_INFO xdata* pRXInfo
//			An SPP_RX_INFO struct must be prepared before the reception,
//			including the following values:
//				maxDataLen (Length of the data buffer, 0-255)
//				pDataBuffer (pointer to the reception buffer)
//
//  Return value:
//		byte
//			SPP_RX_STARTED if OK
//			SPP_BUSY if not ready
//----------------------------------------------------------------------------
byte sppReceive (SPP_RX_INFO xdata *pRXInfo);




//----------------------------------------------------------------------------
//  byte sppStatus (void)
//
//  Description:
//      Returns the status of the SPP finite state machine.
//
//  Return value:
//		byte
//			SPP_IDLE_MODE =  Ready to transmit or receive
//			SPP_TX_MODE =    Transmitting a packet
//			SPP_TXACK_MODE = Waiting for the ack
//			SPP_RX_MODE =    Waiting for or receiving a packet
//			SPP_RXACK_MODE = Transmitting the ack
//
//	NOTE: This function has also been implemented as a macro, SPP_STATUS(),
//	which is both smaller and faster.
//----------------------------------------------------------------------------
byte sppStatus(void);

// #define SPP_STATUS() ... is located in sppInternal.h

// Return values:
#define SPP_IDLE_MODE	0x00
#define SPP_TX_MODE		0x10
#define SPP_TXACK_MODE	0x20
#define SPP_RX_MODE		0x40
#define SPP_RXACK_MODE	0x80




//----------------------------------------------------------------------------
//  void sppReset (void)
//
//  Description:
//		Stops a transmission or reception by 
//			- turning the transceiver off
//			- entering IDLE mode (sppStatus()) 
//----------------------------------------------------------------------------
void sppReset (void);




⌨️ 快捷键说明

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