NimBLE-component: Add support to disable/deinit NimBLE host and port

This commit is contained in:
Hrishikesh Dhayagude
2024-02-14 12:32:12 +05:30
committed by Abhinav Kudnar
parent bd54d216d5
commit 56f4975a22
21 changed files with 225 additions and 1 deletions
@@ -24,13 +24,17 @@
#define NIMBLE_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
#define NIMBLE_PORT_DEINIT_EV_ARG -1
#ifdef __cplusplus
extern "C" {
#endif
void nimble_port_init(void);
void nimble_port_deinit(void);
void nimble_port_run(void);
int nimble_port_stop(void);
struct ble_npl_eventq *nimble_port_get_dflt_eventq(void);
+9
View File
@@ -220,6 +220,15 @@ os_error_t os_mempool_unregister(struct os_mempool *mp);
*/
os_error_t os_mempool_clear(struct os_mempool *mp);
/**
* Clears an extended memory pool.
*
* @param mpe The extended memory pool to clear.
*
* @return os_error_t
*/
os_error_t os_mempool_ext_clear(struct os_mempool_ext *mpe);
/**
* Performs an integrity check of the specified mempool. This function
* attempts to detect memory corruption in the specified memory pool.
+61
View File
@@ -31,6 +31,9 @@
#endif
static struct ble_npl_eventq g_eventq_dflt;
static struct ble_hs_stop_listener stop_listener;
static struct ble_npl_sem ble_hs_stop_sem;
static struct ble_npl_event ble_hs_ev_stop;
extern void os_msys_init(void);
extern void os_mempool_module_init(void);
@@ -62,17 +65,75 @@ nimble_port_init(void)
}
void
nimble_port_deinit(void)
{
ble_npl_eventq_deinit(&g_eventq_dflt);
ble_hs_deinit();
}
void
nimble_port_run(void)
{
struct ble_npl_event *ev;
int arg;
while (1) {
ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER);
ble_npl_event_run(ev);
arg = (int)ble_npl_event_get_arg(ev);
if (arg == NIMBLE_PORT_DEINIT_EV_ARG) {
break;
}
}
}
/**
* Called when the host stop procedure has completed.
*/
static void
ble_hs_stop_cb(int status, void *arg)
{
ble_npl_sem_release(&ble_hs_stop_sem);
}
static void
nimble_port_stop_cb(struct ble_npl_event *ev)
{
ble_npl_sem_release(&ble_hs_stop_sem);
}
int
nimble_port_stop(void)
{
int rc;
ble_npl_sem_init(&ble_hs_stop_sem, 0);
/* Initiate a host stop procedure. */
rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
NULL);
if (rc != 0) {
ble_npl_sem_deinit(&ble_hs_stop_sem);
return rc;
}
/* Wait till the host stop procedure is complete */
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
ble_npl_event_init(&ble_hs_ev_stop, nimble_port_stop_cb,
(void *)NIMBLE_PORT_DEINIT_EV_ARG);
ble_npl_eventq_put(&g_eventq_dflt, &ble_hs_ev_stop);
/* Wait till the event is serviced */
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
ble_npl_sem_deinit(&ble_hs_stop_sem);
return rc;
}
struct ble_npl_eventq *
nimble_port_get_dflt_eventq(void)
{
+10
View File
@@ -283,6 +283,16 @@ os_mempool_clear(struct os_mempool *mp)
return OS_OK;
}
os_error_t
os_mempool_ext_clear(struct os_mempool_ext *mpe)
{
mpe->mpe_mp.mp_flags = 0;
mpe->mpe_put_cb = NULL;
mpe->mpe_put_arg = NULL;
return os_mempool_clear(&mpe->mpe_mp);
}
bool
os_mempool_is_sane(const struct os_mempool *mp)
{
@@ -91,6 +91,12 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
evq->q = xQueueCreate(32, sizeof(struct ble_npl_eventq *));
}
static inline void
ble_npl_eventq_deinit(struct ble_npl_eventq *evq)
{
vQueueDelete(evq->q);
}
static inline struct ble_npl_event *
ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
@@ -154,6 +160,12 @@ ble_npl_mutex_init(struct ble_npl_mutex *mu)
return npl_freertos_mutex_init(mu);
}
static inline ble_npl_error_t
ble_npl_mutex_deinit(struct ble_npl_mutex *mu)
{
return npl_freertos_mutex_deinit(mu);
}
static inline ble_npl_error_t
ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
{
@@ -172,6 +184,12 @@ ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
return npl_freertos_sem_init(sem, tokens);
}
static inline ble_npl_error_t
ble_npl_sem_deinit(struct ble_npl_sem *sem)
{
return npl_freertos_sem_deinit(sem);
}
static inline ble_npl_error_t
ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
{
@@ -196,6 +214,11 @@ ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
{
npl_freertos_callout_init(co, evq, ev_cb, ev_arg);
}
static inline void
ble_npl_callout_deinit(struct ble_npl_callout *co)
{
npl_freertos_callout_deinit(co);
}
static inline ble_npl_error_t
ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
@@ -27,6 +27,7 @@ extern "C" {
#endif
void nimble_port_freertos_init(TaskFunction_t host_task_fn);
void nimble_port_freertos_deinit(void);
#ifdef __cplusplus
}
@@ -34,6 +34,7 @@ void npl_freertos_eventq_remove(struct ble_npl_eventq *evq,
struct ble_npl_event *ev);
ble_npl_error_t npl_freertos_mutex_init(struct ble_npl_mutex *mu);
ble_npl_error_t npl_freertos_mutex_deinit(struct ble_npl_mutex *mu);
ble_npl_error_t npl_freertos_mutex_pend(struct ble_npl_mutex *mu,
ble_npl_time_t timeout);
@@ -41,6 +42,7 @@ ble_npl_error_t npl_freertos_mutex_pend(struct ble_npl_mutex *mu,
ble_npl_error_t npl_freertos_mutex_release(struct ble_npl_mutex *mu);
ble_npl_error_t npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens);
ble_npl_error_t npl_freertos_sem_deinit(struct ble_npl_sem *sem);
ble_npl_error_t npl_freertos_sem_pend(struct ble_npl_sem *sem,
ble_npl_time_t timeout);
@@ -51,6 +53,8 @@ void npl_freertos_callout_init(struct ble_npl_callout *co,
struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg);
void npl_freertos_callout_deinit(struct ble_npl_callout *co);
ble_npl_error_t npl_freertos_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
@@ -49,3 +49,11 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn)
xTaskCreatePinnedToCore(host_task_fn, "ble", 4096,
NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE);
}
void
nimble_port_freertos_deinit(void)
{
if (host_task_h) {
vTaskDelete(host_task_h);
}
}
@@ -159,6 +159,20 @@ npl_freertos_mutex_init(struct ble_npl_mutex *mu)
return BLE_NPL_OK;
}
ble_npl_error_t
npl_freertos_mutex_deinit(struct ble_npl_mutex *mu)
{
if (!mu) {
return BLE_NPL_INVALID_PARAM;
}
if (mu->handle) {
vSemaphoreDelete(mu->handle);
}
return BLE_NPL_OK;
}
ble_npl_error_t
npl_freertos_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
{
@@ -213,6 +227,20 @@ npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
return BLE_NPL_OK;
}
ble_npl_error_t
npl_freertos_sem_deinit(struct ble_npl_sem *sem)
{
if (!sem) {
return BLE_NPL_INVALID_PARAM;
}
if (sem->handle) {
vSemaphoreDelete(sem->handle);
}
return BLE_NPL_OK;
}
ble_npl_error_t
npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
{
@@ -288,6 +316,13 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
co->evq = evq;
ble_npl_event_init(&co->ev, ev_cb, ev_arg);
}
void
npl_freertos_callout_deinit(struct ble_npl_callout *co)
{
if (co->handle) {
xTimerDelete(co->handle, portMAX_DELAY);
}
}
ble_npl_error_t
npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)