Skip to content

Commit e1871e9

Browse files
Raffael Rostagnosylvioalves
authored andcommitted
hal: ble: Dynamic eventq buffer allocation
Allocate event queue buffer dynamically according to event count demand. Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 19998bb commit e1871e9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

zephyr/port/bluetooth/npl/zephyr/src/npl_os_zephyr.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ LOG_MODULE_REGISTER(esp32_ble_npl, CONFIG_LOG_DEFAULT_LEVEL);
2727
#define BLE_HOST_SEM_COUNT (0)
2828
#define BLE_HOST_MUTEX_COUNT (0)
2929

30-
#define MAX_EVENTS 64 /* TODO: evaluate this in the future */
31-
static char evq_buffer[sizeof(struct ble_npl_event) * MAX_EVENTS];
30+
static struct ble_npl_event **evq_buffer;
3231

3332
struct os_mempool ble_zephyr_ev_pool;
3433
static os_membuf_t *ble_zephyr_ev_buf = NULL;
@@ -100,8 +99,10 @@ void npl_zephyr_eventq_init(struct ble_npl_eventq *evq)
10099
eventq = (struct ble_npl_eventq_zephyr *)evq->eventq;
101100
BLE_LL_ASSERT(eventq);
102101
memset(eventq, 0, sizeof(*eventq));
103-
/* point at our statically-allocated array of pointers */
104-
k_msgq_init(&eventq->q, evq_buffer, sizeof(struct ble_npl_event *),
102+
evq_buffer = bt_osi_mem_malloc_internal(
103+
ble_zephyr_total_event_cnt * sizeof(struct ble_npl_event *));
104+
BLE_LL_ASSERT(evq_buffer);
105+
k_msgq_init(&eventq->q, (char *)evq_buffer, sizeof(struct ble_npl_event *),
105106
ble_zephyr_total_event_cnt);
106107
} else {
107108
eventq = (struct ble_npl_eventq_zephyr *)evq->eventq;
@@ -117,6 +118,7 @@ void npl_zephyr_eventq_deinit(struct ble_npl_eventq *evq)
117118
return;
118119
}
119120
k_free(eventq);
121+
k_free(evq_buffer);
120122
evq->eventq = NULL;
121123
}
122124

0 commit comments

Comments
 (0)