SmartSnippets DA1459x SDK
ad_ble.h
Go to the documentation of this file.
1 
43 #ifndef AD_BLE_H
44 #define AD_BLE_H
45 
46 #include "osal.h"
47 
48 #include "ad_ble_config.h"
49 
50 #include "ad_nvparam.h"
51 #include "ble_config.h"
52 #include "co_bt.h"
53 
54 
55 /* Event group bits */
56 #define mainBIT_BLE_GEN_IRQ (1 << 0)
57 #define mainBIT_COMMAND_QUEUE (1 << 1)
58 #define mainBIT_EVENT_QUEUE_AVAIL (1 << 2)
59 #define mainBIT_EVENT_LPCLOCK_AVAIL (1 << 3)
60 #define mainBIT_STAY_ACTIVE_UPDATED (1 << 4)
61 #define mainBIT_BLE_CMAC_IRQ (1 << 5)
62 #define mainBIT_BLE_TIMER_EXPIRED (1 << 6)
63 #define mainBIT_BLE_STACK_READ_CB (1 << 7)
64 #define mainBIT_TEMP_MONITOR_ENABLE (1 << 9)
65 #define mainBIT_TEMP_MONITOR_DISABLE (1 << 10)
66 #define mainBIT_BLE_RF_CALIBRATION (1 << 11)
67 #if (dg_configBLE_ADV_STOP_DELAY_ENABLE == 1)
68 #define mainBIT_EVENT_ADV_END (1 << 31)
69 #endif
70 
72 #define HCI_CMD_HEADER_LENGTH 3
73 #define HCI_ACL_HEADER_LENGTH 4
74 #define HCI_SCO_HEADER_LENGTH 3
75 #define HCI_EVT_HEADER_LENGTH 2
76 #define GTL_MSG_HEADER_LENGTH 8
77 
78 #define HCI_CMD_PARAM_LEN_OFFSET 3
79 #define HCI_ACL_PARAM_LEN_OFFSET 3
80 #define HCI_SCO_PARAM_LEN_OFFSET 3
81 #define HCI_EVT_PARAM_LEN_OFFSET 2
82 #define GTL_MSG_PARAM_LEN_OFFSET 7
83 
84 #define HCI_RESET_CMD_OP_CODE (0x0C03)
85 
86 // Maximum wait time for BLE stack configuration operations
87 #define MAX_WAIT_TIME portMAX_DELAY
88 
89 // Operations for BLE adapter messages
90 typedef enum ad_ble_op_codes {
91  AD_BLE_OP_CODE_STACK_MSG = 0x00,
92  AD_BLE_OP_CODE_ADAPTER_MSG = 0x01,
93  /*
94  * last command ID
95  * make sure above are sorted in ascending order, otherwise this one will be incorrect!
96  */
97  AD_BLE_OP_CODE_LAST,
98 } ad_ble_op_code_t;
99 
100 // Operations for BLE adapter messages
101 typedef enum ad_ble_operations {
102  AD_BLE_OP_CMP_EVT = 0x00,
103  AD_BLE_OP_INIT_CMD = 0x01,
104  AD_BLE_OP_RESET_CMD = 0x02,
105  /*
106  * last command ID
107  * make sure above are sorted in ascending order, otherwise this one will be incorrect!
108  */
109  AD_BLE_OP_LAST,
110 } ad_ble_operation_t;
111 
112 // Statuses for BLE adapter operations
113 typedef enum ad_ble_statuses {
114  AD_BLE_STATUS_NO_ERROR = 0x00,
115  AD_BLE_STATUS_TIMEOUT = 0x01,
116  /*
117  * last error code for BLE adapter operations
118  * make sure above are sorted in ascending order, otherwise this one will be incorrect!
119  */
120  BLE_ADAPTER_OP_LAST
121 } ad_ble_status_t;
122 
123 // Statuses for BLE stack I/O callback operations
124 enum ad_ble_stack_statuses {
125  BLE_STACK_IO_OK = 0x00,
126  BLE_STACK_IO_ERROR = 0x01,
127  /*
128  * last error code for BLE stack I/O operations
129  * make sure above are sorted in ascending order, otherwise this one will be incorrect!
130  */
131  BLE_STACK_IO_LAST
132 };
133 
134 typedef enum {
135  BLE_HCI_CMD_MSG = 0x01,
136  BLE_HCI_ACL_MSG = 0x02,
137  BLE_HCI_SCO_MSG = 0x03,
138  BLE_HCI_EVT_MSG = 0x04,
139  BLE_GTL_MSG = 0x05,
140 #ifdef CONFIG_USE_FTDF
141  FTDF_DTS_MSG = 0xAA,
142 #endif
143 } ble_msg_type_t;
144 
145 typedef uint16_t hci_cmd_op_code_t;
146 typedef uint16_t hci_cmd_op_code_t;
147 
149 typedef struct ble_hci_cmd_hdr {
150  uint8_t op_code_l;
151  uint8_t op_code_h;
152  uint8_t data_length;
154 
156 typedef struct ble_hci_acl_msg_hdr {
157  uint16_t handle_flags;
158  uint16_t data_length;
160 
162 typedef struct ble_hci_sco_hdr {
163  uint16_t conn_handle_flags;
164  uint8_t data_length;
166 
168 typedef struct ble_hci_evt_hdr {
169  uint8_t event_code_;
170  uint8_t data_length;
172 
174 typedef struct hci_cmd_msg {
175  uint16_t op_code;
176  uint8_t param_length;
177  uint8_t param[0];
178 } hci_cmd_msg_t;
179 
181 typedef struct hci_acl_msg {
182  uint16_t handle_flags;
183  uint16_t param_length;
184  uint8_t param[0];
185 } hci_acl_msg_t;
186 
188 typedef struct hci_sco_msg {
189  uint16_t handle_flags;
190  uint8_t param_length;
191  uint8_t param[0];
192 } hci_sco_msg_t;
193 
195 typedef struct hci_evt_msg {
196  uint8_t event_code;
197  uint8_t param_length;
198  uint8_t param[0];
199 } hci_evt_msg_t;
200 
202 typedef struct ble_hci_msg {
203  union {
204  hci_cmd_msg_t cmd;
205  hci_acl_msg_t acl;
206  hci_sco_msg_t sco;
207  hci_evt_msg_t evt;
208  };
209 } ble_hci_msg_t;
210 
212 typedef struct ble_gtl_msg {
213  uint16_t msg_id;
214  uint16_t dest_id;
215  uint16_t src_id;
216  uint16_t param_length;
217  uint32_t param[0];
218 } ble_gtl_msg_t;
219 
221 typedef struct ble_stack_msg {
222  union {
223  ble_gtl_msg_t gtl;
224  ble_hci_msg_t hci;
225  };
227 
229 typedef struct ad_ble_msg {
230  uint16_t op_code;
231  uint16_t msg_size;
232  ad_ble_operation_t operation;
233  uint8_t param[0];
234 } ad_ble_msg_t;
235 
237 typedef struct ad_ble_hdr {
238  uint16_t op_code;
239  uint16_t msg_size;
240  uint8_t param[0];
241 } ad_ble_hdr_t;
242 
244 typedef struct {
245  OS_TASK task;
246  OS_QUEUE cmd_q;
247  OS_QUEUE evt_q;
249 
260 OS_BASE_TYPE ad_ble_command_queue_send( const void *item, OS_TICK_TIME wait_ticks);
261 
269 void ad_ble_lpclock_available(void);
270 
281 OS_BASE_TYPE ad_ble_event_queue_send( const void *item, OS_TICK_TIME wait_ticks);
282 
290 void ad_ble_task_notify(uint32_t value);
291 
296 void ad_ble_init(void);
297 
305 
313 OS_BASE_TYPE ad_ble_event_queue_register(const OS_TASK task_handle);
314 
324 void ad_ble_get_public_address(uint8_t address[BD_ADDR_LEN]);
325 
326 
336 bool ad_ble_read_nvms_param(uint8_t* param, uint8_t len, uint8_t nvparam_tag, uint32_t nvms_addr);
337 
345 void ad_ble_get_irk(uint8_t irk[KEY_LEN]);
346 
351 
359 #if dg_configNVPARAM_ADAPTER
361 #endif /* dg_configNVPARAM_ADAPTER */
362 
372 void ad_ble_stay_active(bool status);
373 
374 #if (dg_configRF_ENABLE_RECALIBRATION == 1)
375 
381 void ad_ble_notify_rf_calibration(void);
382 #endif /* (dg_configRF_ENABLE_RECALIBRATION == 1) */
383 
388 
389 #if (USE_BLE_SLEEP == 1)
390 
393 void ad_ble_update_wakeup_time(void);
394 #endif /* USE_BLE_SLEEP */
395 
399 void ad_ble_sys_tcs_config(void);
400 
401 #if (dg_configUSE_SYS_TCS == 1)
402 
405 void ad_ble_tcs_config(void);
406 #endif
407 
408 #if (dg_configRF_ENABLE_RECALIBRATION == 1)
409 
412 void ad_ble_rf_calibration_info(void);
413 
422 void ad_ble_set_rf_calibration_info(const uint32_t value);
423 #endif
424 
429  // Total number of connection events
430  uint32_t conn_evt_counter[BLE_CONNECTION_MAX_USER];
431  // Number of connection events that completed without apfm status
432  uint32_t conn_evt_counter_non_apfm[BLE_CONNECTION_MAX_USER];
433  // Total number of advertising events
434  uint32_t adv_evt_counter;
435  // Number of advertising events that completed without apfm status
436  uint32_t adv_evt_counter_non_apfm;
437 };
438 
442 void ad_ble_get_lld_stats(struct ad_ble_lld_stats *stats);
443 
444 #if (USE_BLE_SLEEP == 1)
445 #if (dg_configUSE_LP_CLK == LP_CLK_RCX)
446 
449 void ad_ble_update_rcx(void);
450 #endif /* (USE_BLE_SLEEP == 1) */
451 #endif /* (dg_configUSE_LP_CLK == LP_CLK_RCX) */
452 
453 
454 #endif /* AD_BLE_H */
455 
ad_ble_hdr
Definition: ad_ble.h:237
ble_hci_msg
Definition: ad_ble.h:202
ad_ble_msg_t
struct ad_ble_msg ad_ble_msg_t
ble_config.h
BLE configuration options.
ad_ble_config.h
BLE Adapter configuration.
ad_ble_interface_t::evt_q
OS_QUEUE evt_q
Definition: ad_ble.h:247
hci_acl_msg_t
struct hci_acl_msg hci_acl_msg_t
ble_hci_acl_hdr_t
struct ble_hci_acl_msg_hdr ble_hci_acl_hdr_t
ad_ble_sys_tcs_config
void ad_ble_sys_tcs_config(void)
Configure CMAC SYS TCS table.
hci_acl_msg
Definition: ad_ble.h:181
hci_evt_msg
Definition: ad_ble.h:195
ble_hci_cmd_hdr
Definition: ad_ble.h:149
ble_hci_sco_hdr
Definition: ad_ble.h:162
hci_sco_msg
Definition: ad_ble.h:188
ad_ble_command_queue_send
OS_BASE_TYPE ad_ble_command_queue_send(const void *item, OS_TICK_TIME wait_ticks)
Send a message to the BLE adapter command queue.
ad_ble_lld_stats
Structure for low level driver statistics.
Definition: ad_ble.h:428
hci_cmd_msg_t
struct hci_cmd_msg hci_cmd_msg_t
ble_hci_evt_hdr_t
struct ble_hci_evt_hdr ble_hci_evt_hdr_t
osal.h
OS abstraction layer API.
ad_ble_get_irk
void ad_ble_get_irk(uint8_t irk[KEY_LEN])
Get device's IRK.
ad_ble_get_lld_stats
void ad_ble_get_lld_stats(struct ad_ble_lld_stats *stats)
Gets low level driver statistics.
ad_ble_lpclock_available
void ad_ble_lpclock_available(void)
Notify the BLE adapter that LP clock is available.
ble_hci_cmd_hdr_t
struct ble_hci_cmd_hdr ble_hci_cmd_hdr_t
ble_hci_acl_msg_hdr
Definition: ad_ble.h:156
ble_gtl_msg
Definition: ad_ble.h:212
ad_ble_init
void ad_ble_init(void)
Initialize BLE adapter - create command and event queues.
ad_ble_read_nvms_param
bool ad_ble_read_nvms_param(uint8_t *param, uint8_t len, uint8_t nvparam_tag, uint32_t nvms_addr)
Read configuration parameters form NVMS parameter area.
ble_hci_msg_t
struct ble_hci_msg ble_hci_msg_t
ad_ble_event_queue_send
OS_BASE_TYPE ad_ble_event_queue_send(const void *item, OS_TICK_TIME wait_ticks)
Send a message to the BLE adapter event queue.
ad_ble_task_notify
void ad_ble_task_notify(uint32_t value)
Notify BLE adapter.
ad_ble_interface_t::cmd_q
OS_QUEUE cmd_q
Definition: ad_ble.h:246
hci_sco_msg_t
struct hci_sco_msg hci_sco_msg_t
ad_ble_stay_active
void ad_ble_stay_active(bool status)
Force BLE to stay active.
ad_ble_interface_t::task
OS_TASK task
Definition: ad_ble.h:245
ad_ble_non_retention_heap_in_use
bool ad_ble_non_retention_heap_in_use(void)
Check if the non retention BLE heap is in use.
hci_evt_msg_t
struct hci_evt_msg hci_evt_msg_t
ble_stack_msg_t
struct ble_stack_msg ble_stack_msg_t
ble_stack_msg
Definition: ad_ble.h:221
ad_ble_notify_event_queue_avail
void ad_ble_notify_event_queue_avail(void)
Notifies BLE adapter that there is free space on the event queue.
ad_ble_interface_t
Definition: ad_ble.h:244
ble_hci_sco_hdr_t
struct ble_hci_sco_hdr ble_hci_sco_hdr_t
hci_cmd_msg
Definition: ad_ble.h:174
ad_ble_hdr_t
struct ad_ble_hdr ad_ble_hdr_t
ad_ble_get_public_address
void ad_ble_get_public_address(uint8_t address[BD_ADDR_LEN])
Get public static address.
ble_hci_evt_hdr
Definition: ad_ble.h:168
ad_ble_event_queue_register
OS_BASE_TYPE ad_ble_event_queue_register(const OS_TASK task_handle)
Register task for BLE Adapter's event Queue notifications.
nvparam_t
void * nvparam_t
NV-Parameters area handle.
Definition: ad_nvparam.h:72
ad_nvparam.h
NV Parameters adapter API.
ble_gtl_msg_t
struct ble_gtl_msg ble_gtl_msg_t
ad_ble_get_interface
const ad_ble_interface_t * ad_ble_get_interface(void)
Get BLE Adapter interface.
ad_ble_msg
Definition: ad_ble.h:229
ad_ble_get_nvparam_handle
nvparam_t ad_ble_get_nvparam_handle(void)
Get non-volatile parameter handle.