39 #include "contiki-conf.h"
41 #include "sys/clock.h"
49 #include "rf-core/api/ble_cmd.h"
50 #include "rf-core/api/common_cmd.h"
59 #define PRINTF(...) printf(__VA_ARGS__)
65 #define BLE_ADV_INTERVAL (CLOCK_SECOND * 5)
66 #define BLE_ADV_DUTY_CYCLE (CLOCK_SECOND / 10)
67 #define BLE_ADV_MESSAGES 10
70 #define BLE_ADV_TYPE_DEVINFO 0x01
71 #define BLE_ADV_TYPE_NAME 0x09
72 #define BLE_ADV_TYPE_MANUFACTURER 0xFF
73 #define BLE_ADV_NAME_BUF_LEN 32
74 #define BLE_ADV_PAYLOAD_BUF_LEN 64
75 #define BLE_UUID_SIZE 16
77 static unsigned char ble_params_buf[32] CC_ALIGN(4);
78 static uint8_t ble_mode_on = RF_BLE_IDLE;
79 static struct etimer ble_adv_et;
80 static uint8_t payload[BLE_ADV_PAYLOAD_BUF_LEN];
84 typedef struct default_ble_tx_power_s {
88 uint16_t temp_coeff:7;
89 } default_ble_tx_power_t;
91 static default_ble_tx_power_t tx_power = { 0x29, 0x00, 0x00, 0x00 };
94 static struct ble_beacond_config {
95 clock_time_t interval;
96 char adv_name[BLE_ADV_NAME_BUF_LEN];
97 } beacond_config = { .interval = BLE_ADV_INTERVAL };
100 static uint32_t ble_overrides[] = {
110 PROCESS(rf_ble_beacon_process,
"CC13xx / CC26xx RF BLE Beacon Process");
113 send_ble_adv_nc(
int channel, uint8_t *adv_payload,
int adv_payload_len)
116 rfc_CMD_BLE_ADV_NC_t cmd;
117 rfc_bleAdvPar_t *params;
119 params = (rfc_bleAdvPar_t *)ble_params_buf;
122 memset(&cmd, 0x00,
sizeof(cmd));
123 memset(ble_params_buf, 0x00,
sizeof(ble_params_buf));
126 cmd.commandNo = CMD_BLE_ADV_NC;
127 cmd.condition.rule = COND_NEVER;
128 cmd.whitening.bOverride = 0;
129 cmd.whitening.init = 0;
130 cmd.pParams = params;
131 cmd.channel = channel;
135 params->endTrigger.triggerType = TRIG_NEVER;
136 params->endTime = TRIG_NEVER;
139 params = (rfc_bleAdvPar_t *)ble_params_buf;
140 params->advLen = adv_payload_len;
141 params->pAdvData = adv_payload;
144 PRINTF(
"send_ble_adv_nc: Chan=%d CMDSTA=0x%08lx, status=0x%04x\n",
145 channel, cmd_status, cmd.status);
146 return RF_CORE_CMD_ERROR;
151 PRINTF(
"send_ble_adv_nc: Chan=%d CMDSTA=0x%08lx, status=0x%04x\n",
152 channel, cmd_status, cmd.status);
153 return RF_CORE_CMD_ERROR;
156 return RF_CORE_CMD_OK;
162 if(RF_BLE_ENABLED == 0) {
167 if(strlen(name) == 0 || strlen(name) >= BLE_ADV_NAME_BUF_LEN) {
171 memset(beacond_config.adv_name, 0, BLE_ADV_NAME_BUF_LEN);
172 memcpy(beacond_config.adv_name, name, strlen(name));
176 beacond_config.interval = interval;
183 if(RF_BLE_ENABLED == 0) {
184 return RF_CORE_CMD_ERROR;
187 if(ti_lib_chipinfo_supports_ble() ==
false) {
188 return RF_CORE_CMD_ERROR;
191 if(beacond_config.adv_name[0] == 0) {
192 return RF_CORE_CMD_ERROR;
195 ble_mode_on = RF_BLE_IDLE;
199 return RF_CORE_CMD_OK;
218 rfc_CMD_RADIO_SETUP_t cmd;
223 cmd.txPower.IB = tx_power.ib;
224 cmd.txPower.GC = tx_power.gc;
225 cmd.txPower.tempCoeff = tx_power.temp_coeff;
226 cmd.txPower.boost = tx_power.boost;
227 cmd.pRegOverride = ble_overrides;
232 PRINTF(
"rf_radio_setup: CMDSTA=0x%08lx, status=0x%04x\n",
233 cmd_status, cmd.status);
234 return RF_CORE_CMD_ERROR;
239 PRINTF(
"rf_radio_setup: wait, CMDSTA=0x%08lx, status=0x%04x\n",
240 cmd_status, cmd.status);
241 return RF_CORE_CMD_ERROR;
244 return RF_CORE_CMD_OK;
252 bool interrupts_disabled;
257 etimer_set(&ble_adv_et, beacond_config.interval);
261 if(ev == PROCESS_EVENT_EXIT) {
269 memset(payload, 0, BLE_ADV_PAYLOAD_BUF_LEN);
271 payload[p++] = BLE_ADV_TYPE_DEVINFO;
273 payload[p++] = 1 + strlen(beacond_config.adv_name);
274 payload[p++] = BLE_ADV_TYPE_NAME;
275 memcpy(&payload[p], beacond_config.adv_name,
276 strlen(beacond_config.adv_name));
277 p += strlen(beacond_config.adv_name);
279 for(i = 0; i < BLE_ADV_MESSAGES; i++) {
284 interrupts_disabled = ti_lib_int_master_disable();
285 ble_mode_on = RF_BLE_ACTIVE;
286 if(!interrupts_disabled) {
287 ti_lib_int_master_enable();
309 if(NETSTACK_RADIO.receiving_packet()) {
310 PRINTF(
"rf_ble_beacon_process: We were receiving\n");
323 PRINTF(
"rf_ble_beacon_process: rf_core_boot() failed\n");
334 if(rf_radio_setup() != RF_CORE_CMD_OK) {
335 PRINTF(
"cc26xx_rf_ble_beacon_process: Error entering BLE mode\n");
339 for(j = 37; j <= 39; j++) {
340 if(send_ble_adv_nc(j, payload, p) != RF_CORE_CMD_OK) {
341 PRINTF(
"cc26xx_rf_ble_beacon_process: Channel=%d, "
342 "Error advertising\n", j);
350 if(
rf_core_send_cmd(CMDR_DIR_CMD(CMD_STOP), &cmd_status) != RF_CORE_CMD_OK) {
351 PRINTF(
"cc26xx_rf_ble_beacon_process: status=0x%08lx\n", cmd_status);
367 interrupts_disabled = ti_lib_int_master_disable();
369 ble_mode_on = RF_BLE_IDLE;
371 if(!interrupts_disabled) {
372 ti_lib_int_master_enable();
376 if(i < BLE_ADV_MESSAGES - 1) {
381 interrupts_disabled = ti_lib_int_master_disable();
383 ble_mode_on = RF_BLE_IDLE;
385 if(!interrupts_disabled) {
386 ti_lib_int_master_enable();
uint8_t rf_ble_beacond_start()
Start the BLE advertisement/beacon daemon.
void rf_core_power_down()
Disable RFCORE clock domain in the MCU VD and turn off the RFCORE PD.
Header file with macros which rename TI CC26xxware functions.
Default definitions of C compiler quirk work-arounds.
Header file for the CC13xx/CC26xx BLE driver.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_EXIT()
Exit the currently running process.
void process_exit(struct process *p)
Cause a process to exit.
void rf_core_primary_mode_abort()
Abort the currently running primary radio op.
uint8_t rf_ble_is_active()
Check whether the BLE beacond is currently active.
void oscillators_switch_to_hf_xosc(void)
Performs the switch to the XOSC.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
Header file for the CC13xx/CC26xx RF core driver.
Header file for the Rime address representation
uint8_t rf_core_is_accessible()
Check whether the RF core is accessible.
#define NULL
The null pointer.
void oscillators_switch_to_hf_rc(void)
Switches MF and HF clock source to be the HF RC OSC.
void rf_ble_beacond_stop()
Stop the BLE advertisement/beacon daemon.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
uint8_t rf_core_boot()
Boot the RF Core.
uint_fast8_t rf_core_send_cmd(uint32_t cmd, uint32_t *status)
Sends a command to the RF core.
Header file for the Contiki process interface.
void process_start(struct process *p, process_data_t data)
Start a process.
void rf_ble_beacond_config(clock_time_t interval, const char *name)
Set the device name to use with the BLE advertisement/beacon daemon.
uint8_t rf_core_primary_mode_restore()
Abort the currently running primary radio op.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Header file for the CC13xx/CC26xx oscillator control.
void oscillators_request_hf_xosc(void)
Requests the HF XOSC as the source for the HF clock, but does not perform the actual switch...
void rf_core_init_radio_op(rfc_radioOp_t *op, uint16_t len, uint16_t command)
Prepare a buffer to host a Radio Op.
Include file for the Contiki low-layer network stack (NETSTACK)
uint_fast8_t rf_core_wait_cmd_done(void *cmd)
Block and wait for a Radio op to complete.
#define PROCESS_BEGIN()
Define the beginning of a process.