//-------------------------------------------------------------------
// Filename: basic_rf.c
// Description: Basic RF library
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// INCLUDES
//-------------------------------------------------------------------
#include "hal_defs.h"
#include "hal_int.h"
#include "hal_mcu.h" // Using halMcuWaitUs()
#include "hal_rf.h"
#include "basic_rf.h"
#ifdef SECURITY_CCM
#include "hal_rf_security.h"
#include "basic_rf_security.h"
#endif
#include <string.h>
//-------------------------------------------------------------------
// CONSTANTS AND DEFINES
//-------------------------------------------------------------------
// Packet and packet part lengths
#define PKT_LEN_MIC 8
#define PKT_LEN_SEC PKT_LEN_UNSEC + PKT_LEN_MIC
#define PKT_LEN_AUTH 8
#define PKT_LEN_ENCR 24
// 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 - BASIC_RF_AUX_HDR_LENGTH - BASIC_RF_LEN_MIC)
#define BASIC_RF_ACK_PACKET_SIZE 5
#define BASIC_RF_FOOTER_SIZE 2
#define BASIC_RF_HDR_SIZE 10
// 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_PLD_LEN_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_SEC_ENABLED_FCF_BM 0x0008
// Frame control field LSB
#define BASIC_RF_FCF_NOACK_L LO_UINT16(BASIC_RF_FCF_NOACK)
#define BASIC_RF_FCF_ACK_L LO_UINT16(BASIC_RF_FCF_ACK)
#define BASIC_RF_FCF_ACK_BM_L LO_UINT16(BASIC_RF_FCF_ACK_BM)
#define BASIC_RF_FCF_BM_L LO_UINT16(BASIC_RF_FCF_BM)
#define BASIC_RF_SEC_ENABLED_FCF_BM_L LO_UINT16(BASIC_RF_SEC_ENABLED_FCF_BM)
// Auxiliary Security header
#define BASIC_RF_AUX_HDR_LENGTH 5
#define BASIC_RF_LEN_AUTH BASIC_RF_PACKET_OVERHEAD_SIZE + BASIC_RF_AUX_HDR_LENGTH - BASIC_RF_FOOTER_SIZE
#define BASIC_RF_SECURITY_M 2
#define BASIC_RF_LEN_MIC 8
#ifdef SECURITY_CCM
#undef BASIC_RF_HDR_SIZE
#define BASIC_RF_HDR_SIZE 15
#endif
// Footer
#define BASIC_RF_CRC_OK_BM 0x80
//-------------------------------------------------------------------
// TYPEDEFS
//-------------------------------------------------------------------
// The receive struct
typedef struct
{
uint8 seqNumber;
uint16 srcAddr;
uint16 srcPanId;
int8 length;
uint8 *pPayload;
uint8 ackRequest;
int8 rssi;
volatile uint8 isReady;
uint8 status;
} basicRfRxInfo_t;
// Tx state
typedef struct
{
uint8 txSeqNumber;
volatile uint8 ackReceived;
uint8 receiveOn;
uint32 frameCounter;
} basicRfTxState_t;
// Basic RF packet header (IEEE 802.15.4)
typedef struct
{
uint8 packetLength;
uint8 fcf0; // Frame control field LSB
uint8 fcf1; // Frame control field MSB
uint8 seqNumber;
uint16 panId;
uint16 destAddr;
uint16 srcAddr;
#ifdef SECURITY_CCM
uint8 securityControl;
uint8 frameCounter[4];
#endif
} basicRfPktHdr_t;
//-------------------------------------------------------------------
// LOCAL VARIABLES
//-------------------------------------------------------------------
static basicRfRxInfo_t rxi =
{
0xFF
}; // Make sure sequence numbers are
static basicRfTxState_t txState =
{
0x00
}; // initialised and distinct.
static basicRfCfg_t *pConfig;
static uint8 txMpdu[BASIC_RF_MAX_PAYLOAD_SIZE + BASIC_RF_PACKET_OVERHEAD_SIZE + 1];
static uint8 rxMpdu[128];
//-------------------------------------------------------------------
// LOCAL FUNCTIONS
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// @fn basicRfBuildHeader
// @brief Builds packet header according to IEEE 802.15.4 frame format
// @param buffer - Pointer to buffer to write the header
// destAddr - destination short address
// payloadLength - length of higher layer payload
// @return uint8 - length of header
//-------------------------------------------------------------------
static uint8 basicRfBuildHeader(uint8 *buffer, uint16 destAddr, uint8 payloadLength)
{
basicRfPktHdr_t *pHdr;
uint16 fcf;
pHdr = (basicRfPktHdr_t*)buffer;
// Populate packet header
pHdr->packetLength = payloadLength + BASIC_RF_PACKET_OVERHEAD_SIZE;
//pHdr->frameControlField = pConfig->ackRequest ? BASIC_RF_FCF_ACK : BASIC_RF_FCF_NOACK;
fcf = pConfig->ackRequest ? BASIC_RF_FCF_ACK : BASIC_RF_FCF_NOACK;
pHdr->fcf0 = LO_UINT16(fcf);
pHdr->fcf1 = HI_UINT16(fcf);
pHdr->seqNumber = txState.txSeqNumber;
pHdr->panId = pConfig->panId;
pHdr->destAddr = destAddr;
pHdr->srcAddr = pConfig->myAddr;
#ifdef SECURITY_CCM
// Add security to FCF, length and security header
pHdr->fcf0 |= BASIC_RF_SEC_ENABLED_FCF_BM_L;
pHdr->packetLength += PKT_LEN_MIC;
pHdr->packetLength += BASIC_RF_AUX_HDR_LENGTH;
pHdr->securityControl = SECURITY_CONTROL;
pHdr->frameCounter[0] = LO_UINT16(LO_UINT32(txState.frameCounter));
pHdr->frameCounter[1] = HI_UINT16(LO_UINT32(txState.frameCounter));
pHdr->frameCounter[2] = LO_UINT16(HI_UINT32(txState.frameCounter));
pHdr->frameCounter[3] = HI_UINT16(HI_UINT32(txState.frameCounter));
#endif
return BASIC_RF_HDR_SIZE;
}
//-------------------------------------------------------------------
// @fn basicRfBuildMpdu
// @brief Builds mpdu (MAC header + payload) according to IEEE 802.15.4
// frame format
// @param destAddr - Destination short address
// pPayload - pointer to buffer with payload
// payloadLength - length of payload buffer
// @return uint8 - length of mpdu
//-------------------------------------------------------------------
static uint8 basicRfBuildMpdu(uint16 destAddr, uint8 *pPayload, uint8 payloadLength)
{
uint8 hdrLength, n;
hdrLength = basicRfBuildHeader(txMpdu, destAddr, payloadLength);
for (n = 0; n < payloadLength; n++)
{
txMpdu[hdrLength + n] = pPayload[n];
}
return hdrLength + payloadLength; // total mpdu length
}
//-------------------------------------------------------------------
// @fn basicRfRxFrmDoneIsr
// @brief Interrupt service routine for received frame from radio
// (either data or acknowlegdement)
// @param rxi - file scope variable info extracted from the last incoming
// frame
// txState - file scope variable that keeps tx state info
// @return none
//-------------------------------------------------------------------
static void basicRfRxFrmDoneIsr(void)
{
basicRfPktHdr_t *pHdr;
uint8 *pStatusWord;
#ifdef SECURITY_CCM
uint8 authStatus = 0;
#endif
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Zigbee无线通信,实现无线花式点灯功能,实现如下要求: <2> 程序开始运行Zigbee节点盒LED1、LED2灯亮,Zigbee模块D4、D3、D6、D5灯亮; <3> 单击Zigbee节点盒SW1后,板上的LED1、LED2灯进入交替亮灭状态(如LED1亮则LED2灭,LED2亮则LED1灭);同时发送一个信息给Zigbee模块,当Zigbee模块收到这个信息后Zigbee模块板上的D4、D3、D6、D5灯进入流水灯状态。 <4> 单击Zigbee模块上的SW1后,板上的D5、D6、D3、D4灯进入流水状态;同时发送一个信息给Zigbee节点盒,当Zigbee节点盒收到这个信息后Zig
资源推荐
资源详情
资源评论
收起资源包目录
CC2530无线通信系统 (156个子文件)
rf_set.Debug.cspy.bat 2KB
rf_set.cspy.bat 1KB
basic_rf.c 18KB
hal_digio.c 14KB
hal_rf_security.c 12KB
hal_rf.c 12KB
dma_itg.c 9KB
BMA020.c 9KB
hal_uart1.c 8KB
hal_uart.c 8KB
sh10.c 8KB
dma_bma.c 5KB
rf_set.c 5KB
dma_itg.c 5KB
dma_eeprom.c 4KB
hal_timer_32k.c 4KB
sensor.c 4KB
hal_mcu.c 4KB
util.c 4KB
get_adc.c 3KB
hal_clock.c 3KB
hal_led.c 3KB
UART_SEND_RECV.c 3KB
basic_rf_security.c 2KB
dma_tc72.c 2KB
hal_int.c 2KB
UART_PRINT.c 2KB
dma_imc.c 2KB
hal_rf_util.c 2KB
hal_adc.c 2KB
dma_dc.c 2KB
Flash_data.c 2KB
dma_tgs2602.c 1KB
dma_tgs.c 1KB
dma_kr.c 1KB
dma_m4.c 1KB
dma_ad590.c 1KB
TIMER.c 1KB
TIMER.c 1KB
get_swsensor.c 1KB
hal_sleep.c 823B
hal_board.c 264B
rf_set.d51 76KB
rf_set.dbgdt 46KB
rf_set.dep 18KB
rf_set.dni 123B
rf_set.dnx 1KB
readme.doc 32KB
readme.black.doc 16KB
readme.blue.doc 16KB
rf_set.ewd 51KB
rf_set.ewp 81KB
Backup of rf_set.ewp 57KB
rf_set.ewt 163KB
rf_set.eww 160B
hal_board.h 16KB
dma_sht.h 6KB
basic_rf.h 6KB
hal_defs.h 4KB
hal_adc.h 4KB
hal_cc8051.h 3KB
hal_clock.h 3KB
hal_rf.h 2KB
hal_uart1.h 2KB
hal_uart.h 2KB
hal_digio.h 2KB
util.h 1KB
hal_rf_security.h 1KB
BMA020.h 1014B
hal_int.h 854B
hal_timer_32k.h 784B
sensor.h 767B
hal_mcu.h 734B
dma_itg.h 637B
UART_PRINT.h 632B
dma_bma.h 596B
Flash_data.h 514B
dma_eeprom.h 488B
dma_imc.h 469B
dma_itg.h 458B
basic_rf_security.h 445B
dma_ad590.h 443B
dma_tgs2602.h 441B
hal_rf_util.h 439B
dma_m4.h 435B
hal_led.h 427B
dma_dc.h 392B
get_adc.h 304B
sh10.h 304B
hal_sleep.h 266B
dma_tc72.h 244B
get_swsensor.h 238B
dma_tgs.h 223B
dma_kr.h 223B
UART_SEND_RECV.h 186B
TIMER.h 100B
TIMER.h 100B
rf1.HEX 12KB
rf_set.pbd.linf 1KB
rf_set.pbd 202KB
共 156 条
- 1
- 2
资源评论
加菲临界
- 粉丝: 10
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功