/***********************************************************************************
Filename: basic_rf.c
Description: Basic RF library
***********************************************************************************/
/***********************************************************************************
* INCLUDES
*/
#include "hal_int.h"
#include "hal_mcu.h" // Using halMcuWaitUs()
#include "hal_rf.h"
#ifdef SECURITY_CCM
#include "hal_rf_security.h"
#endif
#include "basic_rf.h"
#ifdef SECURITY_CCM
#include "basic_rf_security.h"
#endif
#include "util.h" // Using min()
#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];
/***********************************************************************************
* GLOBAL VARIABLES
*/
/***********************************************************************************
* 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
// Make sure bytefields are network byte order
UINT16_HTON(pHdr->panId);
UINT16_HTON(pHdr->destAddr);
UINT16_HTON(pHdr->srcAddr);
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
// Map header to packet buffer
pHdr= (basicRfPktHdr_t*)rxMpdu;
// Clear
没有合适的资源?快使用搜索试试~ 我知道了~
基于CC2530的温湿度数据收发
共408个文件
r51:103个
h:48个
c:40个
1星 需积分: 44 33 下载量 55 浏览量
2018-07-19
09:40:11
上传
评论 3
收藏 2.24MB RAR 举报
温馨提示
基于CC2530开发板,温湿度传感器,实现温湿度一对多的数据发送与接收。
资源推荐
资源详情
资源评论
收起资源包目录
基于CC2530的温湿度数据收发 (408个子文件)
per_test.cspy.bat 3KB
per_test.cspy.bat 3KB
spectrum_analyzer.cspy.bat 2KB
spectrum_analyzer.cspy.bat 2KB
light_switch.srf05_cc2530.cspy.bat 2KB
light_switch.srf05_cc2530.cspy.bat 2KB
light_switch.cspy.bat 1KB
light_switch.cspy.bat 1KB
light_switch.cspy.bat 1KB
light_switch.pbd.browse 187KB
light_switch.pbd.browse 180KB
basic_rf.c 20KB
basic_rf.c 20KB
hal_rf.c 16KB
hal_rf.c 16KB
hal_digio.c 15KB
hal_digio.c 15KB
per_test.c 14KB
per_test.c 14KB
hal_rf_security.c 13KB
hal_rf_security.c 13KB
spectrum_analyzer.c 8KB
spectrum_analyzer.c 8KB
per_test_menu.c 7KB
per_test_menu.c 7KB
util_buffer.c 6KB
util_buffer.c 6KB
hal_mcu.c 6KB
hal_mcu.c 6KB
hal_timer_32k.c 6KB
hal_timer_32k.c 6KB
hal_lcd_srf05.c 6KB
hal_lcd_srf05.c 6KB
util.c 6KB
util.c 6KB
send.c 5KB
clock.c 5KB
clock.c 5KB
receive.c 4KB
basic_rf_security.c 4KB
basic_rf_security.c 4KB
hal_int.c 4KB
hal_int.c 4KB
adc.c 4KB
adc.c 4KB
hal_rf_util.c 2KB
hal_rf_util.c 2KB
hal_board.c 1KB
hal_board.c 1KB
hal_assert.c 1KB
hal_assert.c 1KB
per_test.d51 221KB
per_test.d51 221KB
spectrum_analyzer.d51 134KB
spectrum_analyzer.d51 134KB
light_switch.d51 97KB
light_switch.d51 95KB
light_switch.dbgdt 58KB
light_switch.dbgdt 55KB
per_test.dbgdt 4KB
per_test.dbgdt 4KB
spectrum_analyzer.dbgdt 4KB
spectrum_analyzer.dbgdt 4KB
light_switch.dbgdt 63B
light_switch.dep 20KB
per_test.dep 20KB
per_test.dep 19KB
light_switch.dep 18KB
light_switch.dep 17KB
spectrum_analyzer.dep 17KB
spectrum_analyzer.dep 17KB
per_test.dep 366B
light_switch.dni 1010B
light_switch.dni 973B
per_test.dni 497B
per_test.dni 497B
spectrum_analyzer.dni 459B
spectrum_analyzer.dni 459B
light_switch.dni 123B
light_switch.dnx 1KB
light_switch.dnx 1KB
light_switch.ewd 24KB
light_switch.ewd 24KB
per_test.ewd 24KB
light_switch.ewd 24KB
spectrum_analyzer.ewd 24KB
per_test.ewd 24KB
per_test.ewd 24KB
spectrum_analyzer.ewd 24KB
Backup (2) of light_switch.ewd 17KB
Backup (3) of light_switch.ewd 17KB
Backup (2) of light_switch.ewd 17KB
Backup (2) of light_switch.ewd 17KB
Backup (2) of per_test.ewd 17KB
Backup (2) of per_test.ewd 17KB
Backup (2) of spectrum_analyzer.ewd 17KB
Backup (3) of per_test.ewd 17KB
Backup (3) of spectrum_analyzer.ewd 17KB
Backup (2) of spectrum_analyzer.ewd 17KB
Backup (2) of per_test.ewd 17KB
共 408 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 小气不倒翁2019-03-13不是基于协议栈的例程,一般
我是一朵油菜花
- 粉丝: 7
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功