25#include <bm/softdevice_handler/nrf_sdh_ble.h>
27#include <zephyr/kernel.h>
28#include <zephyr/sys/slist.h>
29#include <zephyr/sys/util.h>
41#define BLE_GQ_DEF(_name) \
42 BLE_GQ_CUSTOM_DEF(_name, CONFIG_BLE_GQ_MAX_CONNECTIONS, CONFIG_BLE_GQ_HEAP_SIZE, \
43 (CONFIG_BLE_GQ_MAX_CONNECTIONS * CONFIG_BLE_GQ_QUEUE_SIZE))
54#define BLE_GQ_CUSTOM_DEF(_name, _max_conns, _heap_size, _max_req_blocks) \
55 static uint16_t CONCAT(_name, _conn_handles_arr)[] = { \
56 LISTIFY(_max_conns, BLE_GQ_CONN_HANDLE_INIT, (,)), \
58 BUILD_ASSERT(ARRAY_SIZE(CONCAT(_name, _conn_handles_arr)) == (_max_conns)); \
59 static uint16_t CONCAT(_name, _purge_arr)[] = { \
60 LISTIFY(_max_conns, BLE_GQ_PURGE_ARRAY_INIT, (,), (_max_conns)), \
62 BUILD_ASSERT(ARRAY_SIZE(CONCAT(_name, _purge_arr)) == (_max_conns)); \
63 static sys_slist_t CONCAT(_name, _req_queues)[] = { \
64 LISTIFY(_max_conns, BLE_GQ_REQ_QUEUE_INIT, (,), _name), \
66 BUILD_ASSERT(ARRAY_SIZE(CONCAT(_name, _req_queues)) == (_max_conns)); \
67 K_MEM_SLAB_DEFINE_STATIC(_name##_req_blocks, sizeof(struct ble_gq_req), (_max_req_blocks), \
69 static K_HEAP_DEFINE(_name##_heap, (_heap_size)); \
70 static const struct ble_gq _name = { \
71 .max_conns = (_max_conns), \
72 .conn_handles = CONCAT(_name, _conn_handles_arr), \
73 .purge_list = CONCAT(_name, _purge_arr), \
74 .req_queue = (sys_slist_t *)&CONCAT(_name, _req_queues), \
75 .req_blocks = &CONCAT(_name, _req_blocks), \
76 .data_pool = &CONCAT(_name, _heap), \
78 NRF_SDH_BLE_OBSERVER(CONCAT(_name, _obs), ble_gq_on_ble_evt, (void *)&_name, HIGH)
83#define BLE_GQ_CONN_HANDLE_INIT(i, _) BLE_CONN_HANDLE_INVALID
88#define BLE_GQ_PURGE_ARRAY_INIT(i, _max_conns) (_max_conns)
93#define BLE_GQ_REQ_QUEUE_INIT(i, _name) SYS_SLIST_STATIC_INIT(&((_name)[i]))
284 uint16_t conn_handle);
void ble_gq_on_ble_evt(const ble_evt_t *ble_evt, void *ble_gq)
Bluetooth LE event handler for the GATT Queue library.
uint32_t ble_gq_item_add(const struct ble_gq *gatt_queue, struct ble_gq_req *req, uint16_t conn_handle)
Add a GATT request to the GATT queue instance.
uint32_t ble_gq_conn_handle_register(const struct ble_gq *gatt_queue, uint16_t conn_handle)
Register connection handle in the GATT queue instance.
ble_gq_evt_type
Advertising event types.
Definition ble_gq.h:134
@ BLE_GQ_EVT_ERROR
Error.
Definition ble_gq.h:138
ble_gq_req_type
Bluetooth LE GATT request types.
Definition ble_gq.h:98
@ BLE_GQ_REQ_GATTC_WRITE
GATTC Write Request. See sd_ble_gattc_write.
Definition ble_gq.h:106
@ BLE_GQ_REQ_GATTS_HVX
GATTS Handle Value Notification or Indication. See ble_gatts_hvx_params_t.
Definition ble_gq.h:124
@ BLE_GQ_REQ_NUM
Total number of different GATT Request types.
Definition ble_gq.h:128
@ BLE_GQ_REQ_SRV_DISCOVERY
GATTC Service Discovery Request. See sd_ble_gattc_primary_services_discover.
Definition ble_gq.h:110
@ BLE_GQ_REQ_DESC_DISCOVERY
GATTC Characteristic Descriptor Discovery Request. See sd_ble_gattc_descriptors_discover.
Definition ble_gq.h:120
@ BLE_GQ_REQ_CHAR_DISCOVERY
GATTC Characteristic Discovery Request. See sd_ble_gattc_characteristics_discover.
Definition ble_gq.h:115
@ BLE_GQ_REQ_GATTC_READ
GATTC Read Request. See sd_ble_gattc_read.
Definition ble_gq.h:102
void(* ble_gq_evt_handler_t)(const struct ble_gq_req *req, struct ble_gq_evt *evt)
Event handler type.
Definition ble_gq.h:164
struct ble_gq_evt::@11::@13 error
uint32_t reason
Definition ble_gq.h:153
uint16_t conn_handle
Connection handle for which the event applies.
Definition ble_gq.h:148
enum ble_gq_evt_type evt_type
Advertising event type.
Definition ble_gq.h:144
Gatt Queue event.
Definition ble_gq.h:142
ble_gattc_write_params_t gattc_write
GATTC write parameters. Type BLE_GQ_REQ_GATTC_WRITE.
Definition ble_gq.h:208
ble_gq_evt_handler_t evt_handler
Error handler structure.
Definition ble_gq.h:187
uint16_t start_handle
Definition ble_gq.h:214
struct ble_gq_req::@14::@17 gattc_srv_disc
GATTC service discovery parameters. Type BLE_GQ_REQ_SRV_DISCOVERY.
sys_snode_t node
Data for storing the request in a singly-linked list.
Definition ble_gq.h:173
uint8_t * data
Extra payload data that cannot be contained in the request queue.
Definition ble_gq.h:183
ble_uuid_t srvc_uuid
Definition ble_gq.h:215
void * ctx
Context.
Definition ble_gq.h:191
ble_gattc_handle_range_t gattc_char_disc
GATTC characteristic discovery parameters. Type NRF_BLE_GQ_REQ_CHAR_DISCOVERY.
Definition ble_gq.h:221
uint16_t handle
Definition ble_gq.h:201
enum ble_gq_req_type type
Type of request.
Definition ble_gq.h:177
struct ble_gq_req::@14::@16 gattc_read
GATTC read parameters. Type BLE_GQ_REQ_GATTC_READ.
ble_gatts_hvx_params_t gatts_hvx
GATTS handle value notification or indication parameters. Type NRF_BLE_GQ_REQ_GATTS_HVX.
Definition ble_gq.h:231
uint16_t offset
Definition ble_gq.h:202
ble_gattc_handle_range_t gattc_desc_disc
GATTC characteristic descriptor discovery parameters. Type NRF_BLE_GQ_REQ_DESC_DISCOVERY.
Definition ble_gq.h:226
Structure to hold a Bluetooth LE GATT request.
Definition ble_gq.h:169
uint16_t *const conn_handles
Pointer to array with registered connection handles.
Definition ble_gq.h:246
struct k_heap *const data_pool
Heap for allocating memory for write, notification, and indication request values.
Definition ble_gq.h:262
const uint16_t max_conns
Maximum number of connection handles that can be registered.
Definition ble_gq.h:242
struct k_mem_slab *const req_blocks
Pointer to memory slabs used to hold GATT requests.
Definition ble_gq.h:258
uint16_t *const purge_list
Pointer to array used to hold indices of request queues to purge.
Definition ble_gq.h:250
sys_slist_t *const req_queue
Pointer to array of lists used to hold pending requests.
Definition ble_gq.h:254
Bluetooth LE GATT Queue.
Definition ble_gq.h:238