diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index 05975d5f0..62b7e4855 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -27,6 +27,9 @@ #include "ble_hs_priv.h" #include "ble_monitor_priv.h" #include "nimble/nimble_npl.h" +#ifndef MYNEWT +#include "nimble/nimble_port.h" +#endif #define BLE_HS_HCI_EVT_COUNT \ (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + \ @@ -674,13 +677,20 @@ ble_hs_init(void) /* Configure the HCI transport to communicate with a host. */ ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL); - ble_hs_evq_set(ble_npl_eventq_dflt_get()); - +#ifdef MYNEWT + ble_hs_evq_set((struct ble_npl_eventq *)os_eventq_dflt_get()); +#else + ble_hs_evq_set(nimble_port_get_dflt_eventq()); +#endif /* Enqueue the start event to the default event queue. Using the default * queue ensures the event won't run until the end of main(). This allows * the application to configure this package in the meantime. */ - ble_npl_eventq_put(ble_npl_eventq_dflt_get(), &ble_hs_ev_start); +#ifdef MYNEWT + ble_npl_eventq_put((struct ble_npl_eventq *)os_eventq_dflt_get(), &ble_hs_ev_start); +#else + ble_npl_eventq_put(nimble_port_get_dflt_eventq(), &ble_hs_ev_start); +#endif #if BLE_MONITOR ble_monitor_new_index(0, (uint8_t[6]){ }, "nimble0"); diff --git a/nimble/include/nimble/nimble_npl.h b/nimble/include/nimble/nimble_npl.h index 9757e1b69..d7a4faed9 100644 --- a/nimble/include/nimble/nimble_npl.h +++ b/nimble/include/nimble/nimble_npl.h @@ -64,8 +64,6 @@ void *ble_npl_get_current_task_id(void); * Event queue */ -struct ble_npl_eventq *ble_npl_eventq_dflt_get(void); - void ble_npl_eventq_init(struct ble_npl_eventq *evq); struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq, diff --git a/porting/nimble/include/nimble/nimble_port.h b/porting/nimble/include/nimble/nimble_port.h index 8a3b60438..496acbbb1 100644 --- a/porting/nimble/include/nimble/nimble_port.h +++ b/porting/nimble/include/nimble/nimble_port.h @@ -20,12 +20,16 @@ #ifndef _NIMBLE_PORT_H #define _NIMBLE_PORT_H +#include "nimble/nimble_npl.h" + #ifdef __cplusplus extern "C" { #endif void nimble_port_init(void); +struct ble_npl_eventq *nimble_port_get_dflt_eventq(void); + #if NIMBLE_CFG_CONTROLLER void nimble_port_ll_task_func(void *arg); #endif diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c index 8c2ac0164..606429fe0 100644 --- a/porting/nimble/src/nimble_port.c +++ b/porting/nimble/src/nimble_port.c @@ -25,6 +25,8 @@ #include "controller/ble_ll.h" #endif +static struct ble_npl_eventq g_eventq_dflt; + void nimble_port_init(void) { @@ -34,6 +36,9 @@ nimble_port_init(void) void ble_hci_ram_init(void); #endif + /* Initialize default event queue */ + ble_npl_eventq_init(&g_eventq_dflt); + os_msys_init(); ble_hs_init(); @@ -49,6 +54,12 @@ nimble_port_init(void) #endif } +struct ble_npl_eventq * +nimble_port_get_dflt_eventq(void) +{ + return &g_eventq_dflt; +} + #if NIMBLE_CFG_CONTROLLER void nimble_port_ll_task_func(void *arg) diff --git a/porting/npl/dummy/src/npl_os_dummy.c b/porting/npl/dummy/src/npl_os_dummy.c index 90d37da5b..a522531fa 100644 --- a/porting/npl/dummy/src/npl_os_dummy.c +++ b/porting/npl/dummy/src/npl_os_dummy.c @@ -32,12 +32,6 @@ ble_npl_get_current_task_id(void) return NULL; } -struct ble_npl_eventq * -ble_npl_eventq_dflt_get(void) -{ - return NULL; -} - void ble_npl_eventq_init(struct ble_npl_eventq *evq) { diff --git a/porting/npl/freertos/include/nimble/nimble_npl_os.h b/porting/npl/freertos/include/nimble/nimble_npl_os.h index ca1c2e5cb..d5b18d299 100644 --- a/porting/npl/freertos/include/nimble/nimble_npl_os.h +++ b/porting/npl/freertos/include/nimble/nimble_npl_os.h @@ -85,14 +85,6 @@ ble_npl_get_current_task_id(void) return xTaskGetCurrentTaskHandle(); } -struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void); - -static inline struct ble_npl_eventq * -ble_npl_eventq_dflt_get(void) -{ - return npl_freertos_eventq_dflt_get(); -} - static inline void ble_npl_eventq_init(struct ble_npl_eventq *evq) { diff --git a/porting/npl/freertos/src/npl_os_freertos.c b/porting/npl/freertos/src/npl_os_freertos.c index 248baf864..d99116966 100644 --- a/porting/npl/freertos/src/npl_os_freertos.c +++ b/porting/npl/freertos/src/npl_os_freertos.c @@ -29,18 +29,6 @@ in_isr(void) return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0; } -static struct ble_npl_eventq dflt_evq; - -struct ble_npl_eventq * -npl_freertos_eventq_dflt_get(void) -{ - if (!dflt_evq.q) { - dflt_evq.q = xQueueCreate(32, sizeof(struct ble_npl_eventq *)); - } - - return &dflt_evq; -} - struct ble_npl_event * npl_freertos_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) {