43 #include "rf_ble_cmd.h" 49 #define LOG_MODULE "BLE-RADIO" 50 #define LOG_LEVEL LOG_LEVEL_MAIN 52 #define CMD_GET_STATUS(X) (((rfc_radioOp_t *)X)->status) 56 static uint16_t tx_power = 0x3161;
60 static uint32_t ble_overrides[] = {
75 rfc_radioOp_t *cmd = (rfc_radioOp_t *)command;
78 LOG_ERR(
"rf_ble_cmd_send() could not send cmd. status: 0x%04X\n",
80 return RF_BLE_CMD_ERROR;
88 rfc_radioOp_t *cmd = (rfc_radioOp_t *)command;
90 LOG_ERR(
"rf_ble_cmd_wait() could not wait. status: 0x%04X\n",
92 return RF_BLE_CMD_ERROR;
100 rfc_CMD_RADIO_SETUP_t cmd;
105 cmd.txPower = tx_power;
106 cmd.pRegOverride = ble_overrides;
111 return RF_BLE_CMD_ERROR;
121 uint8_t *param, uint8_t *
output)
123 rfc_CMD_BLE_ADV_t *c = (rfc_CMD_BLE_ADV_t *)command;
125 memset(c, 0x00,
sizeof(rfc_CMD_BLE_ADV_t));
126 c->commandNo = CMD_BLE_ADV;
127 c->condition.rule = COND_NEVER;
128 c->whitening.bOverride = 0;
129 c->channel = channel;
130 c->pParams = (rfc_bleAdvPar_t *)param;
131 c->startTrigger.triggerType = TRIG_NOW;
132 c->pOutput = (rfc_bleAdvOutput_t *)output;
137 uint8_t adv_data_len, uint8_t *adv_data,
138 uint8_t scan_resp_data_len, uint8_t *scan_resp_data,
139 ble_addr_type_t own_addr_type, uint8_t *own_addr)
141 rfc_bleAdvPar_t *p = (rfc_bleAdvPar_t *)param;
143 memset(p, 0x00,
sizeof(rfc_bleAdvPar_t));
146 p->rxConfig.bAutoFlushIgnored = 1;
147 p->rxConfig.bAutoFlushCrcErr = 0;
148 p->rxConfig.bAutoFlushEmpty = 1;
149 p->rxConfig.bIncludeLenByte = 1;
150 p->rxConfig.bIncludeCrc = 0;
151 p->rxConfig.bAppendRssi = 1;
152 p->rxConfig.bAppendStatus = 1;
153 p->rxConfig.bAppendTimestamp = 1;
154 p->advConfig.advFilterPolicy = 0;
155 p->advConfig.bStrictLenFilter = 0;
156 p->advConfig.deviceAddrType = own_addr_type;
157 p->pDeviceAddress = (uint16_t *)own_addr;
158 p->advLen = adv_data_len;
159 p->scanRspLen = scan_resp_data_len;
160 p->pAdvData = adv_data;
161 p->pScanRspData = scan_resp_data;
162 p->endTrigger.triggerType = TRIG_NEVER;
169 uint8_t *
output, uint32_t start_time)
171 rfc_CMD_BLE_SLAVE_t *c = (rfc_CMD_BLE_SLAVE_t *)cmd;
173 memset(c, 0x00,
sizeof(rfc_CMD_BLE_SLAVE_t));
175 c->commandNo = CMD_BLE_SLAVE;
176 c->condition.rule = COND_NEVER;
177 c->whitening.bOverride = 0;
178 c->channel = channel;
179 c->pParams = (rfc_bleSlavePar_t *)params;
180 c->startTrigger.triggerType = TRIG_ABSTIME;
181 c->startTrigger.pastTrig = 0;
182 c->startTime = start_time;
183 c->pOutput = (rfc_bleMasterSlaveOutput_t *)output;
188 dataQueue_t *tx_queue, uint32_t access_address,
189 uint8_t crc_init_0, uint8_t crc_init_1,
190 uint8_t crc_init_2, uint32_t win_size,
191 uint32_t window_widening, uint8_t first_packet)
193 rfc_bleSlavePar_t *p = (rfc_bleSlavePar_t *)params;
197 p->rxConfig.bAutoFlushIgnored = 1;
198 p->rxConfig.bAutoFlushCrcErr = 1;
199 p->rxConfig.bAutoFlushEmpty = 1;
200 p->rxConfig.bIncludeLenByte = 1;
201 p->rxConfig.bIncludeCrc = 0;
202 p->rxConfig.bAppendRssi = 1;
203 p->rxConfig.bAppendStatus = 1;
204 p->rxConfig.bAppendTimestamp = 1;
208 p->seqStat.lastRxSn = 1;
209 p->seqStat.lastTxSn = 1;
210 p->seqStat.nextTxSn = 0;
211 p->seqStat.bFirstPkt = 1;
212 p->seqStat.bAutoEmpty = 0;
213 p->seqStat.bLlCtrlTx = 0;
214 p->seqStat.bLlCtrlAckRx = 0;
215 p->seqStat.bLlCtrlAckPending = 0;
220 p->accessAddress = access_address;
221 p->crcInit0 = crc_init_0;
222 p->crcInit1 = crc_init_1;
223 p->crcInit2 = crc_init_2;
224 p->timeoutTrigger.triggerType = TRIG_REL_START;
226 p->timeoutTime = (uint32_t)(10 * win_size);
228 p->timeoutTime = (uint32_t)(win_size + 2 * window_widening);
230 p->endTrigger.triggerType = TRIG_NEVER;
240 rfc_CMD_ADD_DATA_ENTRY_t cmd;
241 cmd.commandNo = CMD_ADD_DATA_ENTRY;
246 LOG_ERR(
"could not add entry to data queue. status: 0x%04X\n",
247 CMD_GET_STATUS(&cmd));
248 return RF_BLE_CMD_ERROR;
250 return RF_BLE_CMD_OK;
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...
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.
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.