42 #include "sys/clock.h" 48 #include <ti/devices/DeviceFamily.h> 49 #include DeviceFamily_constructPath(driverlib/chipinfo.h) 50 #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) 51 #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) 53 #include <ti/drivers/rf/RF.h> 68 #define LOG_MODULE "Radio" 69 #define LOG_LEVEL LOG_LEVEL_NONE 71 #if RF_CONF_BLE_BEACON_ENABLE 75 BLE_ADV_CHANNEL_37 = (1 << 0),
76 BLE_ADV_CHANNEL_38 = (1 << 1),
77 BLE_ADV_CHANNEL_39 = (1 << 2),
79 BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 |
84 #define BLE_ADV_CHANNEL_MIN 37 85 #define BLE_ADV_CHANNEL_MAX 39 88 #define BLE_ADV_MAX_SIZE 31 91 #define BLE_ADV_INTERVAL (CLOCK_SECOND * 5) 92 #define BLE_ADV_DUTY_CYCLE (CLOCK_SECOND / 10) 93 #define BLE_ADV_MESSAGES 10 96 #define BLE_ADV_TYPE_DEVINFO 0x01 97 #define BLE_ADV_TYPE_NAME 0x09 98 #define BLE_ADV_TYPE_MANUFACTURER 0xFF 99 #define BLE_ADV_NAME_BUF_LEN BLE_ADV_MAX_SIZE 100 #define BLE_ADV_PAYLOAD_BUF_LEN 64 101 #define BLE_UUID_SIZE 16 105 uint8_t tx_buf[BLE_ADV_PAYLOAD_BUF_LEN] CC_ALIGN(4);
109 char adv_name[BLE_ADV_NAME_BUF_LEN];
115 clock_time_t ble_adv_interval;
122 static ble_beacond_t ble_beacond;
124 PROCESS(ble_beacond_process,
"RF BLE Beacon Daemon Process");
126 rf_ble_beacond_result_t
129 ble_adv_par.pDeviceAddress = (uint16_t *)
ble_addr_ptr();
132 RF_Params_init(&rf_params);
135 rf_params.nInactivityTimeout = 0;
137 ble_beacond.rf_handle = ble_open(&rf_params);
139 if(ble_beacond.rf_handle == NULL) {
140 return RF_BLE_BEACOND_ERROR;
143 return RF_BLE_BEACOND_OK;
146 rf_ble_beacond_result_t
149 rf_ble_beacond_result_t res;
151 res = RF_BLE_BEACOND_ERROR;
154 ble_beacond.ble_adv_interval = interval;
156 res = RF_BLE_BEACOND_OK;
160 const size_t name_len = strlen(name);
162 if((name_len == 0) || (name_len >= BLE_ADV_NAME_BUF_LEN)) {
163 ble_beacond.adv_name_len = name_len;
164 memcpy(ble_beacond.adv_name, name, name_len);
166 res = RF_BLE_BEACOND_OK;
173 rf_ble_beacond_result_t
176 if(ble_beacond.is_active) {
177 return RF_BLE_BEACOND_OK;
180 ble_beacond.is_active =
true;
184 return RF_BLE_BEACOND_OK;
187 rf_ble_beacond_result_t
190 if(!ble_beacond.is_active) {
191 return RF_BLE_BEACOND_OK;
194 ble_beacond.is_active =
false;
198 return RF_BLE_BEACOND_OK;
204 return (int8_t)ble_beacond.is_active;
207 rf_ble_beacond_result_t
212 if(!tx_power_in_range(dbm, ble_tx_power_table, ble_tx_power_table_size)) {
213 return RADIO_RESULT_INVALID_VALUE;
216 res = rf_set_tx_power(ble_beacond.rf_handle, ble_tx_power_table, dbm);
218 return (res == RF_RESULT_OK)
220 : RF_BLE_BEACOND_ERROR;
229 res = rf_get_tx_power(ble_beacond.rf_handle, ble_tx_power_table, &dbm);
231 if(res != RF_RESULT_OK) {
232 return RF_TxPowerTable_INVALID_DBM;
238 static rf_ble_beacond_result_t
239 ble_beacon_burst(uint8_t channels_bm, uint8_t *data, uint8_t len)
244 for(channel = BLE_ADV_CHANNEL_MIN; channel <= BLE_ADV_CHANNEL_MAX; ++channel) {
245 const uint8_t channel_bv = (1 << (channel - BLE_ADV_CHANNEL_MIN));
246 if((channel_bv & channels_bm) == 0) {
250 ble_adv_par.advLen = len;
251 ble_adv_par.pAdvData = data;
253 ble_cmd_beacon.channel = channel;
255 res = ble_sched_beacon(NULL, 0);
257 if(res != RF_RESULT_OK) {
258 return RF_BLE_BEACOND_ERROR;
262 return RF_BLE_BEACOND_OK;
273 etimer_set(&ble_beacond.ble_adv_et, ble_beacond.ble_adv_interval);
275 (ev == PROCESS_EVENT_EXIT));
277 if(ev == PROCESS_EVENT_EXIT) {
285 ble_beacond.tx_buf[len++] = (uint8_t)0x02;
286 ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_DEVINFO;
287 ble_beacond.tx_buf[len++] = (uint8_t)0x1A;
288 ble_beacond.tx_buf[len++] = (uint8_t)ble_beacond.adv_name_len;
289 ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_NAME;
291 memcpy(ble_beacond.tx_buf + len, ble_beacond.adv_name, ble_beacond.adv_name_len);
292 len += ble_beacond.adv_name_len;
298 ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len);
299 for(i = 1; i < BLE_ADV_MESSAGES; ++i) {
300 etimer_set(&ble_beacond.ble_adv_et, BLE_ADV_DUTY_CYCLE);
303 ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len);
311 rf_ble_beacond_result_t
314 return RF_BLE_BEACOND_DISABLED;
317 rf_ble_beacond_result_t
322 return RF_BLE_BEACOND_DISABLED;
325 rf_ble_beacond_result_t
328 return RF_BLE_BEACOND_DISABLED;
332 rf_ble_beacond_result_t
335 return RF_BLE_BEACOND_DISABLED;
344 rf_ble_beacond_result_t
348 return RF_BLE_BEACOND_DISABLED;
rf_ble_beacond_result_t rf_ble_beacond_start(void)
Start the BLE advertisement/beacon daemon.
#define PROCESS(name, strname)
Declare a process.
Header file of TX power functionality of CC13xx/CC26xx.
Header file for the CC13xx/CC26xx BLE Beacon Daemon.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file for the link-layer address representation
#define PROCESS_END()
Define the end of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
uint8_t * ble_addr_ptr(void)
Retrieve the pointer to where the BLE address is stored.
rf_ble_beacond_result_t rf_ble_beacond_config(clock_time_t interval, const char *name)
Set the device name to use with the BLE advertisement/beacon daemon.
int8_t rf_ble_get_tx_power(void)
Get TX power for BLE advertisements.
rf_ble_beacond_result_t rf_ble_beacond_stop(void)
Stop the BLE advertisement/beacon daemon.
void process_exit(struct process *p)
Cause a process to exit.
rf_ble_beacond_result_t rf_ble_set_tx_power(int8_t power)
Set TX power for BLE advertisements.
Header file of the CC13xx/CC26xx RF scheduler.
Header file for the CC13xx/CC26xx BLE address driver.
int8_t rf_ble_is_active(void)
Check whether the BLE beacond is currently active.
Header file for the Contiki process interface.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
rf_ble_beacond_result_t rf_ble_beacond_init(void)
Initialize the BLE advertisement/beacon daemon.
Header file of RF settings for CC13xx/CC26xx.
Include file for the Contiki low-layer network stack (NETSTACK)
Default definitions of C compiler quirk work-arounds.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Header file for the logging system
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_EXIT()
Exit the currently running process.