将 CC1310 配置为 4Mbps 的速率, 编写 no-RTOS 代码, 执行 下面的 周期性 操作:
(1) 休眠 500ms 以后, 执行 无线发送状态的 配置( RF_tran_init )
(2) 然后读取 传感器信息(16个字节), 执行 无线发送 ( RF_tran_op )
(3) 启动 无线发送的 操作了, 也启动 定时器 工作; ( wait_WLpkg_tran )
(4) 如果 在1ms 内就执行了 tx_callback 中断, 则进入 下面的步骤(6);
(5) 如果 定时器 已经计时超过 1ms 了, 也跳出 无线发送的 等待过程, 进入 下面的步骤(6)
(6) 判断 是否 已经执行了 5次 上面的 操作; 如果少于 5次, 则跳转到(2)接着执行; 否则 进入(7)
(7) 执行 休眠 500ms
附件 rf_tran 4Mbps.c 包含上面的 具体代码; 也包含 简化以后的 main() 函数。
对于 main() 函数中, 也调用了 rf_recv 功能 (对应的代码, 参见 附件 rf_recv.c)
每隔500ms, CC1310读取 传感器信息, 无线发送; 执行 5次。
使用 侦听器 (另外一个 CC1310 单板, 配置为 无线接收状态), 获取上述 5次无线发送的 信息, 也用定时器 获取 5个无线包 之间的 间隔。
刚开始工作的时候, 无线发送过程中, tx_callback 中断处理都很正常; 对于 5个无线包的 4个间隔, 都是 2.4ms 附近;
但是, 工作一段时间以后, 发送无线包的间隔, 都是 3.1ms 附近 ---- 没有得到 tx_callback 中断处理; 那个 1ms 的定时器, 将 代码 '拽出了' 持续等待 tx_callback 中断的 那种状态。
备注: 侦听器 始终可以 完整 获取到 每个周期内的 5个 无线包。即, 无论是否 tx_callback 中断处理, 无线发送的操作, 都是顺利完成了, 可以被 无线接收到。
有时候, 持续工作十几个小时, 才出现上述 3.1ms 的问题; 有时候, 半个小时以后就出现 上述问题了。
出现上述问题以后, 不能自动恢复, 这个问题 会持续存在。 只有将 单板掉电重启, 才能恢复正常。 备注:上面的操作(1), 对 CC1310 执行 全部的、配置 4Mbps、执行 无线发送的、 初始化操作
上述 rf_tran 4Mbps.c 文件中, 将 CC1310 配置为 4Mbps 速率的代码, 都是参照 TI 例程 rfPacketErrorRate, 相应 '摘取' 得到。
请帮忙指点一下, 是否上述 代码中, 漏掉了 某个关键的 处理, 然后 导致 某种状态下, 触发了某种异常情况, 于是 无线包 成功发送了, 却 没有 能够 产生 tx_callback 中断?
#include <stdlib.h> #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> #include "Board.h" #include "RFQueue.h" #include <smartrf_settings/smartrf_settings.h> #include <smartrf_settings/smartrf_settings_predefined.h> /***** Defines *****/ #define NUM_DATA_ENTRIES 1 #define NUM_APPENDED_BYTES 0 // -- For the HS command (6 bytes total): packet length (2 bytes) + Timestamp (4 bytes) // -- For other Sub-1 GHz commands (6 bytes total): packet length (1 bytes) + Timestamp (4 bytes) + status (1 byte) // -- For 200 Kbps IEEE 802.15.4g commands (5 bytes total): Timestamp (4 bytes) + status (1 byte) // -- For BLE (9 bytes total), but max payload is well under the max length supported by the sub-1 phys: Timestamp (4 bytes) + status (1 byte) + RSSI (1 byte) + CRC (3 bytes) /***** Prototypes *****/ static void tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; static volatile RF_CmdHandle cmdHandle; static uint8_t txDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; /* TX queue or RF Core to read data from */ static dataQueue_t txDataQueue; static rfc_dataEntryGeneral_t* tx_currentDataEntry; static uint8_t *pPacket; /* Runs the transmitting part of the test application and returns a result. */ void RF_tran_init (uint16_t freq_MHz, uint8_t N_dBm) { RF_Params rfParams; RF_Params_init(&rfParams); if( RFQueue_defineQueue(&txDataQueue, txDataEntryBuffer, sizeof(txDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES) ) { //while(true); // Failed to allocate space for all data entries } RF_cmdTxHS.pQueue = &txDataQueue; RF_cmdTxHS.startTrigger.triggerType = TRIG_NOW; //TRIG_ABSTIME RF_cmdTxHS.startTrigger.pastTrig = 1; RF_cmdTxHS.startTime = 0; //---START //copy from ZhuYanjie // RF_cmdTxHS.pNextOp=(rfc_radioOp_t *)&RF_cmdRxHS; RF_cmdTxHS.pktConf.bCheckQAtEnd=0; RF_cmdTxHS.pktConf.bFsOff=0; RF_cmdTxHS.pktConf.bUseCrc=1; RF_cmdTxHS.pktConf.bVarLen=1; RF_cmdTxHS.condition.rule=COND_STOP_ON_FALSE; //----END //copy from ZhuYanjie //smartrf_settings_predefined.c //-10, 0, 1, 2, 3.....11, 12, 13((12.5 dBm rounded to integer), 14('14' requires CCFG_FORCE_VDDR_HH= 1) RF_cmdRadioSetup_hsm.txPower = RF_TxPowerTable_findValue((RF_TxPowerTable_Entry *)RF_PROP_txPowerTable, N_dBm).rawValue; { uint8_t i = 0; do { if ((pOverrides_fsk[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_fsk[i] = (uint32_t)0x00FB88A3; //pOverrides_fsk[i] = (uint32_t)0x000188A3; //pOverrides_fsk[i] = (uint32_t)0x000388A3; } } while ((pOverrides_fsk[i++] != 0xFFFFFFFF)); i = 0; do { if ((pOverrides_lrm[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_lrm[i] = (uint32_t)0x00FB88A3; //pOverrides_lrm[i] = (uint32_t)0x000188A3; //pOverrides_lrm[i] = (uint32_t)0x000388A3; } } while ((pOverrides_lrm[i++] != 0xFFFFFFFF)); i = 0; do { if ((pOverrides_sl_lr[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_sl_lr[i] = (uint32_t)0x00FB88A3; //pOverrides_sl_lr[i] = (uint32_t)0x000188A3;//pOverrides_sl_lr[i] = (uint32_t)0x000388A3; } } while ((pOverrides_sl_lr[i++] != 0xFFFFFFFF)); i = 0; do { if ((pOverrides_ook[i] & 0x0000FFFF) == 0x000088A3) { pOverrides_ook[i] = (uint32_t)0x00FB88A3; } } while ((pOverrides_ook[i++] != 0xFFFFFFFF)); } //RfSetup_Hsm //4Mbps rfHandle = RF_open(&rfObject, &RF_prop_hsm, (RF_RadioSetup*)&RF_cmdRadioSetup_hsm, &rfParams); // Set the frequency RF_cmdFs_preDef.frequency = freq_MHz; //0x393, 915M //0x364, 868M //915, 903, 907, 911, 919, 923, 927 RF_cmdFs_preDef.fractFreq = 0; //fractFreq RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs_preDef, RF_PriorityNormal, NULL, 0); } void RF_tran_op (uint8_t sn8b, uint16_t pkg_Len, uint8_t *ptr) { tx_currentDataEntry = (rfc_dataEntryGeneral_t*)&txDataEntryBuffer; pPacket = &tx_currentDataEntry->data; pPacket[0] = 0; pPacket[1] = sn8b; tx_currentDataEntry->length= (pkg_Len +2) ; memcpy( &pPacket[2], ptr, pkg_Len ); cmdHandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxHS, RF_PriorityNormal, &tx_callback, 0); delta_txTrig_txOK++; if(pkg_Len< 100) wait_WLpkg_tran( 1 ); else wait_WLpkg_tran( 6 ); //1022-bytes, wl_pkg tran, 3.4 Mbps } void RF_tran_close () { RF_close(rfHandle); } void tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { cur_RF_EventMask = e ; if(e & RF_EventLastCmdDone) { if(delta_txTrig_txOK>0) delta_txTrig_txOK--; } } /* HIGHSPEED RX FRAME (HSM) * +-------------------------------------------------------------+ * |_LEN_|_____________PAYLOAD(sz)__________|_TIMESTAMP_|_STATUS_| * | |_SERIAL_|__________DATA___________| | | * |2B |2B | Upto 252B | 4B | 1B | * +-------------------------------------------------------------+ * Note that HSM mode can transfer up to 4KB of payload but are hard-coded for a maximum of 254B in this example #define RX_FRAME_HSM_OFFSET_LEN 0 #define RX_FRAME_HSM_OFFSET_SERIAL 2 #define RX_FRAME_HSM_OFFSET_DATA 4 #define RX_FRAME_HSM_OFFSET_TIMESTAMP(sz) (RX_FRAME_HSM_OFFSET_SERIAL + sz) */ void wait_WLpkg_tran( uint8_t N_ms ) { Timer_start(); cnt_N_ms= 0; while( (cnt_N_ms< N_ms) && (delta_txTrig_txOK>0) ) {} Timer_stop(); } void *mainThread(void *arg0) { uint8_t buf[16]; uint8_t curPat; //............. //other code //............. while(1) { usleep( GAP_500ms ); //------------//------------//------------//------------//------------ // WL_tran //------------//------------//------------//------------//------------ RF_tran_init ( curWL_freq, curWL_dBm ); for(curPat=0; curPat<5; curPat++) { // get_sensor_info ( &buf[0] ) ; RF_tran_op ( curPat, 16, &buf[0] ); //2+16 } RF_tran_close ( ); //------------//------------//------------//------------//------------ // WL_recv //------------//------------//------------//------------//------------ RF_recv_init ( curWL_freq ); //1.46ms wait_WLpkg_recv( 5 ); //other code RF_recv_close ( ); }//---- while(1) ----// }
#include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> #include "Board.h" #include "RFQueue.h" #include <smartrf_settings/smartrf_settings.h> #include <smartrf_settings/smartrf_settings_predefined.h> #include "cap_self.h" /***** Defines *****/ #define NUM_DATA_ENTRIES 2 // NOTE: Only two data entries supported at the moment #define NUM_APPENDED_BYTES 6 // -- For the HS command (6 bytes total): packet length (2 bytes) + Timestamp (4 bytes) // -- For other Sub-1 GHz commands (6 bytes total): packet length (1 bytes) + Timestamp (4 bytes) + status (1 byte) // -- For 200 Kbps IEEE 802.15.4g commands (5 bytes total): Timestamp (4 bytes) + status (1 byte) // -- For BLE (9 bytes total), but max payload is well under the max length supported by the sub-1 phys: Timestamp (4 bytes) + status (1 byte) + RSSI (1 byte) + CRC (3 bytes) #define ABORT_GRACEFUL 1 // Option for the RF cancel command #define ABORT_ABRUPT 0 // Option for the RF cancel command /***** Prototypes *****/ static void rx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ uint16_t payload_sz = 0; static uint16_t* crcOk; static int8_t* rssi; static RF_Object rfObject; static RF_Handle rfHandle; static RF_CmdHandle rxCmdHndl = 0; // Handle needed to abort the RX command //rockywjj-note: must use it. static volatile RF_RatConfigCompare ratCompareConfig; static volatile RF_RatHandle ratHandle = RF_ALLOC_ERROR; static volatile RF_Stat ratStatus; static volatile uint16_t nRxPkts = 0, nMissPkts = 0, nExpPkts = 0; #pragma DATA_ALIGN (rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; static dataQueue_t rxDataQueue; rfc_dataEntryGeneral_t* currentDataEntry; rfc_hsRxOutput_t rxStatistics_hs; // Output structure for CMD_HS_RX rfc_propRxOutput_t rxStatistics_prop; // Output structure for CMD_PROP_RX void RF_recv_init ( uint16_t freq_MHz ) { RF_Params rfParams; RF_Params_init(&rfParams); if( RFQueue_defineQueue(&rxDataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { //while(true); // Failed to allocate space for all data entries } RF_RatConfigCompare_init((RF_RatConfigCompare *)&ratCompareConfig); //ratCompareConfig.callback = (RF_RatCallback)&rx_timeoutCb; ratCompareConfig.channel = RF_RatChannelAny; RF_cmdPropRx.pQueue = &rxDataQueue; RF_cmdPropRx.pOutput = (uint8_t*)&rxStatistics_prop; RF_cmdPropRx.maxPktLen = MAX_LENGTH; RF_cmdPropRx.pktConf.bRepeatOk = 1; RF_cmdPropRx.pktConf.bRepeatNok = 1; RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1; RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; RF_cmdPropRx.rxConf.bAppendTimestamp = 1; RF_cmdPropRx.rxConf.bAppendStatus = 0x1, RF_cmdRxHS.pOutput = &rxStatistics_hs; RF_cmdRxHS.pQueue = &rxDataQueue; RF_cmdRxHS.maxPktLen = MAX_LENGTH; RF_cmdRxHS.pktConf.bRepeatOk = 1; RF_cmdRxHS.pktConf.bRepeatNok = 1; RF_cmdRxHS.rxConf.bAutoFlushCrcErr = 1; RF_cmdRxHS.rxConf.bAppendTimestamp = 1; //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M RF_cmdPropRadioDivSetup_fsk.txPower = 0xA73A; //RF_cmdPropRadioDivSetup_fsk.txPower = 0x00C6; //RF_cmdPropRadioDivSetup_fsk.txPower = 0x00C9; RF_cmdPropRadioDivSetup_lrm.txPower = 0xA73A; //RF_cmdPropRadioDivSetup_lrm.txPower = 0x00C6; //RF_cmdPropRadioDivSetup_lrm.txPower = 0x00C9; RF_cmdPropRadioDivSetup_sl_lr.txPower = 0xA73A; //RF_cmdPropRadioDivSetup_sl_lr.txPower = 0x00C6; //RF_cmdPropRadioDivSetup_sl_lr.txPower = 0x00C9; { uint8_t i = 0; do { if ((pOverrides_fsk[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_fsk[i] = (uint32_t)0x00FB88A3; //pOverrides_fsk[i] = (uint32_t)0x000188A3; //pOverrides_fsk[i] = (uint32_t)0x000388A3; } } while ((pOverrides_fsk[i++] != 0xFFFFFFFF)); i = 0; do { if ((pOverrides_lrm[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_lrm[i] = (uint32_t)0x00FB88A3; //pOverrides_lrm[i] = (uint32_t)0x000188A3; //pOverrides_lrm[i] = (uint32_t)0x000388A3; } } while ((pOverrides_lrm[i++] != 0xFFFFFFFF)); i = 0; do { if ((pOverrides_sl_lr[i] & 0x0000FFFF) == 0x000088A3) { //RangeExtender_Dis //RangeExtender_En, 868M //RangeExtender_En, 915M pOverrides_sl_lr[i] = (uint32_t)0x00FB88A3; //pOverrides_sl_lr[i] = (uint32_t)0x000188A3;//pOverrides_sl_lr[i] = (uint32_t)0x000388A3; } } while ((pOverrides_sl_lr[i++] != 0xFFFFFFFF)); } //RfSetup_Hsm //4Mbps rfHandle = RF_open(&rfObject, &RF_prop_hsm, (RF_RadioSetup*)&RF_cmdRadioSetup_hsm, &rfParams); // Set the frequency RF_cmdFs_preDef.frequency = freq_MHz; //0x393, 915M //0x364, 868M //915, 903, 907, 911, 919, 923, 927 RF_cmdFs_preDef.fractFreq = 0; //fractFreq RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs_preDef, RF_PriorityNormal, NULL, 0); // Enter RX mode and stay forever in RX // RfSetup_Hsm rxCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdRxHS, RF_PriorityNormal, &rx_callback, RF_EventRxEntryDone); crcOk = &rxStatistics_hs.nRxOk; rssi = &rxStatistics_hs.lastRssi; *crcOk = 0; *rssi = 0; } void RF_recv_close ( ) { (void)RF_ratDisableChannel(rfHandle, ratHandle); // Stop the RAT Compare ratHandle = RF_ALLOC_ERROR; (void)RF_cancelCmd(rfHandle, rxCmdHndl, ABORT_ABRUPT); // Force abort (void)RF_pendCmd(rfHandle, rxCmdHndl, 0); RF_close(rfHandle); } void rx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { /* Get current unhandled data entry, point to next entry */ currentDataEntry = RFQueue_getDataEntry(); RFQueue_nextEntry(); { payload_sz = ( ((*(uint8_t*)(¤tDataEntry->data + 1)) << 8) | (*(uint8_t*)(¤tDataEntry->data ))); //Num of [ser2B, payload] pktSeqNum16b = ( ((*(uint8_t*)(¤tDataEntry->data + 2)) << 8) | (*(uint8_t*)(¤tDataEntry->data + 3))); //val of ser2B CAP_pkg_rssi = (0xFF - *rssi); *rssi = 0; pkg_crcOk = *crcOk; *crcOk = 0; memcpy( WL_CMD_58B, (¤tDataEntry->data+4), (payload_sz-2) ); } packetReceived = true; } } uint8_t free_air_rssi(void) { uint8_t u_rssi; u_rssi = 0xFF - RF_getRssi(rfHandle); //(0xFF - *rssi); *rssi = 0; return u_rssi; } /* HIGHSPEED RX FRAME (HSM) * +-------------------------------------------------------------+ * |_LEN_|_____________PAYLOAD(sz)__________|_TIMESTAMP_|_STATUS_| * | |_SERIAL_|__________DATA___________| | | * |2B |2B | Upto 252B | 4B | 1B | * +-------------------------------------------------------------+ * Note that HSM mode can transfer up to 4KB of payload but are hard-coded for a maximum of 254B in this example #define RX_FRAME_HSM_OFFSET_LEN 0 #define RX_FRAME_HSM_OFFSET_SERIAL 2 #define RX_FRAME_HSM_OFFSET_DATA 4 #define RX_FRAME_HSM_OFFSET_TIMESTAMP(sz) (RX_FRAME_HSM_OFFSET_SERIAL + sz) */ // TimeStamp-4B, UNIT-0.25us (4M) // // ( 256-2) byte, 0.89ms ---> 2.3 Mbps (2.283) // ( 512-2) byte, 1.42ms ---> 2.9 Mbps (2.903) // (1024-2) byte, 1.42ms ---> 3.4 Mbps (3.351)