ZHDA134 April 2026 CC1310 , CC1311P3 , CC1312PSIP , CC1312R , CC1312R7 , CC1314R10 , CC1350 , CC1352P , CC1352P7 , CC1352R , CC1354P10 , CC1354R10
如果我们要使用高级 RX 命令而不是标准 RX 命令接收标准数据包格式的数据包,该方案也可行,并且命令添加方式与第 2.1.3 节所述高级 TX 命令的添加方式一致。以下代码示例展示了如何使用高级 RX 命令接收标准数据包。此外,可以将 MAX_LENGTH 从 255 更改为 3,以启用数据包长度过滤。
1: //--------------------------------------------------------------------------------------------
2: // Receive Standard Packet Format with CMD_PROP_RX_ADV (1 Length Byte)
3: //--------------------------------------------------------------------------------------------
4: // Defines
5: #define DATA_ENTRY_HEADER_SIZE 8 // Constant header size of a Generic Data Entry
6: #define NUM_DATA_ENTRIES 2 // NOTE: Only two data entries supported
7: #define CRC 2 // 2 if .rxConf.bIncludeCrc = 0x1, 0 otherwise
8: #define RSSI 1 // 1 if .rxConf.bAppendRssi = 0x1, 0 otherwise
9: #define TIMESTAMP 4 // 4 if .rxConf.bAppendTimestamp = 0x1, 0 otherwise
10: #define STATUS 1 // 1 if .rxConf.bAppendStatus = 0x1, 0 otherwise
11: #define LENGTH_FIELD 1 // RF_cmdPropRx.rxConf.bIncludeHdr = 0x1
12: #define MAX_LENGTH 255 // Max length the radio will accept
13: #define NUM_APPENDED_BYTES LENGTH_FIELD + CRC + RSSI + TIMESTAMP + STATUS
14:
15: uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES - LENGTH_FIELD]; // Length stored in
16: uint8_t packetLength; // packetLength
17: static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
18:
19: static RF_Object rfObject;
20: static RF_Handle rfHandle;
21:
22: static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH,
23: NUM_APPENDED_BYTES)]__attribute__((aligned(4)));
24: static dataQueue_t dataQueue;
25: static rfc_dataEntryGeneral_t* currentDataEntry;
26: static uint8_t* packetDataPointer;
27: rfc_propRxOutput_t rxStatistics;
28: uint16_t crc16;
29: int8_t rssi;
30: uint32_t timestamp;
31: uint8_t status;
32:
33: void *mainThread(void *arg0)
34: {
35: RF_Params rfParams;
36: RF_Params_init(&rfParams);
37:
38: if(RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer),
39: NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES))
40: {
41: while(1);
42: }
43:
44: RF_cmdPropRxAdv.pktConf.bCrcIncHdr = 0x1; // Settings that must change to support
45: RF_cmdPropRxAdv.hdrConf.numHdrBits = 0x8; // the standard packet format
46: RF_cmdPropRxAdv.hdrConf.numLenBits = 0x8;
47:
48: RF_cmdPropRxAdv.pktConf.bRepeatOk = 0x1; // Application specific settings
49: RF_cmdPropRxAdv.pktConf.bRepeatNok = 0x1;
50: RF_cmdPropRxAdv.rxConf.bAutoFlushIgnored = 0x1;
51: RF_cmdPropRxAdv.rxConf.bAutoFlushCrcErr = 0x1;
52: RF_cmdPropRxAdv.maxPktLen = MAX_LENGTH;
53: RF_cmdPropRxAdv.pQueue = &dataQueue;
54:
55: // Settings to modify if going from a PHY that uses the standard RX command
56: // to use the advanced RX command
57: RF_cmdPropRxAdv.condition.rule = 0x1;
58: RF_cmdPropRxAdv.pktConf.bUseCrc = 0x1;
59: RF_cmdPropRxAdv.rxConf.bIncludeHdr = 0x1;
60: RF_cmdPropRxAdv.endTrigger.triggerType = 0x1;
61:
62: RF_cmdPropRxAdv.rxConf.bIncludeCrc = 0x1; // Optional bytes to append
63: RF_cmdPropRxAdv.rxConf.bAppendRssi = 0x1;
64: RF_cmdPropRxAdv.rxConf.bAppendTimestamp = 0x1;
65: RF_cmdPropRxAdv.rxConf.bAppendStatus = 0x1;
66:
67: RF_cmdPropRxAdv.pOutput = (uint8_t*)&rxStatistics; // Optional (for debug)
68:
69: rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup,
70: &rfParams);
71: RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
72: RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRxAdv, RF_PriorityNormal,
73: &callback, RF_EventRxEntryDone);
74: while(1);
75: }
76:77: //--------------------------------------------------------------------------------------------
78: // Callback for Receiving Standard Packet Format with CMD_PROP_RX_ADV (1 Length Byte)
79: //--------------------------------------------------------------------------------------------
80: void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
81: {
82: if(e & RF_EventRxEntryDone)
83: {
84: currentDataEntry = RFQueue_getDataEntry();
85:
86: packetLength = *(uint8_t*)(¤tDataEntry->data);
87: packetDataPointer = (uint8_t*)(¤tDataEntry->data + LENGTH_FIELD);
88:
89: memcpy(packet, packetDataPointer, (packetLength + NUM_APPENDED_BYTES - LENGTH_FIELD));
90:
91: crc16 = ((uint16_t)(packet[packetLength + 0] << 8) +
92: (uint16_t)(packet[packetLength + 1] << 0));
93:
94: rssi = packet[packetLength + 2];
95:
96: timestamp = ((uint32_t)(packet[packetLength + 3] << 0 ) +
97: (uint32_t)(packet[packetLength + 4] << 8 ) +
98: (uint32_t)(packet[packetLength + 5] << 16) +
99: (uint32_t)(packet[packetLength + 6] << 24));
100:
101: status = packet[packetLength + 7];
102:
103: RFQueue_nextEntry();
104: }
105: }