45 #include "rf_ble_cmd.h" 51 #define LOG_MODULE "BLE-RADIO" 52 #define LOG_LEVEL LOG_LEVEL_MAIN 54 #define CMD_GET_STATUS(X) (((rfc_radioOp_t *)X)->status) 58 static uint16_t tx_power = 0x3161;
63 uint32_t ble_overrides_common[] =
66 ADI_HALFREG_OVERRIDE(0,4,0xF,0x8),
72 HW_REG_OVERRIDE(0x4020, 0x7F00),
74 HW32_ARRAY_OVERRIDE(0x4004, 1),
93 uint32_t ble_overrides_1Mbps[] =
96 ADI_HALFREG_OVERRIDE(0,4,0xF,0x8),
98 HW_REG_OVERRIDE(0x6084, 0x05F8),
102 uint32_t ble_overrides_2Mbps[] =
105 ADI_HALFREG_OVERRIDE(0,4,0xF,0x8),
106 (uint32_t)0xFFFFFFFF,
109 uint32_t ble_overrides_coded[] =
112 ADI_HALFREG_OVERRIDE(0,4,0xF,0xF),
114 HW_REG_OVERRIDE(0x6088, 0x0018),
115 (uint32_t)0xFFFFFFFF,
118 static uint32_t ble_overrides[] = {
134 rfc_radioOp_t *cmd = (rfc_radioOp_t *)command;
137 LOG_ERR(
"rf_ble_cmd_send() could not send cmd. status: 0x%04X\n",
138 CMD_GET_STATUS(cmd));
139 return RF_BLE_CMD_ERROR;
141 return RF_BLE_CMD_OK;
147 rfc_radioOp_t *cmd = (rfc_radioOp_t *)command;
149 LOG_ERR(
"rf_ble_cmd_wait() could not wait. status: 0x%04X\n",
150 CMD_GET_STATUS(cmd));
151 return RF_BLE_CMD_ERROR;
153 return RF_BLE_CMD_OK;
160 rfc_CMD_BLE5_RADIO_SETUP_t cmd;
165 cmd.startTrigger.bEnaCmd = 0;
166 cmd.defaultPhy.mainMode = 1;
167 cmd.defaultPhy.coding = 1;
168 cmd.pRegOverrideCommon = ble_overrides_common;
169 cmd.pRegOverride1Mbps = ble_overrides_1Mbps;
170 cmd.pRegOverride2Mbps = ble_overrides_2Mbps;
171 cmd.pRegOverrideCoded = ble_overrides_coded;
173 rfc_CMD_RADIO_SETUP_t cmd;
179 cmd.pRegOverride = ble_overrides;
181 cmd.txPower = tx_power;
185 return RF_BLE_CMD_ERROR;
196 uint8_t *param, uint8_t *
output)
199 rfc_CMD_BLE5_ADV_t *c = (rfc_CMD_BLE5_ADV_t *)command;
201 memset(c, 0x00,
sizeof(rfc_CMD_BLE5_ADV_t));
203 c->commandNo = CMD_BLE5_ADV;
206 c->txPower = tx_power;
208 rfc_CMD_BLE_ADV_t *c = (rfc_CMD_BLE_ADV_t *)command;
210 memset(c, 0x00,
sizeof(rfc_CMD_BLE_ADV_t));
211 c->commandNo = CMD_BLE_ADV;
213 c->condition.rule = COND_NEVER;
214 c->whitening.bOverride = 0;
215 c->channel = channel;
216 c->pParams = (rfc_bleAdvPar_t *)param;
217 c->startTrigger.triggerType = TRIG_NOW;
218 c->pOutput = (rfc_bleAdvOutput_t *)output;
223 uint8_t adv_data_len, uint8_t *adv_data,
224 uint8_t scan_resp_data_len, uint8_t *scan_resp_data,
225 ble_addr_type_t own_addr_type, uint8_t *own_addr)
227 rfc_bleAdvPar_t *p = (rfc_bleAdvPar_t *)param;
229 memset(p, 0x00,
sizeof(rfc_bleAdvPar_t));
232 p->rxConfig.bAutoFlushIgnored = 1;
233 p->rxConfig.bAutoFlushCrcErr = 0;
234 p->rxConfig.bAutoFlushEmpty = 1;
235 p->rxConfig.bIncludeLenByte = 1;
236 p->rxConfig.bIncludeCrc = 0;
237 p->rxConfig.bAppendRssi = 1;
238 p->rxConfig.bAppendStatus = 1;
239 p->rxConfig.bAppendTimestamp = 1;
240 p->advConfig.advFilterPolicy = 0;
241 p->advConfig.bStrictLenFilter = 0;
242 p->advConfig.deviceAddrType = own_addr_type;
243 p->pDeviceAddress = (uint16_t *)own_addr;
244 p->advLen = adv_data_len;
245 p->scanRspLen = scan_resp_data_len;
246 p->pAdvData = adv_data;
247 p->pScanRspData = scan_resp_data;
248 p->endTrigger.triggerType = TRIG_NEVER;
255 uint8_t *
output, uint32_t start_time)
258 rfc_CMD_BLE5_INITIATOR_t *c = (rfc_CMD_BLE5_INITIATOR_t *)cmd;
260 memset(c, 0x00,
sizeof(rfc_CMD_BLE5_INITIATOR_t));
262 c->commandNo = CMD_BLE5_INITIATOR;
263 c->condition.rule = COND_NEVER;
264 c->whitening.bOverride = 0;
265 c->channel = channel;
266 c->pParams = (rfc_ble5InitiatorPar_t *)params;
267 c->startTrigger.triggerType = TRIG_ABSTIME;
268 c->startTime = start_time;
269 c->pOutput = (rfc_ble5ScanInitOutput_t *)output;
271 c->txPower = tx_power;
274 rfc_CMD_BLE_INITIATOR_t *c = (rfc_CMD_BLE_INITIATOR_t *)cmd;
276 memset(c, 0x00,
sizeof(rfc_CMD_BLE_INITIATOR_t));
278 c->commandNo = CMD_BLE_INITIATOR;
279 c->condition.rule = COND_NEVER;
280 c->whitening.bOverride = 0;
281 c->channel = channel;
282 c->pParams = (rfc_bleInitiatorPar_t *)params;
283 c->startTrigger.triggerType = TRIG_ABSTIME;
284 c->startTime = start_time;
285 c->pOutput = (rfc_bleInitiatorOutput_t *)output;
291 uint32_t initiator_time,
292 ble_addr_type_t own_addr_type, uint8_t *own_addr,
293 ble_addr_type_t peer_addr_type, uint8_t *peer_addr,
294 uint32_t connect_time, uint8_t *conn_req_data)
297 rfc_ble5InitiatorPar_t *p = (rfc_ble5InitiatorPar_t *)param;
298 p->backoffPar.bLastSucceeded = 0;
299 p->backoffPar.bLastFailed = 0;
300 p->maxWaitTimeForAuxCh = 0;
304 rfc_bleInitiatorPar_t *p = (rfc_bleInitiatorPar_t *)param;
307 p->rxConfig.bAutoFlushIgnored = 1;
308 p->rxConfig.bAutoFlushCrcErr = 0;
309 p->rxConfig.bAutoFlushEmpty = 1;
310 p->rxConfig.bIncludeLenByte = 1;
311 p->rxConfig.bIncludeCrc = 0;
312 p->rxConfig.bAppendRssi = 1;
313 p->rxConfig.bAppendStatus = 1;
314 p->rxConfig.bAppendTimestamp = 1;
317 p->initConfig.bUseWhiteList = 1;
318 p->initConfig.bDynamicWinOffset = 0;
319 p->initConfig.deviceAddrType = own_addr_type;
320 p->initConfig.peerAddrType = peer_addr_type;
321 p->initConfig.bStrictLenFilter = 1;
323 p->connectReqLen = 22;
324 p->pConnectReqData = conn_req_data;
325 p->pDeviceAddress = (uint16_t *)own_addr;
326 p->pWhiteList = (rfc_bleWhiteListEntry_t *)peer_addr;
327 p->connectTime = connect_time;
328 p->timeoutTrigger.triggerType = TRIG_REL_START;
329 p->timeoutTime = initiator_time;
330 p->endTrigger.triggerType = TRIG_NEVER;
337 uint8_t *
output, uint32_t start_time)
340 rfc_CMD_BLE5_SLAVE_t *c = (rfc_CMD_BLE5_SLAVE_t *)cmd;
342 memset(c, 0x00,
sizeof(rfc_CMD_BLE5_SLAVE_t));
344 c->commandNo = CMD_BLE5_SLAVE;
345 c->condition.rule = COND_NEVER;
346 c->whitening.bOverride = 0;
347 c->channel = channel;
348 c->pParams = (rfc_ble5SlavePar_t *)params;
349 c->startTrigger.triggerType = TRIG_ABSTIME;
350 c->startTime = start_time;
351 c->pOutput = (rfc_bleMasterSlaveOutput_t *)output;
353 c->phyMode.mainMode = 1;
354 c->phyMode.coding = 1;
355 c->txPower = tx_power;
358 rfc_CMD_BLE_SLAVE_t *c = (rfc_CMD_BLE_SLAVE_t *)cmd;
360 memset(c, 0x00,
sizeof(rfc_CMD_BLE_SLAVE_t));
362 c->commandNo = CMD_BLE_SLAVE;
363 c->condition.rule = COND_NEVER;
364 c->whitening.bOverride = 0;
365 c->channel = channel;
366 c->pParams = (rfc_bleSlavePar_t *)params;
367 c->startTrigger.triggerType = TRIG_ABSTIME;
368 c->startTrigger.pastTrig = 0;
369 c->startTime = start_time;
370 c->pOutput = (rfc_bleMasterSlaveOutput_t *)output;
376 dataQueue_t *tx_queue, uint32_t access_address,
377 uint8_t crc_init_0, uint8_t crc_init_1,
378 uint8_t crc_init_2, uint32_t win_size,
379 uint32_t window_widening, uint8_t first_packet)
382 rfc_ble5SlavePar_t *p = (rfc_ble5SlavePar_t *)params;
383 p->maxRxPktLen = 255;
384 p->maxLenLowRate = 0;
386 rfc_bleSlavePar_t *p = (rfc_bleSlavePar_t *)params;
390 p->rxConfig.bAutoFlushIgnored = 1;
391 p->rxConfig.bAutoFlushCrcErr = 1;
392 p->rxConfig.bAutoFlushEmpty = 1;
393 p->rxConfig.bIncludeLenByte = 1;
394 p->rxConfig.bIncludeCrc = 0;
395 p->rxConfig.bAppendRssi = 1;
396 p->rxConfig.bAppendStatus = 1;
397 p->rxConfig.bAppendTimestamp = 1;
401 p->seqStat.lastRxSn = 1;
402 p->seqStat.lastTxSn = 1;
403 p->seqStat.nextTxSn = 0;
404 p->seqStat.bFirstPkt = 1;
405 p->seqStat.bAutoEmpty = 0;
406 p->seqStat.bLlCtrlTx = 0;
407 p->seqStat.bLlCtrlAckRx = 0;
408 p->seqStat.bLlCtrlAckPending = 0;
413 p->accessAddress = access_address;
414 p->crcInit0 = crc_init_0;
415 p->crcInit1 = crc_init_1;
416 p->crcInit2 = crc_init_2;
417 p->timeoutTrigger.triggerType = TRIG_REL_START;
419 p->timeoutTime = (uint32_t)(10 * win_size);
421 p->timeoutTime = (uint32_t)(win_size + 2 * window_widening);
423 p->endTrigger.triggerType = TRIG_NEVER;
430 uint8_t *
output, uint32_t start_time)
433 rfc_CMD_BLE5_MASTER_t *c = (rfc_CMD_BLE5_MASTER_t *)cmd;
435 memset(c, 0x00,
sizeof(rfc_CMD_BLE5_MASTER_t));
437 c->commandNo = CMD_BLE5_MASTER;
438 c->condition.rule = COND_NEVER;
439 c->whitening.bOverride = 0;
440 c->channel = channel;
441 c->pParams = (rfc_ble5MasterPar_t *)params;
442 c->startTrigger.triggerType = TRIG_ABSTIME;
443 c->startTime = start_time;
444 c->pOutput = (rfc_bleMasterSlaveOutput_t *)output;
446 c->phyMode.mainMode = 1;
447 c->phyMode.coding = 1;
448 c->txPower = tx_power;
451 rfc_CMD_BLE_MASTER_t *c = (rfc_CMD_BLE_MASTER_t *)cmd;
453 memset(c, 0x00,
sizeof(rfc_CMD_BLE_MASTER_t));
455 c->commandNo = CMD_BLE_MASTER;
456 c->condition.rule = COND_NEVER;
457 c->whitening.bOverride = 0;
458 c->channel = channel;
459 c->pParams = (rfc_bleMasterPar_t *)params;
460 c->startTrigger.triggerType = TRIG_ABSTIME;
461 c->startTime = start_time;
462 c->pOutput = (rfc_bleMasterSlaveOutput_t *)output;
468 dataQueue_t *tx_queue, uint32_t access_address,
469 uint8_t crc_init_0, uint8_t crc_init_1,
470 uint8_t crc_init_2, uint8_t first_packet)
473 rfc_ble5MasterPar_t *p = (rfc_ble5MasterPar_t *)params;
474 p->maxRxPktLen = 255;
475 p->maxLenLowRate = 0;
477 rfc_bleMasterPar_t *p = (rfc_bleMasterPar_t *)params;
481 p->rxConfig.bAutoFlushIgnored = 1;
482 p->rxConfig.bAutoFlushCrcErr = 1;
483 p->rxConfig.bAutoFlushEmpty = 1;
484 p->rxConfig.bIncludeLenByte = 1;
485 p->rxConfig.bIncludeCrc = 0;
486 p->rxConfig.bAppendRssi = 1;
487 p->rxConfig.bAppendStatus = 1;
488 p->rxConfig.bAppendTimestamp = 1;
492 p->seqStat.lastRxSn = 1;
493 p->seqStat.lastTxSn = 1;
494 p->seqStat.nextTxSn = 0;
495 p->seqStat.bFirstPkt = 1;
496 p->seqStat.bAutoEmpty = 0;
497 p->seqStat.bLlCtrlTx = 0;
498 p->seqStat.bLlCtrlAckRx = 0;
499 p->seqStat.bLlCtrlAckPending = 0;
503 p->accessAddress = access_address;
504 p->crcInit0 = crc_init_0;
505 p->crcInit1 = crc_init_1;
506 p->crcInit2 = crc_init_2;
507 p->endTrigger.triggerType = TRIG_REL_START;
508 p->endTime = (uint32_t)15 * 4000;
518 rfc_CMD_ADD_DATA_ENTRY_t cmd;
519 cmd.commandNo = CMD_ADD_DATA_ENTRY;
524 LOG_ERR(
"could not add entry to data queue. status: 0x%04X\n",
525 CMD_GET_STATUS(&cmd));
526 return RF_BLE_CMD_ERROR;
528 return RF_BLE_CMD_OK;
void rf_ble_cmd_create_master_params(uint8_t *params, dataQueue_t *rx_queue, dataQueue_t *tx_queue, uint32_t access_address, uint8_t crc_init_0, uint8_t crc_init_1, uint8_t crc_init_2, uint8_t first_packet)
Creates BLE radio command parameters that are used to set up BLE connection event on the radio core...
void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue, uint8_t adv_data_len, uint8_t *adv_data, uint8_t scan_resp_data_len, uint8_t *scan_resp_data, ble_addr_type_t own_addr_type, uint8_t *own_addr)
Creates BLE radio command parameters that are used to enable BLE advertisement on the radio core...
void rf_ble_cmd_create_initiator_params(uint8_t *param, dataQueue_t *rx_queue, uint32_t initiator_time, ble_addr_type_t own_addr_type, uint8_t *own_addr, ble_addr_type_t peer_addr_type, uint8_t *peer_addr, uint32_t connect_time, uint8_t *conn_req_data)
Creates BLE radio command parameters that are used to set up BLE initiation event on the radio core...
unsigned short rf_ble_cmd_send(uint8_t *command)
Sends a BLE radio command to the radio.
Header file for the CC13xx/CC26xx RF core driver.
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
BLE commands for the TI CC26xx BLE radio.
void rf_ble_cmd_create_initiator_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up BLE initiation event when sent to the radio core...
unsigned short rf_ble_cmd_setup_ble_mode(void)
Initializes the radio core to be used as a BLE radio.
void rf_ble_cmd_create_slave_params(uint8_t *params, dataQueue_t *rx_queue, dataQueue_t *tx_queue, uint32_t access_address, uint8_t crc_init_0, uint8_t crc_init_1, uint8_t crc_init_2, uint32_t win_size, uint32_t window_widening, uint8_t first_packet)
Creates BLE radio command parameters that are used to setup a single BLE connection event on the radi...
void rf_core_init_radio_op(rfc_radioOp_t *op, uint16_t len, uint16_t command)
Prepare a buffer to host a Radio Op.
unsigned short rf_ble_cmd_wait(uint8_t *command)
Waits for a running BLE radio command to be finished.
unsigned short rf_ble_cmd_add_data_queue_entry(dataQueue_t *q, uint8_t *e)
Adds a data buffer to a BLE transmission queue.
uint_fast8_t rf_core_send_cmd(uint32_t cmd, uint32_t *status)
Sends a command to the RF core.
void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up a single BLE connection event when sent to the rad...
Header file for the logging system
void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel, uint8_t *param, uint8_t *output)
Creates a BLE radio command structure that enables BLE advertisement when sent to the radio core...
uint_fast8_t rf_core_wait_cmd_done(void *cmd)
Block and wait for a Radio op to complete.
void rf_ble_cmd_create_master_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time)
Creates a BLE radio command structure that sets up BLE connection event when sent to the radio core...