From 4012844c28f77c8d77f160c27589fbfb9dd1213a Mon Sep 17 00:00:00 2001 From: Roshan Bangar Date: Tue, 9 May 2023 12:09:02 +0530 Subject: [PATCH] Sync porting files --- nimble/include/nimble/hci_common.h | 3 -- nimble/include/nimble/nimble_npl.h | 2 +- porting/nimble/include/nimble/nimble_port.h | 2 +- porting/nimble/src/os_msys_init.c | 4 ++ .../freertos/include/nimble/nimble_npl_os.h | 4 +- .../freertos/include/nimble/npl_freertos.h | 2 +- porting/npl/freertos/src/npl_os_freertos.c | 47 ++++++++++++++----- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 742824d87..317ff01ba 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1144,7 +1144,6 @@ struct ble_hci_le_subrate_req_cp { uint16_t conn_handle; uint16_t subrate_min; uint16_t subrate_max; - uint16_t max_latency; uint16_t cont_num; uint16_t supervision_tmo; } __attribute__((packed)); @@ -1266,8 +1265,6 @@ struct ble_hci_vs_set_antenna_cp { /* * Advertising filter policy * - * Determines how an advertiser filters scan and connection requests. - * * NONE: no filtering (default value). No whitelist used. * SCAN: process all connection requests but only scans from white list. * CONN: process all scan request but only connection requests from white list diff --git a/nimble/include/nimble/nimble_npl.h b/nimble/include/nimble/nimble_npl.h index 8d5c8de6d..c11a2972d 100644 --- a/nimble/include/nimble/nimble_npl.h +++ b/nimble/include/nimble/nimble_npl.h @@ -121,7 +121,7 @@ uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem); * Callouts */ -void ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, +int ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg); ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co, diff --git a/porting/nimble/include/nimble/nimble_port.h b/porting/nimble/include/nimble/nimble_port.h index 329281a03..fef61731c 100644 --- a/porting/nimble/include/nimble/nimble_port.h +++ b/porting/nimble/include/nimble/nimble_port.h @@ -27,7 +27,7 @@ #define NIMBLE_HS_STACK_SIZE CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE -#if (CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2) +#if SOC_ESP_NIMBLE_CONTROLLER #define NIMBLE_LL_STACK_SIZE CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE #endif diff --git a/porting/nimble/src/os_msys_init.c b/porting/nimble/src/os_msys_init.c index 40c06a5da..c4200c844 100644 --- a/porting/nimble/src/os_msys_init.c +++ b/porting/nimble/src/os_msys_init.c @@ -147,6 +147,10 @@ os_msys_buf_alloc(void) #if OS_MSYS_2_BLOCK_COUNT > 0 os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE)); if (!os_msys_init_2_data) { +#if OS_MSYS_1_BLOCK_COUNT > 0 + nimble_platform_mem_free(os_msys_init_1_data); + os_msys_init_1_data = NULL; +#endif return ESP_FAIL; } #endif diff --git a/porting/npl/freertos/include/nimble/nimble_npl_os.h b/porting/npl/freertos/include/nimble/nimble_npl_os.h index 52573cdd0..cb28615f4 100644 --- a/porting/npl/freertos/include/nimble/nimble_npl_os.h +++ b/porting/npl/freertos/include/nimble/nimble_npl_os.h @@ -113,7 +113,7 @@ struct npl_funcs_t { ble_npl_error_t (*p_ble_npl_sem_pend)(struct ble_npl_sem *, ble_npl_time_t); ble_npl_error_t (*p_ble_npl_sem_release)(struct ble_npl_sem *); uint16_t (*p_ble_npl_sem_get_count)(struct ble_npl_sem *); - void (*p_ble_npl_callout_init)(struct ble_npl_callout *, struct ble_npl_eventq *, ble_npl_event_fn *, void *); + int (*p_ble_npl_callout_init)(struct ble_npl_callout *, struct ble_npl_eventq *, ble_npl_event_fn *, void *); ble_npl_error_t (*p_ble_npl_callout_reset)(struct ble_npl_callout *, ble_npl_time_t); void (*p_ble_npl_callout_stop)(struct ble_npl_callout *); void (*p_ble_npl_callout_deinit)(struct ble_npl_callout *); @@ -270,7 +270,7 @@ IRAM_ATTR ble_npl_sem_get_count(struct ble_npl_sem *sem) return npl_funcs->p_ble_npl_sem_get_count(sem); } -static inline void +static inline int IRAM_ATTR ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) { diff --git a/porting/npl/freertos/include/nimble/npl_freertos.h b/porting/npl/freertos/include/nimble/npl_freertos.h index acc3f6da1..dd9fff53d 100644 --- a/porting/npl/freertos/include/nimble/npl_freertos.h +++ b/porting/npl/freertos/include/nimble/npl_freertos.h @@ -83,7 +83,7 @@ ble_npl_error_t npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_error_t npl_freertos_sem_release(struct ble_npl_sem *sem); -void npl_freertos_callout_init(struct ble_npl_callout *co, +int npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg); diff --git a/porting/npl/freertos/src/npl_os_freertos.c b/porting/npl/freertos/src/npl_os_freertos.c index 57b21325c..a72407603 100644 --- a/porting/npl/freertos/src/npl_os_freertos.c +++ b/porting/npl/freertos/src/npl_os_freertos.c @@ -683,7 +683,7 @@ IRAM_ATTR os_callout_timer_cb(TimerHandle_t timer) } #endif -void +int IRAM_ATTR npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) { @@ -707,13 +707,25 @@ IRAM_ATTR npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_e .name = "nimble_timer" }; - ESP_ERROR_CHECK(esp_timer_create(&create_args, &callout->handle)); + if (esp_timer_create(&create_args, &callout->handle) != ESP_OK) { + ble_npl_event_deinit(&callout->ev); + os_memblock_put(&ble_freertos_co_pool,callout); + co->co = NULL; + return -1; + } #else callout->handle = xTimerCreate("co", 1, pdFALSE, callout, os_callout_timer_cb); + + if (!callout->handle) { + ble_npl_event_deinit(&callout->ev); + os_memblock_put(&ble_freertos_co_pool,callout); + co->co = NULL; + return -1; + } + #endif - BLE_LL_ASSERT(callout->handle); } else { callout = (struct ble_npl_callout_freertos *)co->co; BLE_LL_ASSERT(callout); @@ -725,7 +737,9 @@ IRAM_ATTR npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_e if(!co->co) { co->co = malloc(sizeof(struct ble_npl_callout_freertos)); callout = (struct ble_npl_callout_freertos *)co->co; - BLE_LL_ASSERT(callout); + if (!callout) { + return -1; + } memset(callout, 0, sizeof(*callout)); ble_npl_event_init(&callout->ev, ev_cb, ev_arg); @@ -739,12 +753,22 @@ IRAM_ATTR npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_e .name = "nimble_timer" }; - ESP_ERROR_CHECK(esp_timer_create(&create_args, &callout->handle)); + if (esp_timer_create(&create_args, &callout->handle) != ESP_OK) { + ble_npl_event_deinit(&callout->ev); + free((void *)callout); + co->co = NULL; + return -1; + } #else callout->handle = xTimerCreate("co", 1, pdFALSE, callout, os_callout_timer_cb); -#endif - BLE_LL_ASSERT(callout->handle); + if (!callout->handle) { + ble_npl_event_deinit(&callout->ev); + free((void *)callout); + co->co = NULL; + return -1; + } +#endif } else { callout = (struct ble_npl_callout_freertos *)co->co; @@ -753,7 +777,7 @@ IRAM_ATTR npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_e ble_npl_event_init(&callout->ev, ev_cb, ev_arg); } #endif - + return 0; } void @@ -766,8 +790,10 @@ IRAM_ATTR npl_freertos_callout_deinit(struct ble_npl_callout *co) return; } - BLE_LL_ASSERT(callout->handle); - + if (!callout->handle) { + return; + } + ble_npl_event_deinit(&callout->ev); #if CONFIG_BT_NIMBLE_USE_ESP_TIMER if(esp_timer_stop(callout->handle)) ESP_LOGD(TAG, "Timer not stopped"); @@ -778,7 +804,6 @@ IRAM_ATTR npl_freertos_callout_deinit(struct ble_npl_callout *co) #else xTimerDelete(callout->handle, portMAX_DELAY); - ble_npl_event_deinit(&callout->ev); #if OS_MEM_ALLOC os_memblock_put(&ble_freertos_co_pool,callout);