48#define LOG_MODULE "RADIO"
49#define LOG_LEVEL LOG_LEVEL_MAIN
51static uint16_t adv_interval;
52static ble_adv_type_t adv_type;
53static ble_addr_type_t adv_own_addr_type;
54static uint8_t adv_channel_map;
55static uint16_t buffer_size = 0;
57static uint16_t scan_interval;
58static uint16_t scan_window;
59static ble_scan_type_t scan_type;
60static ble_addr_type_t scan_own_addr_type;
62static ble_addr_type_t initiator_peer_addr_type;
63static uint8_t initiator_peer_addr[BLE_ADDR_SIZE];
65static uint16_t connection_interval;
66static uint16_t connection_latency;
67static uint16_t connection_timeout;
72 int result = ble_hal.
reset();
73 return result == BLE_RESULT_OK;
77send(
const void *payload,
unsigned short payload_len)
80 res = ble_hal.send((
void *)payload, payload_len);
81 LOG_DBG(
"ble-mode send() %d bytes\n", payload_len);
82 if(res == BLE_RESULT_OK) {
85 LOG_ERR(
"ble-mode send() error: %d\n", res);
114 *value = BLE_DATA_CHANNEL_MIN;
117 *value = BLE_DATA_CHANNEL_MAX;
119 case RADIO_CONST_BLE_BUFFER_SIZE:
120 if(buffer_size == 0) {
123 memcpy(value, &buffer_size, 2);
125 case RADIO_CONST_BLE_BUFFER_AMOUNT:
128 case RADIO_PARAM_BLE_CONN_INTERVAL:
129 ble_hal.read_connection_interval(0, (
unsigned int *)value);
140 case RADIO_PARAM_BLE_ADV_INTERVAL:
141 if((value > BLE_ADV_INTERVAL_MAX) || (value < BLE_ADV_INTERVAL_MIN)) {
144 adv_interval = (uint16_t)value;
146 case RADIO_PARAM_BLE_ADV_TYPE:
149 case RADIO_PARAM_BLE_ADV_OWN_ADDR_TYPE:
150 adv_own_addr_type = value;
152 case RADIO_PARAM_BLE_ADV_CHANNEL_MAP:
153 adv_channel_map = value;
155 case RADIO_PARAM_BLE_ADV_ENABLE:
159 adv_own_addr_type, adv_channel_map);
163 case RADIO_PARAM_BLE_SCAN_INTERVAL:
164 if((value > BLE_SCAN_INTERVAL_MAX) || (value < BLE_SCAN_INTERVAL_MIN)) {
167 scan_interval = (uint16_t)value;
169 case RADIO_PARAM_BLE_SCAN_WINDOW:
170 if((value > BLE_SCAN_INTERVAL_MAX) || (value < BLE_SCAN_INTERVAL_MIN)) {
173 scan_window = (uint16_t)value;
175 case RADIO_PARAM_BLE_SCAN_TYPE:
178 case RADIO_PARAM_BLE_SCAN_OWN_ADDR_TYPE:
179 scan_own_addr_type = value;
181 case RADIO_PARAM_BLE_SCAN_ENABLE:
184 scan_window, scan_own_addr_type);
188 case RADIO_PARAM_BLE_PEER_ADDR_TYPE:
189 initiator_peer_addr_type = value;
191 case RADIO_PARAM_BLE_CONN_INTERVAL:
192 connection_interval = value;
194 case RADIO_PARAM_BLE_CONN_LATENCY:
195 connection_latency = value;
197 case RADIO_PARAM_BLE_CONN_SUPERVISION_TIMEOUT:
198 connection_timeout = value;
200 case RADIO_PARAM_BLE_INITIATOR_ENABLE:
203 initiator_peer_addr_type,
213 case RADIO_PARAM_BLE_CONN_UPDATE:
217 switch(ble_hal.
connection_update(0, connection_interval, connection_latency, connection_timeout)) {
220 case BLE_RESULT_NOT_SUPPORTED:
222 case BLE_RESULT_INVALID_PARAM:
224 case BLE_RESULT_ERROR:
233get_object(radio_param_t param,
void *dest,
size_t size)
236 case RADIO_CONST_BLE_BD_ADDR:
237 if(size != BLE_ADDR_SIZE || !dest) {
247set_object(radio_param_t param,
const void *src,
size_t size)
250 case RADIO_PARAM_BLE_ADV_PAYLOAD:
251 if(size <= 0 || size >= BLE_ADV_DATA_LEN || !src) {
254 ble_hal.
set_adv_data((
unsigned short)size, (
char *)src);
256 case RADIO_PARAM_BLE_ADV_SCAN_RESPONSE:
257 if(size <= 0 || size >= BLE_SCAN_RESP_DATA_LEN || !src) {
262 case RADIO_PARAM_BLE_PEER_ADDR:
263 if(size <= 0 || size > BLE_ADDR_SIZE || !src) {
266 memcpy(initiator_peer_addr, src, size);
BLE radio hardware abstraction for the TI CC26XX controller.
hardware abstraction for a BLE controller
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio.
@ RADIO_RESULT_ERROR
An error occurred when getting/setting the parameter, but the arguments were otherwise correct.
@ RADIO_RESULT_NOT_SUPPORTED
The parameter is not supported.
@ RADIO_RESULT_INVALID_VALUE
The value argument was incorrect.
@ RADIO_RESULT_OK
The parameter was set/read successfully.
@ RADIO_CONST_CHANNEL_MAX
The highest radio channel number.
@ RADIO_CONST_CHANNEL_MIN
The lowest radio channel number.
@ RADIO_TX_ERR
An error occurred during transmission.
@ RADIO_TX_OK
TX was successful and where an ACK was requested one was received.
Header file for the logging system.
Header file for the radio API.
ble_result_t(* set_adv_enable)(unsigned short enable)
Enables/disables advertising.
ble_result_t(* connection_update)(unsigned int connection_handle, unsigned int conn_interval, unsigned int conn_latency, unsigned int supervision_timeout)
Updates the connection parameters.
ble_result_t(* set_scan_enable)(unsigned short enable, unsigned short filter_duplicates)
Enables/disables scanning.
ble_result_t(* reset)(void)
Resets the BLE controller.
ble_result_t(* create_connection)(unsigned int scan_interval, unsigned int scan_window, ble_addr_type_t peer_addr_type, uint8_t *peer_addr, ble_addr_type_t own_addr_type, unsigned int conn_interval, unsigned int conn_latency, unsigned int supervision_timeout)
Initiates the creation of a BLE connection.
ble_result_t(* set_scan_param)(ble_scan_type_t type, unsigned int scan_interval, unsigned int scan_window, ble_addr_type_t own_addr_type)
Sets the parameter for scanning.
ble_result_t(* create_connection_cancel)(void)
Cancels the initiation of a BLE connection.
ble_result_t(* read_bd_addr)(uint8_t *addr)
Reads the static BLE device address.
ble_result_t(* set_adv_param)(unsigned int adv_interval, ble_adv_type_t type, ble_addr_type_t own_addr_type, unsigned short adv_channel_map)
Sets the parameter for advertising.
ble_result_t(* set_scan_resp_data)(unsigned short data_len, char *data)
Sets the scan response data.
ble_result_t(* disconnect)(unsigned int connection_handle, unsigned short reason)
Disconnects the connection.
ble_result_t(* set_adv_data)(unsigned short data_len, char *data)
Sets the advertising data.
ble_result_t(* read_buffer_size)(unsigned int *buf_len, unsigned int *num_buf)
Reads the size of the data buffers.
The structure of a Contiki-NG radio device driver.
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
int(* off)(void)
Turn the radio off.
int(* init)(void)
Initialise the radio hardware.
int(* send)(const void *payload, unsigned short payload_len)
Prepare & transmit a packet.
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
int(* on)(void)
Turn the radio on.
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.