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

📄 basic_rf.h

📁 基于无线传感器网络的CC2420收发芯片初始化源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                               CHIPCON CC2420 BASIC RF LIBRARY                          *
 *      ***   + +   ***                             Library header file                                *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * The "Basic RF" library contains simple functions for packet transmission and reception with the     *
 * Chipcon CC2420 radio chip. The intention of this library is mainly to demonstrate how the CC2420 is *
 * operated, and not to provide a complete and fully-functional packet protocol. The protocol uses     *
 * 802.15.4 MAC compliant data and acknowledgment packets, however it contains only a small subset of  *
 * the 802.15.4 standard:                                                                              *
 *     - Association, scanning, beacons is not implemented                                             *
 *     - No defined coordinator/device roles (peer-to-peer, all nodes are equal)                       *
 *     - Waits for the channel to become ready, but does not check CCA twice (802.15.4 CSMA-CA)        *
 *     - Does not retransmit packets                                                                   *
 *     - Can not communicate with other networks (using a different PAN identifier)                    *
 *                                                                                                     *
 * INSTRUCTIONS:                                                                                       *
 * Startup:                                                                                            *
 *     1. Create a BASIC_RF_RX_INFO structure, and initialize the following members:                   *
 *         - rfRxInfo.pPayload (must point to an array of at least BASIC_RF_MAX_PAYLOAD_SIZE bytes)    *
 *     2. Call basicRfInit() to initialize the packet protocol.                                        *
 *                                                                                                     *
 * Transmission:                                                                                       *
 *     1. Create a BASIC_RF_TX_INFO structure, and initialize the following members:                   *
 *         - rfTxInfo.destAddr (the destination address, on the same PAN as you)                       *
 *         - rfTxInfo.pPayload (the payload data to be transmitted to the other node)                  *
 *         - rfTxInfo.length (the size od rfTxInfo.pPayload)                                           *
 *         - rfTxInfo.ackRequest (acknowledgment requested)                                            *
 *     2. Call basicRfSendPacket()                                                                     *
 *                                                                                                     *
 * Reception:                                                                                          *
 *     1. Call basicRfReceiveOn() to enable packet reception                                           *
 *     2. When a packet arrives, the FIFOP interrupt will run, and will in turn call                   *
 *        basicRfReceivePacket(), which must be defined by the application                             *
 *     3. Call basicRfReceiveOff() to disable packet reception                                         *
 *                                                                                                     *
 * FRAME FORMATS:                                                                                      *
 * Data packets:                                                                                       *
 *     [Preambles (4)][SFD (1)][Length (1)][Frame control field (2)][Sequence number (1)][PAN ID (2)]  *
 *     [Dest. address (2)][Source address (2)][Payload (Length - 2+1+2+2+2)][Frame check sequence (2)] *
 *                                                                                                     *
 * Acknowledgment packets:                                                                             *
 *     [Preambles (4)][SFD (1)][Length = 5 (1)][Frame control field (2)][Sequence number (1)]          *
 *     [Frame check sequence (2)]                                                                      *
 *******************************************************************************************************
 * Compiler: AVR-GCC                                                                                   *
 * Target platform: CC2420DB, CC2420 + any MCU with very few modifications required                    *
 *******************************************************************************************************
 * Revision history:                                                                                   *
 *  $Log: basic_rf.h,v $
 *  Revision 1.4  2004/07/26 11:26:15  mbr
 *  Modified BASIC_RF_ACK_DURATION & BASIC_RF_SYMBOL_DURATION
 *
 *  Revision 1.3  2004/03/30 14:58:45  mbr
 *  Release for web
 *                                                                                                     *
 *
 *
 *******************************************************************************************************/
#ifndef BASIC_RF_H
#define BASIC_RF_H




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                 General constants                 **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// Constants concerned with the Basic RF packet format

// Packet overhead ((frame control field, sequence number, PAN ID, destination and source) + (footer))
// Note that the length byte itself is not included included in the packet length
#define BASIC_RF_PACKET_OVERHEAD_SIZE   ((2 + 1 + 2 + 2 + 2) + (2))
#define BASIC_RF_MAX_PAYLOAD_SIZE		(127 - BASIC_RF_PACKET_OVERHEAD_SIZE)
#define BASIC_RF_ACK_PACKET_SIZE		5

// The time it takes for the acknowledgment packet to be received after the data packet has been
// transmitted
#define BASIC_RF_ACK_DURATION			(0.5 * 32 * 2 * ((4 + 1) + (1) + (2 + 1) + (2)))
#define BASIC_RF_SYMBOL_DURATION	    (32 * 0.5)

// The length byte
#define BASIC_RF_LENGTH_MASK            0x7F

// Frame control field
#define BASIC_RF_FCF_NOACK              0x8841
#define BASIC_RF_FCF_ACK                0x8861
#define BASIC_RF_FCF_ACK_BM             0x0020
#define BASIC_RF_FCF_BM                 (~BASIC_RF_FCF_ACK_BM)
#define BASIC_RF_ACK_FCF		        0x0002

// Footer
#define BASIC_RF_CRC_OK_BM              0x80
//-------------------------------------------------------------------------------------------------------




/*******************************************************************************************************
 *******************************************************************************************************
 **************************                Packet transmission                **************************
 *******************************************************************************************************
 *******************************************************************************************************/


//-------------------------------------------------------------------------------------------------------
// The data structure which is used to transmit packets
typedef struct {
    WORD destPanId;
	WORD destAddr;
	INT8 length;
    BYTE *pPayload;
	BOOL ackRequest;
} BASIC_RF_TX_INFO;
//-------------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------------
//  BYTE basicRfSendPacket(BASIC_RF_TX_INFO *pRTI)
//
//  DESCRIPTION:
//		Transmits a packet using the IEEE 802.15.4 MAC data packet format with short addresses. CCA is
//		measured only once before backet transmission (not compliant with 802.15.4 CSMA-CA).
//		The function returns:
//			- When pRTI->ackRequest is FALSE: After the transmission has begun (SFD gone high)
//			- When pRTI->ackRequest is TRUE: After the acknowledgment has been received/declared missing.

⌨️ 快捷键说明

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