ZHDA134 April   2026 CC1310 , CC1311P3 , CC1312PSIP , CC1312R , CC1312R7 , CC1314R10 , CC1350 , CC1352P , CC1352P7 , CC1352R , CC1354P10 , CC1354R10

 

  1.   1
  2.   摘要
  3.   商标
  4. 1简介
  5. 2使用标准命令导出的 PHY 设置
    1. 2.1 标准数据包格式(1 个长度字节)
      1. 2.1.1 使用 CMD_PROP_TX 和标准数据包格式(1 个长度字节)的 TX
      2. 2.1.2 使用 CMD_PROP_RX 和标准数据包格式(1 个长度字节)的 RX
      3. 2.1.3 使用 CMD_PROP_TX_ADV 命令和标准数据包格式(1 个长度字节)的 TX
      4. 2.1.4 使用 CMD_PROP_RX_ADV 和标准数据包格式(1 个长度字节)的 RX
    2. 2.2 标准数据包格式(2 个长度字节)
      1. 2.2.1 使用 CMD_PROP_TX_ADV 和标准数据包格式(2 个长度字节)的 TX
      2. 2.2.2 使用 CMD_PROP_RX_ADV 和标准数据包格式(2 个长度字节)的 RX
  6. 3使用高级命令导出的 TX 和 RX 设置
    1. 3.1 高级数据包格式
      1. 3.1.1 使用 CMD_PROP_TX_ADV 和高级数据包格式的 TX
      2. 3.1.2 使用 CMD_PROP_RX_ADV 和高级数据包格式的 RX
    2. 3.2 标准数据包格式(1 个长度字节)
      1. 3.2.1 使用 CMD_PROP_TX_ADV 命令和标准数据包格式(1 个长度字节)的 TX
      2. 3.2.2 使用 CMD_PROP_RX_ADV 和标准数据包格式(1 个长度字节)的 RX
    3. 3.3 标准数据包格式(2 个长度字节)
      1. 3.3.1 使用 CMD_PROP_TX_ADV 和标准数据包格式(2 个长度字节)的 TX
      2. 3.3.2 使用 CMD_PROP_RX_ADV 和标准数据包格式(2 个长度字节)的 RX
  7. 4参考资料

使用 CMD_PROP_RX 和标准数据包格式(1 个长度字节)的 RX

为了能够使用 CMD_PROP_RX 接收中图 1-1 所示的标准数据包格式的数据包,可以使用以下代码(此处代码与原始 rfPacketRx 相比略有修改,以提高可读性并简化调试)。

1:  //---------------------------------------------------------------------------------------------
2:  // Receive Standard Packet Format with CMD_PROP_RX (1 Length Byte)
3:  //---------------------------------------------------------------------------------------------
4:
5:  // Defines
6:  #define DATA_ENTRY_HEADER_SIZE  8   // Constant header size of a Generic Data Entry
7:  #define NUM_DATA_ENTRIES        2   // NOTE: Only two data entries supported
8:  #define CRC                     2   // 2 if .rxConf.bIncludeCrc = 0x1, 0 otherwise
9:  #define RSSI                    1   // 1 if .rxConf.bAppendRssi = 0x1, 0 otherwise
10: #define TIMESTAMP               4   // 4 if .rxConf.bAppendTimestamp = 0x1, 0 otherwise
11: #define STATUS                  1   // 1 if .rxConf.bAppendStatus = 0x1, 0 otherwise
12: #define LENGTH_FIELD            1   // RF_cmdPropRx.rxConf.bIncludeHdr = 0x1
13: #define MAX_LENGTH              255 // Max length the radio will accept
14: #define NUM_APPENDED_BYTES      LENGTH_FIELD + CRC + RSSI + TIMESTAMP + STATUS
15:
16: uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - LENGTH_FIELD]; // Length stored in 
17: uint8_t packetLength;                                           // packetLength
18:
19: static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
20:
21: static RF_Object rfObject;
22: static RF_Handle rfHandle;
23:
24: static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH,
25:                                  NUM_APPENDED_BYTES)]__attribute__((aligned(4)));
26: static dataQueue_t dataQueue;
27: static rfc_dataEntryGeneral_t* currentDataEntry;
28: static uint8_t* packetDataPointer;
29: rfc_propRxOutput_t rxStatistics;
30: uint16_t crc16;
31: int8_t rssi;
32: uint32_t timestamp;
33: uint8_t status;
34:
35: void *mainThread(void *arg0)
36: {
37:     RF_Params rfParams;
38:     RF_Params_init(&rfParams);
39:
40:     if(RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), 
41:                            NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES))
42:     {
43:         while(1);
44:     }
45:
46:     RF_cmdPropRx.pktConf.bRepeatOk = 0x1; // Application specific settings
47:     RF_cmdPropRx.pktConf.bRepeatNok = 0x1;
48:     RF_cmdPropRx.rxConf.bAutoFlushIgnored = 0x1;
49:     RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 0x1;
50:     RF_cmdPropRx.maxPktLen = MAX_LENGTH;
51:     RF_cmdPropRx.pQueue = &dataQueue;
52:
53:     RF_cmdPropRx.rxConf.bIncludeCrc = 0x1; // Optional bytes to append
54:     RF_cmdPropRx.rxConf.bAppendRssi = 0x1;
55:     RF_cmdPropRx.rxConf.bAppendTimestamp = 0x1;
56:     RF_cmdPropRx.rxConf.bAppendStatus = 0x1;
57:
58:     RF_cmdPropRx.pOutput = (uint8_t*)&rxStatistics; // Optional (for debug)
59:
60:     rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, 
61:                        &rfParams);
62:     RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
63:     RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, 
64:               &callback, RF_EventRxEntryDone);
65:     while(1);
66: }
67:
68: //---------------------------------------------------------------------------------------------
69: // Callback for Receiving Standard Packet Format with CMD_PROP_RX (1 Length Byte)
70: //---------------------------------------------------------------------------------------------
71: void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
72: {
73:     if(e & RF_EventRxEntryDone)
74:     {
75:         currentDataEntry = RFQueue_getDataEntry();
76:
77:         packetLength = *(uint8_t*)(&currentDataEntry->data);
78:         packetDataPointer = (uint8_t*)(&currentDataEntry->data + LENGTH_FIELD);
79:
80:         memcpy(packet, packetDataPointer, (packetLength + NUM_APPENDED_BYTES - LENGTH_FIELD));
81:
82:         crc16 = ((uint16_t)(packet[packetLength + 0] << 8) +
83:                  (uint16_t)(packet[packetLength + 1] << 0));
84:
85:         rssi = packet[packetLength + 2];
86:
87:         timestamp = ((uint32_t)(packet[packetLength + 3] <<  0) +
88:                      (uint32_t)(packet[packetLength + 4] <<  8) +
89:                      (uint32_t)(packet[packetLength + 5] << 16) +
90:                      (uint32_t)(packet[packetLength + 6] << 24));
91:
92:         status = packet[packetLength + 7];
93:
94:         RFQueue_nextEntry();
95:     }
96: }

本代码示例未实现长度过滤功能,且所有可附加的可选字节均已添加。如果要接收的唯一数据包是图 2-1 中所示的数据包,可将 MAX_LENGTH 从 255 修改为 3,所有长度字节大于 3 的数据包将被自动丢弃(因为 rxConf.bAutoFlushIgnored =1)。