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

📄 cul.h

📁 无线龙ZigBee模块CC1010的接收-发送程序。
💻 H
📖 第 1 页 / 共 3 页
字号:
// 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);




/*****************************************************************************
 *****************************************************************************
 *************               Timer with Callback                 *************
 *****************************************************************************
 ****************************************************************************/

// SPP supports 2 custom callbacks which can be set dynamically

//----------------------------------------------------------------------------
//  void sppSetTimerCB (void)
//
//	Description:
//		Add timer callback
//
//	Arguments:
//		byte cb
//			Callback index - use SPP_CUSTOM_0_TIMER	or SPP_CUSTOM_1_TIMER
//			The SPP finite state machine uses SPP_FSM_TIMER
//		void (*pF) ()
//			Pointer to the function to call
//		word *pTicks
//			The timeout in 10s of msecs
//
//	NOTE: *pTicks will be decremented by the Timer 3 interrupt 
//----------------------------------------------------------------------------
void sppSetTimerCB (byte cb, void (*pF) (), word *pTicks);

// Available callbacks 
#define SPP_FSM_TIMER		0 // used by the SPP
#define SPP_CUSTOM_0_TIMER	1 // free
#define SPP_CUSTOM_1_TIMER	2 // free



//----------------------------------------------------------------------------
//  word sppGetTime (void)
//
//	Description:
//		Returns the value of the 10-msec counter, which is started by 
//		sppSetupRF(...)
//
//	Return value:
//		The current time in 10s of msecs
//----------------------------------------------------------------------------
word sppGetTime (void);




//----------------------------------------------------------------------------
//  MACRO: SPP_CHANGE_TICKS(var, value)
//
//	Description:
//		Use this macro to change the tick counter variables used with the 
//		callback timer
//
//	Arguments
//		(word) var
//			The variable
//		(word) value
//			The new value
//----------------------------------------------------------------------------
#define SPP_CHANGE_TICKS(var, value)		\
	do {									\
		INT_ENABLE (INUM_TIMER3, INT_OFF);	\
		var = (word) value;					\
		INT_ENABLE (INUM_TIMER3, INT_ON);	\
	} while (0)




// sppInternal.h requires some of the type definitions listed above!
#include <chipcon/sppInternal.h>

#endif // CUL_H

⌨️ 快捷键说明

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