/***********************************************************************************
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
没有合适的资源?快使用搜索试试~ 我知道了~
chenggong.rar_CC2530无线_无线采集cc2530_温湿度
共136个文件
h:49个
c:31个
r51:29个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 90 浏览量
2022-09-20
22:38:35
上传
评论
收藏 396KB RAR 举报
温馨提示
基于CC2530温湿度无线采集与发送,只要改一下相应的管脚就可以用了。
资源详情
资源评论
资源推荐
收起资源包目录
chenggong.rar_CC2530无线_无线采集cc2530_温湿度 (136个子文件)
sensor.cspy.bat 2KB
sensor.cspy.bat 1KB
controller.cspy.bat 1KB
basic_rf.c 20KB
basic_rf.c 20KB
hal_rf.c 16KB
hal_rf.c 16KB
main.c 14KB
hal_rf_security.c 13KB
hal_rf_security.c 13KB
main.c 12KB
DHT11.c 7KB
hal_board.c 7KB
hal_board.c 7KB
i2c_bus.c 6KB
hal_mcu.c 6KB
hal_mcu.c 6KB
hal_timer_32k.c 6KB
hal_timer_32k.c 6KB
util.c 6KB
util.c 6KB
clock.c 5KB
clock.c 5KB
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_assert.c 3KB
hal_assert.c 3KB
hal_rf_util.c 2KB
hal_rf_util.c 2KB
i2c_bus.c 2KB
controller.d51 150KB
sensor.d51 145KB
sensor.dbgdt 7KB
controller.dbgdt 5KB
sensor.dbgdt 63B
sensor.dep 15KB
controller.dep 13KB
controller.dni 900B
sensor.dni 727B
sensor.dni 217B
sensor.ewd 33KB
controller.ewd 33KB
Backup of sensor.ewd 33KB
Backup of controller.ewd 33KB
controller.ewp 58KB
sensor.ewp 58KB
Backup of controller.ewp 57KB
Backup of sensor.ewp 57KB
controller.eww 164B
sensor.eww 160B
hal_board.h 7KB
hal_board.h 7KB
hal_cc8051.h 6KB
hal_cc8051.h 6KB
hal_defs.h 6KB
hal_defs.h 6KB
hal_types.h 5KB
hal_types.h 5KB
basic_rf.h 5KB
basic_rf.h 5KB
hal_rf.h 5KB
hal_rf.h 5KB
hal_int.h 4KB
hal_int.h 4KB
lcd12864_driver.h 4KB
hal_lcd.h 4KB
hal_lcd.h 4KB
adc.h 4KB
adc.h 4KB
clock.h 4KB
clock.h 4KB
hal_uart.h 4KB
hal_uart.h 4KB
hal_digio.h 4KB
hal_digio.h 4KB
hal_mcu.h 3KB
hal_mcu.h 3KB
hal_rf_security.h 3KB
hal_rf_security.h 3KB
util.h 3KB
util.h 3KB
hal_joystick.h 3KB
hal_joystick.h 3KB
hal_timer_32k.h 3KB
hal_timer_32k.h 3KB
hal_button.h 3KB
hal_button.h 3KB
basic_rf_security.h 3KB
basic_rf_security.h 3KB
hal_led.h 3KB
hal_led.h 3KB
hal_assert.h 3KB
hal_assert.h 3KB
LCDdisplay.h 2KB
hal_rf_util.h 1KB
hal_rf_util.h 1KB
共 136 条
- 1
- 2
我虽横行却不霸道
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0