ZHDA134 April 2026 CC1310 , CC1311P3 , CC1312PSIP , CC1312R , CC1312R7 , CC1314R10 , CC1350 , CC1352P , CC1352P7 , CC1352R , CC1354P10 , CC1354R10
若要接收 2 个长度字节的标准数据包格式,需要修改相关设置,不能直接使用第 2.1.4 节中示例所示的设置。此外,需要更改一些定义和变量以及回调中的应用代码。需修改的代码位于第 11 行和第 12 行、第 15 行和第 16 行、第 46 行和第 47 行以及第 86-89 行。
1: //--------------------------------------------------------------------------------------------
2: // Receive Standard Packet Format with CMD_PROP_RX_ADV (2 Length Bytes)
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 2 // Changed from 1
12: #define MAX_LENGTH 4093 // Changed from 255
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: uint16_t packetLength; // Changed from uint8_t packetLength
17:
18: static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
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
45: // to support the standard format
46: RF_cmdPropRxAdv.hdrConf.numHdrBits = 0x10; // Changed from 0x8
47: RF_cmdPropRxAdv.hdrConf.numLenBits = 0x10; // Changed from 0x8
48:
49: RF_cmdPropRxAdv.pktConf.bRepeatOk = 0x1; // Application specific settings
50: RF_cmdPropRxAdv.pktConf.bRepeatNok = 0x1;
51: RF_cmdPropRxAdv.rxConf.bAutoFlushIgnored = 0x1;
52: RF_cmdPropRxAdv.rxConf.bAutoFlushCrcErr = 0x1;
53: RF_cmdPropRxAdv.maxPktLen = MAX_LENGTH;
54: RF_cmdPropRxAdv.pQueue = &dataQueue;
55:
56: // Settings to modify if going from a PHY that uses the standard RX command
57: // to use the advanced RX command
58: RF_cmdPropRxAdv.condition.rule = 0x1;
59: RF_cmdPropRxAdv.pktConf.bUseCrc = 0x1;
60: RF_cmdPropRxAdv.rxConf.bIncludeHdr = 0x1;
61: RF_cmdPropRxAdv.endTrigger.triggerType = 0x1;
62:
63: RF_cmdPropRxAdv.rxConf.bIncludeCrc = 0x1; // Optional bytes to append
64: RF_cmdPropRxAdv.rxConf.bAppendRssi = 0x1;
65: RF_cmdPropRxAdv.rxConf.bAppendTimestamp = 0x1;
66: RF_cmdPropRxAdv.rxConf.bAppendStatus = 0x1;
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: //--------------------------------------------------------------------------------------------
79: // Callback for Receiving Standard Packet Format with CMD_PROP_RX_ADV (2 Length Bytes)
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 = ((uint16_t)(*(uint8_t*)(¤tDataEntry->data + 1) << 8) |
87: (uint16_t)(*(uint8_t*)(¤tDataEntry->data + 0) << 0));
88: // Changed from
89: // packetLength = *(uint8_t*)(¤tDataEntry->data);
90:
91: packetDataPointer = (uint8_t*)(¤tDataEntry->data + LENGTH_FIELD);
92:
93: memcpy(packet, packetDataPointer,
94: (packetLength + NUM_APPENDED_BYTES - LENGTH_FIELD));
95:
96: crc16 = ((uint16_t)(packet[packetLength + 0] << 8) +
97: (uint16_t)(packet[packetLength + 1] << 0));
98:
99: rssi = packet[packetLength + 2];
100:
101: timestamp = ((uint32_t)(packet[packetLength + 3] << 0 ) +
102: (uint32_t)(packet[packetLength + 4] << 8 ) +
103: (uint32_t)(packet[packetLength + 5] << 16) +
104: (uint32_t)(packet[packetLength + 6] << 24));
105:
106: status = packet[packetLength + 7];
107:
108: RFQueue_nextEntry();
109: }
110: }