diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index d135901aeb..55f2397335 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -6,7 +6,7 @@ if(CONFIG_BT_ENABLED) elseif(CONFIG_IDF_TARGET_ESP32C3) set(srcs "controller/esp32c3/bt.c") elseif(CONFIG_IDF_TARGET_ESP32S3) - set(srcs "controller/esp32s3/bt.c") + set(srcs "controller/esp32c3/bt.c") endif() set(include_dirs common/osi/include) @@ -16,7 +16,7 @@ if(CONFIG_BT_ENABLED) elseif(CONFIG_IDF_TARGET_ESP32C3) list(APPEND include_dirs include/esp32c3/include) elseif(CONFIG_IDF_TARGET_ESP32S3) - list(APPEND include_dirs include/esp32s3/include) + list(APPEND include_dirs include/esp32c3/include) endif() list(APPEND priv_include_dirs diff --git a/components/bt/common/api/include/api/esp_blufi_api.h b/components/bt/common/api/include/api/esp_blufi_api.h index ce7fe3a0d3..0ba46fd400 100644 --- a/components/bt/common/api/include/api/esp_blufi_api.h +++ b/components/bt/common/api/include/api/esp_blufi_api.h @@ -86,6 +86,7 @@ typedef enum { ESP_BLUFI_DATA_FORMAT_ERROR, ESP_BLUFI_CALC_MD5_ERROR, ESP_BLUFI_WIFI_SCAN_FAIL, + ESP_BLUFI_MSG_STATE_ERROR, } esp_blufi_error_state_t; /** diff --git a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c index 164b0ae1ed..80959b8541 100644 --- a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c @@ -144,6 +144,16 @@ void btc_blufi_recv_handler(uint8_t *data, int len) if (BLUFI_FC_IS_FRAG(hdr->fc)) { if (blufi_env.offset == 0) { + /* + blufi_env.aggr_buf should be NULL if blufi_env.offset is 0. + It is possible that the process of sending fragment packet + has not been completed + */ + if (blufi_env.aggr_buf) { + BTC_TRACE_ERROR("%s msg error, blufi_env.aggr_buf is not freed\n", __func__); + btc_blufi_report_error(ESP_BLUFI_MSG_STATE_ERROR); + return; + } blufi_env.total_len = hdr->data[0] | (((uint16_t) hdr->data[1]) << 8); blufi_env.aggr_buf = osi_malloc(blufi_env.total_len); if (blufi_env.aggr_buf == NULL) { @@ -163,6 +173,18 @@ void btc_blufi_recv_handler(uint8_t *data, int len) } else { if (blufi_env.offset > 0) { /* if previous pkt is frag */ + /* blufi_env.aggr_buf should not be NULL */ + if (blufi_env.aggr_buf == NULL) { + BTC_TRACE_ERROR("%s buffer is NULL\n", __func__); + btc_blufi_report_error(ESP_BLUFI_DH_MALLOC_ERROR); + return; + } + /* payload length should be equal to total_len */ + if ((blufi_env.offset + hdr->data_len) != blufi_env.total_len) { + BTC_TRACE_ERROR("%s payload is longer than packet length, len %d \n", __func__, blufi_env.total_len); + btc_blufi_report_error(ESP_BLUFI_DATA_FORMAT_ERROR); + return; + } memcpy(blufi_env.aggr_buf + blufi_env.offset, hdr->data, hdr->data_len); btc_blufi_protocol_handler(hdr->type, blufi_env.aggr_buf, blufi_env.total_len); diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index b0323c5717..1ebd78ea7a 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -4,11 +4,13 @@ config BT_CTRL_MODE_EFF config BT_CTRL_BLE_MAX_ACT int "BLE Max Instances" - default 10 + default 6 range 1 10 help BLE maximum activities of bluetooth controller,both of connections, - scan , sync and adv(periodic adv, multi-adv). + scan , sync and adv(periodic adv, multi-adv). Each instance needs to + consume 828 bytes, you can save RAM by modifying the instance value + according to actual needs. config BT_CTRL_BLE_MAX_ACT_EFF int @@ -24,8 +26,24 @@ config BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB (alloate when controller initialise, never free until controller de-initialise) another is dynamically allocating (allocate before TX and free after TX). +choice BT_CTRL_PINNED_TO_CORE_CHOICE + prompt "The cpu core which bluetooth controller run" + depends on !FREERTOS_UNICORE + help + Specify the cpu core to run bluetooth controller. + Can not specify no-affinity. + + config BT_CTRL_PINNED_TO_CORE_0 + bool "Core 0 (PRO CPU)" + config BT_CTRL_PINNED_TO_CORE_1 + bool "Core 1 (APP CPU)" + depends on !FREERTOS_UNICORE +endchoice + config BT_CTRL_PINNED_TO_CORE int + default 0 if BT_CTRL_PINNED_TO_CORE_0 + default 1 if BT_CTRL_PINNED_TO_CORE_1 default 0 choice BT_CTRL_HCI_MODE_CHOICE @@ -36,7 +54,7 @@ choice BT_CTRL_HCI_MODE_CHOICE config BT_CTRL_HCI_MODE_VHCI bool "VHCI" help - Normal option. Mostly, choose this VHCI when bluetooth host run on ESP32C3, too. + Normal option. Mostly, choose this VHCI when bluetooth host run on ESP32S3 or ESP32C3. config BT_CTRL_HCI_MODE_UART_H4 bool "UART(H4)" @@ -395,7 +413,6 @@ menu "MODEM SLEEP Options" selects an external 32kHz crystal but the external 32kHz crystal does not exist or the low power clock selects the main crystal. - endmenu config BT_CTRL_SLEEP_MODE_EFF diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 1056981575..82e05b7837 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -20,7 +20,6 @@ #include "esp_types.h" #include "esp_system.h" #include "esp_task.h" -#include "riscv/interrupt.h" #include "esp_attr.h" #include "esp_phy_init.h" #include "esp_bt.h" @@ -34,18 +33,25 @@ #include "soc/soc_memory_layout.h" #include "esp32c3/clk.h" #include "esp_coexist_internal.h" -#include "esp32c3/rom/rom_layout.h" #include "esp_timer.h" #include "esp_sleep.h" +#include "esp_rom_sys.h" #include "phy.h" - +#if CONFIG_IDF_TARGET_ESP32C3 +#include "riscv/interrupt.h" +#include "esp32c3/rom/rom_layout.h" +#else //CONFIG_IDF_TARGET_ESP32S3 +#include "freertos/xtensa_api.h" +#include "xtensa/core-macros.h" +#include "esp32s3/rom/rom_layout.h" +#endif #if CONFIG_BT_ENABLED /* Macro definition ************************************************************************ */ -#define BTDM_LOG_TAG "BTDM_INIT" +#define BT_LOG_TAG "BLE_INIT" #define BTDM_INIT_PERIOD (5000) /* ms */ @@ -125,12 +131,10 @@ typedef struct vhci_host_callback { int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/ } vhci_host_callback_t; -/* Dram region */ typedef struct { - esp_bt_mode_t mode; - intptr_t start; - intptr_t end; -} btdm_dram_available_region_t; + void *handle; + void *storage; +} btdm_queue_item_t; typedef void (* osi_intr_handler)(void); @@ -140,7 +144,7 @@ struct osi_funcs_t { uint32_t _version; void (*_interrupt_set)(int cpu_no, int intr_source, int interrupt_no, int interrpt_prio); void (*_interrupt_clear)(int interrupt_source, int interrupt_no); - void (*_interrupt_handler_set)(int interrupt_no, intr_handler_t fn, void *arg); + void (*_interrupt_handler_set)(int interrupt_no, void *fn, void *arg); void (*_interrupt_disable)(void); void (*_interrupt_restore)(void); void (*_task_yield)(void); @@ -206,7 +210,6 @@ extern void btdm_controller_disable(void); extern uint8_t btdm_controller_get_mode(void); extern const char *btdm_controller_get_compile_version(void); extern void btdm_rf_bb_init_phase2(void); // shall be called after PHY/RF is enabled - /* Sleep */ extern void btdm_controller_enable_sleep(bool enable); extern uint8_t btdm_controller_get_sleep_mode(void); @@ -217,8 +220,8 @@ extern void btdm_in_wakeup_requesting_set(bool in_wakeup_requesting); /* vendor dependent tasks to be posted and handled by controller task*/ extern int btdm_vnd_offload_task_register(btdm_vnd_ol_sig_t sig, btdm_vnd_ol_task_func_t func); extern int btdm_vnd_offload_task_deregister(btdm_vnd_ol_sig_t sig); -extern int btdm_vnd_offload_post_from_isr(btdm_vnd_ol_sig_t sig, void *param, bool need_yield); -extern int btdm_vnd_offload_post(btdm_vnd_ol_sig_t sig, void *param); +extern int r_btdm_vnd_offload_post_from_isr(btdm_vnd_ol_sig_t sig, void *param, bool need_yield); +extern int r_btdm_vnd_offload_post(btdm_vnd_ol_sig_t sig, void *param); /* Low Power Clock */ extern bool btdm_lpclk_select_src(uint32_t sel); @@ -261,13 +264,12 @@ extern uint32_t _btdm_data_end; extern uint32_t _nimble_data_start; extern uint32_t _nimble_data_end; - /* Local Function Declare ********************************************************************* */ static void interrupt_set_wrapper(int cpu_no, int intr_source, int intr_num, int intr_prio); static void interrupt_clear_wrapper(int intr_source, int intr_num); -static void interrupt_handler_set_wrapper(int n, intr_handler_t fn, void *arg); +static void interrupt_handler_set_wrapper(int n, void *fn, void *arg); static void IRAM_ATTR interrupt_disable(void); static void IRAM_ATTR interrupt_restore(void); static void IRAM_ATTR task_yield_from_isr(void); @@ -403,10 +405,11 @@ static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock; void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) { #if CONFIG_MAC_BB_PD +#if CONFIG_IDF_TARGET_ESP32C3 // Bluetooth module power down SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); - +#endif esp_mac_bb_power_down(); #endif } @@ -414,30 +417,15 @@ void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) { #if CONFIG_MAC_BB_PD +#if CONFIG_IDF_TARGET_ESP32C3 // Bluetooth module power up CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); - +#endif esp_mac_bb_power_up(); #endif } -static inline void esp_bt_power_domain_on(void) -{ - // Bluetooth module power up - CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); - CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); - esp_wifi_bt_power_domain_on(); -} - -static inline void esp_bt_power_domain_off(void) -{ - // Bluetooth module power down - SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); - SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); - esp_wifi_bt_power_domain_off(); -} - void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem) { #if CONFIG_MAC_BB_PD @@ -445,31 +433,67 @@ void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uin #endif } +static inline void esp_bt_power_domain_on(void) +{ + // Bluetooth module power up +#if CONFIG_IDF_TARGET_ESP32C3 + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); + CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); +#endif + esp_wifi_bt_power_domain_on(); +} + +static inline void esp_bt_power_domain_off(void) +{ + // Bluetooth module power down +#if CONFIG_IDF_TARGET_ESP32C3 + SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); + SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); +#endif + esp_wifi_bt_power_domain_off(); +} + static void interrupt_set_wrapper(int cpu_no, int intr_source, int intr_num, int intr_prio) { +#if __riscv intr_matrix_route(intr_source, intr_num); esprv_intc_int_set_priority(intr_num, intr_prio); //esprv_intc_int_enable_level(1 << intr_num); esprv_intc_int_set_type(intr_num, 0); +#else + intr_matrix_set(cpu_no, intr_source, intr_num); +#endif } static void interrupt_clear_wrapper(int intr_source, int intr_num) { } -static void interrupt_handler_set_wrapper(int n, intr_handler_t fn, void *arg) +static void interrupt_handler_set_wrapper(int n, void *fn, void *arg) { +#if __riscv intr_handler_set(n, fn, arg); +#else + xt_set_interrupt_handler(n, (xt_handler)fn, arg); +#endif } static void interrupt_on_wrapper(int intr_num) { +#if __riscv esprv_intc_int_enable(1 << intr_num); +#else + xt_ints_on(1 << intr_num); +#endif } static void interrupt_off_wrapper(int intr_num) { - esprv_intc_int_disable(1<handle = (void *)xSemaphoreCreateCounting(max, init); +#else + + semphr->storage = heap_caps_malloc(sizeof(StaticQueue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + assert(semphr->storage); + + semphr->handle = (void *)xSemaphoreCreateCountingStatic(max, init, semphr->storage); +#endif + assert(semphr->handle); + return semphr; } static void semphr_delete_wrapper(void *semphr) { - vSemaphoreDelete(semphr); + if (semphr == NULL) { + return; + } + + btdm_queue_item_t *semphr_item = (btdm_queue_item_t *)semphr; + + if (semphr_item->handle) { + vSemaphoreDelete(semphr_item->handle); + } +#ifdef CONFIG_SPIRAM_USE_MALLOC + if (semphr_item->storage) { + free(semphr_item->storage); + } +#endif + + free(semphr); } static int IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) { - return (int)xSemaphoreTakeFromISR(semphr, hptw); + return (int)xSemaphoreTakeFromISR(((btdm_queue_item_t *)semphr)->handle, hptw); } static int IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) { - return (int)xSemaphoreGiveFromISR(semphr, hptw); + return (int)xSemaphoreGiveFromISR(((btdm_queue_item_t *)semphr)->handle, hptw); } static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) { if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xSemaphoreTake(semphr, portMAX_DELAY); + return (int)xSemaphoreTake(((btdm_queue_item_t *)semphr)->handle, portMAX_DELAY); } else { - return (int)xSemaphoreTake(semphr, block_time_ms / portTICK_PERIOD_MS); + return (int)xSemaphoreTake(((btdm_queue_item_t *)semphr)->handle, block_time_ms / portTICK_PERIOD_MS); } } static int semphr_give_wrapper(void *semphr) { - return (int)xSemaphoreGive(semphr); + return (int)xSemaphoreGive(((btdm_queue_item_t *)semphr)->handle); } static void *mutex_create_wrapper(void) @@ -551,40 +603,71 @@ static int mutex_unlock_wrapper(void *mutex) static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size) { - return (void *)xQueueCreate(queue_len, item_size); + btdm_queue_item_t *queue = NULL; + + queue = (btdm_queue_item_t*)heap_caps_malloc(sizeof(btdm_queue_item_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + assert(queue); + +#if CONFIG_SPIRAM_USE_MALLOC + + queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + assert(queue->storage); + + queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage)); + assert(queue->handle); + +#else + queue->handle = xQueueCreate( queue_len, item_size); + assert(queue->handle); +#endif + + return queue; } static void queue_delete_wrapper(void *queue) { - vQueueDelete(queue); + btdm_queue_item_t *queue_item = (btdm_queue_item_t *)queue; + if (queue_item) { + if(queue_item->handle){ + vQueueDelete(queue_item->handle); + } + +#if CONFIG_SPIRAM_USE_MALLOC + if (queue_item->storage) { + free(queue_item->storage); + } +#endif + + free(queue_item); + } } static int queue_send_wrapper(void *queue, void *item, uint32_t block_time_ms) { if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xQueueSend(queue, item, portMAX_DELAY); + return (int)xQueueSend(((btdm_queue_item_t*)queue)->handle, item, portMAX_DELAY); } else { - return (int)xQueueSend(queue, item, block_time_ms / portTICK_PERIOD_MS); + return (int)xQueueSend(((btdm_queue_item_t*)queue)->handle, item, block_time_ms / portTICK_PERIOD_MS); } } static int IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw) { - return (int)xQueueSendFromISR(queue, item, hptw); + return (int)xQueueSendFromISR(((btdm_queue_item_t*)queue)->handle, item, hptw); } static int queue_recv_wrapper(void *queue, void *item, uint32_t block_time_ms) { if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xQueueReceive(queue, item, portMAX_DELAY); + return (int)xQueueReceive(((btdm_queue_item_t*)queue)->handle, item, portMAX_DELAY); } else { - return (int)xQueueReceive(queue, item, block_time_ms / portTICK_PERIOD_MS); + return (int)xQueueReceive(((btdm_queue_item_t*)queue)->handle, item, block_time_ms / portTICK_PERIOD_MS); } } static int IRAM_ATTR queue_recv_from_isr_wrapper(void *queue, void *item, void *hptw) { - return (int)xQueueReceiveFromISR(queue, item, hptw); + return (int)xQueueReceiveFromISR(((btdm_queue_item_t*)queue)->handle, item, hptw); } static int task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id) @@ -604,13 +687,17 @@ static bool IRAM_ATTR is_in_isr_wrapper(void) static void *malloc_internal_wrapper(size_t size) { - return heap_caps_malloc(size, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA); + void *p = heap_caps_malloc(size, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA); + if(p == NULL) { + ESP_LOGE(BT_LOG_TAG, "Malloc failed"); + } + return p; } static int IRAM_ATTR read_mac_wrapper(uint8_t mac[6]) { int ret = esp_read_mac(mac, ESP_MAC_BT); - ESP_LOGI(BTDM_LOG_TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", + ESP_LOGI(BT_LOG_TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return ret; @@ -685,7 +772,7 @@ static void btdm_sleep_enter_phase1_wrapper(uint32_t lpcycles) if (esp_timer_start_once(s_btdm_slp_tmr, us_to_sleep - uncertainty) == ESP_OK) { s_lp_stat.wakeup_timer_started = 1; } else { - ESP_LOGE(BTDM_LOG_TAG, "timer start failed"); + ESP_LOGE(BT_LOG_TAG, "timer start failed"); assert(0); } } @@ -772,7 +859,7 @@ static void IRAM_ATTR btdm_sleep_exit_phase0(void *param) static void IRAM_ATTR btdm_slp_tmr_callback(void *arg) { #ifdef CONFIG_PM_ENABLE - btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)BTDM_ASYNC_WAKEUP_SRC_TMR); + r_btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)BTDM_ASYNC_WAKEUP_SRC_TMR); #endif } @@ -789,7 +876,7 @@ static bool async_wakeup_request(int event) case BTDM_ASYNC_WAKEUP_SRC_DISA: btdm_in_wakeup_requesting_set(true); if (!btdm_power_state_active()) { - btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)event); + r_btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)event); do_wakeup_request = true; semphr_take_wrapper(s_wakeup_req_sem, OSI_FUNCS_TIME_BLOCKING); } @@ -888,21 +975,21 @@ esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode) mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm; mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } else { mem_start = (intptr_t)ets_rom_layout_p->bss_start_btdm; mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm; mem_end = (intptr_t)ets_rom_layout_p->data_end_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } @@ -913,21 +1000,21 @@ esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode) mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm; mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } else { mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm; mem_end = (intptr_t)ets_rom_layout_p->data_end_interface_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } mem_start = (intptr_t)ets_rom_layout_p->bss_start_interface_btdm; mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } @@ -954,21 +1041,21 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode) mem_start = (intptr_t)&_bt_bss_start; mem_end = (intptr_t)&_btdm_bss_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } else { mem_start = (intptr_t)&_bt_bss_start; mem_end = (intptr_t)&_bt_bss_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release BT BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release BT BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } mem_start = (intptr_t)&_btdm_bss_start; mem_end = (intptr_t)&_btdm_bss_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release BTDM BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release BTDM BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } @@ -979,21 +1066,21 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode) mem_start = (intptr_t)&_bt_data_start; mem_end = (intptr_t)&_btdm_data_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } else { mem_start = (intptr_t)&_bt_data_start; mem_end = (intptr_t)&_bt_data_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release BT Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release BT Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } mem_start = (intptr_t)&_btdm_data_start; mem_end = (intptr_t)&_btdm_data_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release BTDM Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release BTDM Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } @@ -1001,13 +1088,13 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode) mem_start = (intptr_t)&_nimble_bss_start; mem_end = (intptr_t)&_nimble_bss_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release NimBLE BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release NimBLE BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } mem_start = (intptr_t)&_nimble_data_start; mem_end = (intptr_t)&_nimble_data_end; if (mem_start != mem_end) { - ESP_LOGD(BTDM_LOG_TAG, "Release NimBLE Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); + ESP_LOGD(BT_LOG_TAG, "Release NimBLE Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); } } @@ -1021,19 +1108,13 @@ static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end) * is too small to fit a heap. This cannot be termed as a fatal error and hence * we replace it by ESP_OK */ + if (ret == ESP_ERR_INVALID_SIZE) { return ESP_OK; } return ret; } -// release wifi and coex memory, free about 720 bytes, -void esp_release_wifi_and_coex_mem(void) -{ - ESP_ERROR_CHECK(try_heap_caps_add_region((intptr_t)ets_rom_layout_p->dram_start_coexist, (intptr_t)ets_rom_layout_p->dram_end_pp)); - ESP_ERROR_CHECK(try_heap_caps_add_region((intptr_t)ets_rom_layout_p->data_start_interface_coexist,(intptr_t)ets_rom_layout_p->bss_end_interface_pp)); -} - #if CONFIG_MAC_BB_PD static void IRAM_ATTR btdm_mac_bb_power_down_cb(void) { @@ -1066,25 +1147,25 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) if (cfg->controller_task_prio != ESP_TASK_BT_CONTROLLER_PRIO || cfg->controller_task_stack_size < ESP_TASK_BT_CONTROLLER_STACK) { - ESP_LOGE(BTDM_LOG_TAG, "Invalid controller task prioriy or stack size"); + ESP_LOGE(BT_LOG_TAG, "Invalid controller task prioriy or stack size"); return ESP_ERR_INVALID_ARG; } if (cfg->bluetooth_mode != ESP_BT_MODE_BLE) { - ESP_LOGE(BTDM_LOG_TAG, "%s controller only support BLE only mode", __func__); + ESP_LOGE(BT_LOG_TAG, "%s controller only support BLE only mode", __func__); return ESP_ERR_NOT_SUPPORTED; } if (cfg->bluetooth_mode & ESP_BT_MODE_BLE) { if ((cfg->ble_max_act <= 0) || (cfg->ble_max_act > BT_CTRL_BLE_MAX_ACT_LIMIT)) { - ESP_LOGE(BTDM_LOG_TAG, "Invalid value of ble_max_act"); + ESP_LOGE(BT_LOG_TAG, "Invalid value of ble_max_act"); return ESP_ERR_INVALID_ARG; } } if (cfg->sleep_mode == ESP_BT_SLEEP_MODE_1) { if (cfg->sleep_clock == ESP_BT_SLEEP_CLOCK_NONE) { - ESP_LOGE(BTDM_LOG_TAG, "SLEEP_MODE_1 enabled but sleep clock not configured"); + ESP_LOGE(BT_LOG_TAG, "SLEEP_MODE_1 enabled but sleep clock not configured"); return ESP_ERR_INVALID_ARG; } } @@ -1122,7 +1203,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) return ESP_ERR_INVALID_ARG; } - ESP_LOGI(BTDM_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version()); + ESP_LOGI(BT_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version()); // init low-power control resources do { @@ -1173,19 +1254,19 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac); // set default bluetooth sleep clock source - s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value + s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value #if CONFIG_BT_CTRL_LPCLK_SEL_EXT_32K_XTAL // check whether or not EXT_CRYS is working if (rtc_clk_slow_freq_get() == RTC_SLOW_FREQ_32K_XTAL) { s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_XTAL32K; // External 32 kHz XTAL } else { - ESP_LOGW(BTDM_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock."); + ESP_LOGW(BT_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock"); #if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP s_lp_cntl.no_light_sleep = 1; #endif } #elif (CONFIG_BT_CTRL_LPCLK_SEL_MAIN_XTAL) - ESP_LOGI(BTDM_LOG_TAG, "Bluetooth will use main XTAL as Bluetooth sleep clock."); + ESP_LOGI(BT_LOG_TAG, "Bluetooth will use main XTAL as Bluetooth sleep clock."); #if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP s_lp_cntl.no_light_sleep = 1; #endif @@ -1193,10 +1274,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) // check whether or not internal 150 kHz RC oscillator is working if (rtc_clk_slow_freq_get() == RTC_SLOW_FREQ_RTC) { s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_RTC_SLOW; // Internal 150 kHz RC oscillator - ESP_LOGW(BTDM_LOG_TAG, "Internal 150kHz RC osciallator. The accuracy of this clock is a lot larger than 500ppm which is " + ESP_LOGW(BT_LOG_TAG, "Internal 150kHz RC osciallator. The accuracy of this clock is a lot larger than 500ppm which is " "required in Bluetooth communication, so don't select this option in scenarios such as BLE connection state."); } else { - ESP_LOGW(BTDM_LOG_TAG, "Internal 150kHz RC oscillator not detected."); + ESP_LOGW(BT_LOG_TAG, "Internal 150kHz RC oscillator not detected."); assert(0); } #endif @@ -1241,7 +1322,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) err = ESP_ERR_NO_MEM; goto error; } - ESP_LOGW(BTDM_LOG_TAG, "Light sleep mode will not be able to apply when bluetooth is enabled."); + ESP_LOGW(BT_LOG_TAG, "light sleep mode will not be able to apply when bluetooth is enabled."); } if ((err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock)) != ESP_OK) { err = ESP_ERR_NO_MEM; @@ -1390,7 +1471,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) //As the history reason, mode should be equal to the mode which set in esp_bt_controller_init() if (mode != btdm_controller_get_mode()) { - ESP_LOGE(BTDM_LOG_TAG, "invalid mode %d, controller support mode is %d", mode, btdm_controller_get_mode()); + ESP_LOGE(BT_LOG_TAG, "invalid mode %d, controller support mode is %d", mode, btdm_controller_get_mode()); return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/controller/esp32s3/Kconfig.in b/components/bt/controller/esp32s3/Kconfig.in index cf42f0f621..7f8171358c 100644 --- a/components/bt/controller/esp32s3/Kconfig.in +++ b/components/bt/controller/esp32s3/Kconfig.in @@ -1,455 +1 @@ -config BT_CTRL_MODE_EFF - int - default 1 - -config BT_CTRL_BLE_MAX_ACT - int "BLE Max Instances" - default 10 - range 1 10 - help - BLE maximum instances of bluetooth controller. - -config BT_CTRL_BLE_MAX_ACT_EFF - int - default BT_CTRL_BLE_MAX_ACT - default 0 - -config BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB - int "BLE static ACL TX buffer numbers" - range 0 12 - default 0 - help - BLE ACL buffer have two methods to be allocated. One is persistent allocating - (alloate when controller initialise, never free until controller de-initialise) - another is dynamically allocating (allocate before TX and free after TX). - -choice BT_CTRL_PINNED_TO_CORE_CHOICE - prompt "The cpu core which bluetooth controller run" - depends on !FREERTOS_UNICORE - help - Specify the cpu core to run bluetooth controller. - Can not specify no-affinity. - - config BT_CTRL_PINNED_TO_CORE_0 - bool "Core 0 (PRO CPU)" - config BT_CTRL_PINNED_TO_CORE_1 - bool "Core 1 (APP CPU)" - depends on !FREERTOS_UNICORE -endchoice - -config BT_CTRL_PINNED_TO_CORE - int - default 0 if BT_CTRL_PINNED_TO_CORE_0 - default 1 if BT_CTRL_PINNED_TO_CORE_1 - default 0 - -choice BT_CTRL_HCI_MODE_CHOICE - prompt "HCI mode" - help - Specify HCI mode as VHCI or UART(H4) - - config BT_CTRL_HCI_MODE_VHCI - bool "VHCI" - help - Normal option. Mostly, choose this VHCI when bluetooth host run on ESP32S3, too. - - config BT_CTRL_HCI_MODE_UART_H4 - bool "UART(H4)" - help - If use external bluetooth host which run on other hardware and use UART as the HCI interface, - choose this option. -endchoice - -config BT_CTRL_HCI_TL - int - default 0 if BT_CTRL_HCI_MODE_UART_H4 - default 1 if BT_CTRL_HCI_M0DE_VHCI - default 1 - help - HCI mode as VHCI or UART(H4) - -config BT_CTRL_ADV_DUP_FILT_MAX - int "The maxinum number of 5.0 extend duplicate scan filter" - range 1 500 - default 30 - help - The maxinum number of suplicate scan filter - -config BT_CTRL_HW_CCA - bool "HW CCA check enable" - default n - help - It enables HW CCA feature in controller - -config BT_CTRL_HW_CCA_VAL - int "CCA threshold value" - range 20 60 - default 20 - help - It is the threshold value of HW CCA, if the value is 30, it means CCA threshold is -30 dBm. - -config BT_CTRL_HW_CCA_EFF - int - default 1 if BT_CTRL_HW_CCA - default 0 - help - If other devices are sending packets in the air and the signal is strong, - the packet hw to be sent this time is cancelled. - -choice BT_CTRL_CE_LENGTH_TYPE - prompt "Connection event length determination method" - help - Specify connection event length determination - - config BT_CTRL_CE_LENGTH_TYPE_ORIG - bool "ORIGINAL" - config BT_CTRL_CE_LENGTH_TYPE_CE - bool "Use CE parameter for HCI command" - config BT_CTRL_CE_LENGTH_TYPE_SD - bool "Use Espressif self-defined method" -endchoice - -config BT_CTRL_CE_LENGTH_TYPE_EFF - int - default 0 if BT_CTRL_CE_LENGTH_TYPE_ORIG - default 1 if BT_CTRL_CE_LENGTH_TYPE_CE - default 2 if BT_CTRL_CE_LENGTH_TYPE_SD - -choice BT_CTRL_TX_ANTENNA_INDEX - prompt "default Tx anntena used" - help - Specify default Tx antenna used for bluetooth - - config BT_CTRL_TX_ANTENNA_INDEX_0 - bool "Antenna 0" - config BT_CTRL_TX_ANTENNA_INDEX_1 - bool "Antenna 1" -endchoice - -config BT_CTRL_TX_ANTENNA_INDEX_EFF - int - default 0 if BT_CTRL_TX_ANTENNA_INDEX_0 - default 1 if BT_CTRL_TX_ANTENNA_INDEX_1 - -choice BT_CTRL_RX_ANTENNA_INDEX - prompt "default Rx anntena used" - help - Specify default Rx antenna used for bluetooth - - config BT_CTRL_RX_ANTENNA_INDEX_0 - bool "Antenna 0" - config BT_CTRL_RX_ANTENNA_INDEX_1 - bool "Antenna 1" -endchoice - -config BT_CTRL_RX_ANTENNA_INDEX_EFF - int - default 0 if BT_CTRL_RX_ANTENNA_INDEX_0 - default 1 if BT_CTRL_RX_ANTENNA_INDEX_1 - -choice BT_CTRL_DFT_TX_POWER_LEVEL - prompt "BLE default Tx power level" - default BT_CTRL_DFT_TX_POWER_LEVEL_P9 - help - Specify default Tx power level - - config BT_CTRL_DFT_TX_POWER_LEVEL_N24 - bool "-24dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N21 - bool "-21dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N18 - bool "-18dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N15 - bool "-15dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N12 - bool "-12dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N9 - bool "-9dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N6 - bool "-6dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N3 - bool "-3dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_N0 - bool "0dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P3 - bool "+3dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P6 - bool "+6dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P9 - bool "+9dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P12 - bool "+12dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P15 - bool "+15dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P18 - bool "+18dBm" - config BT_CTRL_DFT_TX_POWER_LEVEL_P18 - bool "+21dBm" - -endchoice - -config BT_CTRL_DFT_TX_POWER_LEVEL_EFF - int - default 0 if BT_CTRL_DFT_TX_POWER_LEVEL_N24 - default 1 if BT_CTRL_DFT_TX_POWER_LEVEL_N21 - default 2 if BT_CTRL_DFT_TX_POWER_LEVEL_N18 - default 3 if BT_CTRL_DFT_TX_POWER_LEVEL_N15 - default 4 if BT_CTRL_DFT_TX_POWER_LEVEL_N12 - default 5 if BT_CTRL_DFT_TX_POWER_LEVEL_N9 - default 6 if BT_CTRL_DFT_TX_POWER_LEVEL_N6 - default 7 if BT_CTRL_DFT_TX_POWER_LEVEL_N3 - default 8 if BT_CTRL_DFT_TX_POWER_LEVEL_N0 - default 9 if BT_CTRL_DFT_TX_POWER_LEVEL_P3 - default 10 if BT_CTRL_DFT_TX_POWER_LEVEL_P6 - default 11 if BT_CTRL_DFT_TX_POWER_LEVEL_P9 - default 12 if BT_CTRL_DFT_TX_POWER_LEVEL_P12 - default 13 if BT_CTRL_DFT_TX_POWER_LEVEL_P15 - default 14 if BT_CTRL_DFT_TX_POWER_LEVEL_P18 - default 15 if BT_CTRL_DFT_TX_POWER_LEVEL_P21 - - default 0 - -config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP - bool "BLE adv report flow control supported" - default y - help - The function is mainly used to enable flow control for advertising reports. When it is enabled, - advertising reports will be discarded by the controller if the number of unprocessed advertising - reports exceeds the size of BLE adv report flow control. - -config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM - int "BLE adv report flow control number" - depends on BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP - range 50 1000 - default 100 - help - The number of unprocessed advertising report that bluetooth host can save.If you set - `BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` to a small value, this may cause adv packets lost. - If you set `BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` to a large value, bluetooth host may cache a - lot of adv packets and this may cause system memory run out. For example, if you set - it to 50, the maximum memory consumed by host is 35 * 50 bytes. Please set - `BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` according to your system free memory and handle adv - packets as fast as possible, otherwise it will cause adv packets lost. - -config BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD - int "BLE adv lost event threshold value" - depends on BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP - range 1 1000 - default 20 - help - When adv report flow control is enabled, The ADV lost event will be generated when the number - of ADV packets lost in the controller reaches this threshold. It is better to set a larger value. - If you set `BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD` to a small value or printf every adv lost event, it - may cause adv packets lost more. - -config BT_CTRL_BLE_SCAN_DUPL - bool "BLE Scan Duplicate Options" - default y - help - This select enables parameters setting of BLE scan duplicate. - -choice BT_CTRL_SCAN_DUPL_TYPE - prompt "Scan Duplicate Type" - default BT_CTRL_SCAN_DUPL_TYPE_DEVICE - depends on BT_CTRL_BLE_SCAN_DUPL - help - Scan duplicate have three ways. one is "Scan Duplicate By Device Address", This way is to use - advertiser address filtering. The adv packet of the same address is only allowed to be reported once. - Another way is "Scan Duplicate By Device Address And Advertising Data". This way is to use advertising - data and device address filtering. All different adv packets with the same address are allowed to be - reported. The last way is "Scan Duplicate By Advertising Data". This way is to use advertising data - filtering. All same advertising data only allow to be reported once even though they are from - different devices. - - config BT_CTRL_SCAN_DUPL_TYPE_DEVICE - bool "Scan Duplicate By Device Address" - help - This way is to use advertiser address filtering. The adv packet of the same address is only - allowed to be reported once - - config BT_CTRL_SCAN_DUPL_TYPE_DATA - bool "Scan Duplicate By Advertising Data" - help - This way is to use advertising data filtering. All same advertising data only allow to be reported - once even though they are from different devices. - - config BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE - bool "Scan Duplicate By Device Address And Advertising Data" - help - This way is to use advertising data and device address filtering. All different adv packets with - the same address are allowed to be reported. -endchoice - -config BT_CTRL_SCAN_DUPL_TYPE - int - depends on BT_CTRL_BLE_SCAN_DUPL - default 0 if BT_CTRL_SCAN_DUPL_TYPE_DEVICE - default 1 if BT_CTRL_SCAN_DUPL_TYPE_DATA - default 2 if BT_CTRL_SCAN_DUPL_TYPE_DATA_DEVICE - default 0 - -config BT_CTRL_SCAN_DUPL_CACHE_SIZE - int "Maximum number of devices in scan duplicate filter" - depends on BT_CTRL_BLE_SCAN_DUPL - range 10 1000 - default 100 - help - Maximum number of devices which can be recorded in scan duplicate filter. - When the maximum amount of device in the filter is reached, the cache will be refreshed. - -config BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD - int "Duplicate scan list refresh period (seconds)" - depends on BT_CTRL_BLE_SCAN_DUPL - range 0 1000 - default 0 - help - If the period value is non-zero, the controller will periodically clear the device information - stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared - until the scanning is disabled. Duplicate advertisements for this period should not be sent to the - Host in advertising report events. - There are two scenarios where the ADV packet will be repeatedly reported: - 1. The duplicate scan cache is full, the controller will delete the oldest device information and - add new device information. - 2. When the refresh period is up, the controller will clear all device information and start filtering - again. - -config BT_CTRL_BLE_MESH_SCAN_DUPL_EN - bool "Special duplicate scan mechanism for BLE Mesh scan" - depends on BT_CTRL_BLE_SCAN_DUPL - default n - help - This enables the BLE scan duplicate for special BLE Mesh scan. - -config BT_CTRL_MESH_DUPL_SCAN_CACHE_SIZE - int "Maximum number of Mesh adv packets in scan duplicate filter" - depends on BT_CTRL_BLE_MESH_SCAN_DUPL_EN - range 10 1000 - default 100 - help - Maximum number of adv packets which can be recorded in duplicate scan cache for BLE Mesh. - When the maximum amount of device in the filter is reached, the cache will be refreshed. - -choice BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM - prompt "Coexistence: limit on MAX Tx/Rx time for coded-PHY connection" - default BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS - depends on ESP32_WIFI_SW_COEXIST_ENABLE - help - When using PHY-Coded in BLE connection, limitation on max tx/rx time can be applied to - better avoid dramatic performance deterioration of Wi-Fi. - - config BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EN - bool "Force Enable" - help - Always enable the limitation on max tx/rx time for Coded-PHY connection - - config BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS - bool "Force Disable" - help - Disable the limitation on max tx/rx time for Coded-PHY connection -endchoice - -config BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF - int - default 0 if (!ESP32_WIFI_SW_COEXIST_ENABLE) - default 1 if BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EN - default 0 if BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_DIS - -menu "MODEM SLEEP Options" - visible if BT_ENABLED - - config BT_CTRL_MODEM_SLEEP - bool "Bluetooth modem sleep" - depends on !BT_CTRL_HCI_MODE_UART_H4 - default n - help - Enable/disable bluetooth controller low power mode. - Modem sleep is not supported to be used with UART HCI. - - config BT_CTRL_MODEM_SLEEP_MODE_1 - bool "Bluetooth Modem sleep Mode 1" - depends on BT_CTRL_MODEM_SLEEP - default y - help - Mode 1 is the currently supported sleep mode. In this mode, - bluetooth controller sleeps between and BLE events. A low - power clock is used to maintain bluetooth reference clock. - - choice BT_CTRL_LOW_POWER_CLOCK - prompt "Bluetooth low power clock" - depends on BT_CTRL_MODEM_SLEEP_MODE_1 - help - Select the low power clock source for bluetooth controller - - config BT_CTRL_LPCLK_SEL_MAIN_XTAL - bool "Main crystal" - help - Main crystal can be used as low power clock for bluetooth modem sleep. If this option is - selected, bluetooth modem sleep can work under Dynamic Frequency Scaling(DFS) enabled, and - bluetooth can work under light sleep enabled. Main crystal has a relatively better performance - than other bluetooth low power clock sources. - config BT_CTRL_LPCLK_SEL_EXT_32K_XTAL - bool "External 32kHz crystal" - depends on ESP32S3_RTC_CLK_SRC_EXT_CRYS - help - External 32kHz crystal has a nominal frequency of 32.768kHz and provides good frequency - stability. If used as Bluetooth low power clock, External 32kHz can support Bluetooth - modem sleep to be used with both DFS and light sleep. - - config BT_CTRL_LPCLK_SEL_RTC_SLOW - bool "Internal 150kHz RC oscillator" - depends on ESP32S3_RTC_CLK_SRC_INT_RC - help - Internal 150kHz RC oscillator. The accuracy of this clock is a lot larger than 500ppm which is required - in Bluetooth communication, so don't select this option in scenarios such as BLE connection state. - endchoice - - config BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - bool "power up main XTAL during light sleep" - depends on (BT_CTRL_LPCLK_SEL_MAIN_XTAL || BT_CTRL_LPCLK_SEL_EXT_32K_XTAL) && FREERTOS_USE_TICKLESS_IDLE - default n - help - If this option is selected, the main crystal will power up during light sleep when the low power clock - selects an external 32kHz crystal but the external 32kHz crystal does not exist or the low power clock - selects the main crystal. - -endmenu - -config BT_CTRL_SLEEP_MODE_EFF - int - default 1 if BT_CTRL_MODEM_SLEEP_MODE_1 - default 0 - -config BT_CTRL_SLEEP_CLOCK_EFF - int - default 1 if BT_CTRL_LPCLK_SEL_MAIN_XTAL - default 2 if BT_CTRL_LPCLK_SEL_EXT_32K_XTAL - default 3 if BT_CTRL_LPCLK_SEL_RTC_SLOW - - default 0 - -config BT_CTRL_HCI_TL_EFF - int - default 0 if BT_CTRL_HCI_MODE_UART_H4 - default 1 if BT_CTRL_HCI_M0DE_VHCI - default 1 - -config BT_CTRL_AGC_RECORRECT_EN - bool "Enable HW AGC recorrect" - default n - help - Enable uncoded phy AGC recorrect - -config BT_CTRL_CODED_AGC_RECORRECT_EN - bool "Enable coded phy AGC recorrect" - depends on BT_CTRL_AGC_RECORRECT_EN - default n - help - Enable coded phy AGC recorrect - -config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX - bool "Disable active scan backoff" - default n - help - Disable active scan backoff. The bluetooth spec requires that scanners should run a backoff procedure to - minimize collision of scan request PDUs from nultiple scanners. If scan backoff is disabled, in active - scanning, scan request PDU will be sent every time when HW receives scannable ADV PDU. +source "$IDF_PATH/components/bt/controller/esp32c3/Kconfig.in" diff --git a/components/bt/controller/esp32s3/bt.c b/components/bt/controller/esp32s3/bt.c deleted file mode 100644 index 131f70c94d..0000000000 --- a/components/bt/controller/esp32s3/bt.c +++ /dev/null @@ -1,1653 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include "sdkconfig.h" -#include "esp_heap_caps.h" -#include "esp_heap_caps_init.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" -#include "freertos/xtensa_api.h" -#include "freertos/portmacro.h" -#include "xtensa/core-macros.h" -#include "esp_types.h" -#include "esp_system.h" -#include "esp_task.h" -#include "esp_attr.h" -#include "esp_phy_init.h" -#include "esp_bt.h" -#include "esp_err.h" -#include "esp_log.h" -#include "esp_pm.h" -#include "esp_ipc.h" -#include "driver/periph_ctrl.h" -#include "soc/rtc.h" -#include "soc/rtc_cntl_reg.h" -#include "soc/soc_memory_layout.h" -#include "esp32c3/clk.h" -#include "esp_coexist_internal.h" -#include "esp_timer.h" -#include "esp_sleep.h" -#include "esp_rom_sys.h" -#include "esp32s3/rom/rom_layout.h" - -#if CONFIG_BT_ENABLED - -/* Macro definition - ************************************************************************ - */ - -#define BT_LOG_TAG "BT_INIT" - -#define BTDM_INIT_PERIOD (5000) /* ms */ - -/* Low Power Clock Selection */ -#define BTDM_LPCLK_SEL_XTAL (0) -#define BTDM_LPCLK_SEL_XTAL32K (1) -#define BTDM_LPCLK_SEL_RTC_SLOW (2) -#define BTDM_LPCLK_SEL_8M (3) - -// wakeup request sources -enum { - BTDM_ASYNC_WAKEUP_SRC_VHCI = 0, - BTDM_ASYNC_WAKEUP_SRC_DISA, - BTDM_ASYNC_WAKEUP_SRC_TMR, - BTDM_ASYNC_WAKEUP_SRC_MAX, -}; - -// low power control struct -typedef union { - struct { - uint32_t enable : 1; // whether low power mode is required - uint32_t lpclk_sel : 2; // low power clock source - uint32_t mac_bb_pd : 1; // whether hardware(MAC, BB) force-power-down is required during sleep - uint32_t wakeup_timer_required : 1; // whether system timer is needed - uint32_t no_light_sleep : 1; // do not allow system to enter light sleep after bluetooth is enabled - uint32_t main_xtal_pu : 1; // power up main XTAL - uint32_t reserved : 25; // reserved - }; - uint32_t val; -} btdm_lpcntl_t; - -// low power control status -typedef union { - struct { - uint32_t pm_lock_released : 1; // whether power management lock is released - uint32_t mac_bb_pd : 1; // whether hardware(MAC, BB) is powered down - uint32_t phy_enabled : 1; // whether phy is switched on - uint32_t wakeup_timer_started : 1; // whether wakeup timer is started - uint32_t reserved : 28; // reserved - }; - uint32_t val; -} btdm_lpstat_t; - -/* Sleep and wakeup interval control */ -#define BTDM_MIN_SLEEP_DURATION (24) // threshold of interval in half slots to allow to fall into modem sleep -#define BTDM_MODEM_WAKE_UP_DELAY (8) // delay in half slots of modem wake up procedure, including re-enable PHY/RF - -#define BT_DEBUG(...) -#define BT_API_CALL_CHECK(info, api_call, ret) \ -do{\ - esp_err_t __err = (api_call);\ - if ((ret) != __err) {\ - BT_DEBUG("%s %d %s ret=0x%X\n", __FUNCTION__, __LINE__, (info), __err);\ - return __err;\ - }\ -} while(0) - -#define OSI_FUNCS_TIME_BLOCKING 0xffffffff -#define OSI_VERSION 0x00010006 -#define OSI_MAGIC_VALUE 0xFADEBEAD - -/* Types definition - ************************************************************************ - */ -/* vendor dependent signals to be posted to controller task */ -typedef enum { - BTDM_VND_OL_SIG_WAKEUP_TMR = 0, - BTDM_VND_OL_SIG_NUM, -} btdm_vnd_ol_sig_t; - -/* prototype of function to handle vendor dependent signals */ -typedef void (* btdm_vnd_ol_task_func_t)(void *param); - -/* VHCI function interface */ -typedef struct vhci_host_callback { - void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */ - int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/ -} vhci_host_callback_t; - -/* Dram region */ -typedef struct { - esp_bt_mode_t mode; - intptr_t start; - intptr_t end; -} btdm_dram_available_region_t; - -typedef struct { - void *handle; - void *storage; -} btdm_queue_item_t; - -typedef void (* osi_intr_handler)(void); - -/* OSI function */ -struct osi_funcs_t { - uint32_t _magic; - uint32_t _version; - void (*_interrupt_set)(int32_t cpu_no, int32_t intr_source, int32_t interrupt_no, int32_t interrpt_prio); - void (*_interrupt_clear)(int32_t interrupt_source, int32_t interrupt_no); - void (*_interrupt_handler_set)(int32_t interrupt_no, void *fn, void *arg); - void (*_interrupt_disable)(void); - void (*_interrupt_restore)(void); - void (*_task_yield)(void); - void (*_task_yield_from_isr)(void); - void *(*_semphr_create)(uint32_t max, uint32_t init); - void (*_semphr_delete)(void *semphr); - int32_t (*_semphr_take_from_isr)(void *semphr, void *hptw); - int32_t (*_semphr_give_from_isr)(void *semphr, void *hptw); - int32_t (*_semphr_take)(void *semphr, uint32_t block_time_ms); - int32_t (*_semphr_give)(void *semphr); - void *(*_mutex_create)(void); - void (*_mutex_delete)(void *mutex); - int32_t (*_mutex_lock)(void *mutex); - int32_t (*_mutex_unlock)(void *mutex); - void *(* _queue_create)(uint32_t queue_len, uint32_t item_size); - void (* _queue_delete)(void *queue); - int32_t (* _queue_send)(void *queue, void *item, uint32_t block_time_ms); - int32_t (* _queue_send_from_isr)(void *queue, void *item, void *hptw); - int32_t (* _queue_recv)(void *queue, void *item, uint32_t block_time_ms); - int32_t (* _queue_recv_from_isr)(void *queue, void *item, void *hptw); - int32_t (* _task_create)(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id); - void (* _task_delete)(void *task_handle); - bool (* _is_in_isr)(void); - int (* _cause_sw_intr_to_core)(int core_id, int intr_no); - void *(* _malloc)(size_t size); - void *(* _malloc_internal)(size_t size); - void (* _free)(void *p); - int32_t (* _read_efuse_mac)(uint8_t mac[6]); - void (* _srand)(unsigned int seed); - int (* _rand)(void); - uint32_t (* _btdm_lpcycles_2_hus)(uint32_t cycles, uint32_t *error_corr); - uint32_t (* _btdm_hus_2_lpcycles)(uint32_t hus); - bool (* _btdm_sleep_check_duration)(int32_t *slot_cnt); - void (* _btdm_sleep_enter_phase1)(uint32_t lpcycles); /* called when interrupt is disabled */ - void (* _btdm_sleep_enter_phase2)(void); - void (* _btdm_sleep_exit_phase1)(void); /* called from ISR */ - void (* _btdm_sleep_exit_phase2)(void); /* called from ISR */ - void (* _btdm_sleep_exit_phase3)(void); /* called from task */ - void (* _coex_wifi_sleep_set)(bool sleep); - int (* _coex_core_ble_conn_dyn_prio_get)(bool *low, bool *high); - void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status); - void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); - void (* _interrupt_on)(int intr_num); - void (* _interrupt_off)(int intr_num); - void (* _esp_hw_power_down)(void); - void (* _esp_hw_power_up)(void); - void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem); -}; - - -/* External functions or values - ************************************************************************ - */ - -/* not for user call, so don't put to include file */ -/* OSI */ -extern int btdm_osi_funcs_register(void *osi_funcs); -/* Initialise and De-initialise */ -extern int btdm_controller_init(esp_bt_controller_config_t *config_opts); -extern void btdm_controller_deinit(void); -extern int btdm_controller_enable(esp_bt_mode_t mode); -extern void btdm_controller_disable(void); -extern uint8_t btdm_controller_get_mode(void); -extern const char *btdm_controller_get_compile_version(void); -extern void btdm_rf_bb_init_phase2(void); // shall be called after PHY/RF is enabled -/* Sleep */ -extern void btdm_controller_enable_sleep(bool enable); -extern uint8_t btdm_controller_get_sleep_mode(void); -extern bool btdm_power_state_active(void); -extern void btdm_wakeup_request(void); -extern void btdm_in_wakeup_requesting_set(bool in_wakeup_requesting); - -/* vendor dependent tasks to be posted and handled by controller task*/ -extern int btdm_vnd_offload_task_register(btdm_vnd_ol_sig_t sig, btdm_vnd_ol_task_func_t func); -extern int btdm_vnd_offload_task_deregister(btdm_vnd_ol_sig_t sig); -extern int btdm_vnd_offload_post_from_isr(btdm_vnd_ol_sig_t sig, void *param, bool need_yield); -extern int btdm_vnd_offload_post(btdm_vnd_ol_sig_t sig, void *param); - -/* Low Power Clock */ -extern bool btdm_lpclk_select_src(uint32_t sel); -extern bool btdm_lpclk_set_div(uint32_t div); -extern int btdm_hci_tl_io_event_post(int event); - -/* VHCI */ -extern bool API_vhci_host_check_send_available(void); -extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len); -extern int API_vhci_host_register_callback(const vhci_host_callback_t *callback); -/* TX power */ -extern int ble_txpwr_set(int power_type, int power_level); -extern int ble_txpwr_get(int power_type); - -extern uint16_t l2c_ble_link_get_tx_buf_num(void); -extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high); -extern void coex_pti_v2(void); - -extern bool btdm_deep_sleep_mem_init(void); -extern void btdm_deep_sleep_mem_deinit(void); -extern void btdm_ble_power_down_dma_copy(bool copy); -extern uint8_t btdm_sleep_clock_sync(void); - -#if CONFIG_MAC_BB_PD -extern void esp_mac_bb_power_down(void); -extern void esp_mac_bb_power_up(void); -extern void ets_backup_dma_copy(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); -#endif - -extern uint32_t _bt_bss_start; -extern uint32_t _bt_bss_end; -extern uint32_t _btdm_bss_start; -extern uint32_t _btdm_bss_end; -extern uint32_t _nimble_bss_start; -extern uint32_t _nimble_bss_end; -extern uint32_t _bt_data_start; -extern uint32_t _bt_data_end; -extern uint32_t _btdm_data_start; -extern uint32_t _btdm_data_end; -extern uint32_t _nimble_data_start; -extern uint32_t _nimble_data_end; - -/* Local Function Declare - ********************************************************************* - */ -static void interrupt_set_wrapper(int32_t cpu_no, int32_t intr_source, int32_t intr_num, int32_t intr_prio); -static void interrupt_clear_wrapper(int32_t intr_source, int32_t intr_num); -static void interrupt_handler_set_wrapper(int n, void *fn, void *arg); -static void IRAM_ATTR interrupt_disable(void); -static void IRAM_ATTR interrupt_restore(void); -static void IRAM_ATTR task_yield_from_isr(void); -static void *semphr_create_wrapper(uint32_t max, uint32_t init); -static void semphr_delete_wrapper(void *semphr); -static int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw); -static int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw); -static int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_ms); -static int32_t semphr_give_wrapper(void *semphr); -static void *mutex_create_wrapper(void); -static void mutex_delete_wrapper(void *mutex); -static int32_t mutex_lock_wrapper(void *mutex); -static int32_t mutex_unlock_wrapper(void *mutex); -static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size); -static void queue_delete_wrapper(void *queue); -static int32_t queue_send_wrapper(void *queue, void *item, uint32_t block_time_ms); -static int32_t IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw); -static int32_t queue_recv_wrapper(void *queue, void *item, uint32_t block_time_ms); -static int32_t IRAM_ATTR queue_recv_from_isr_wrapper(void *queue, void *item, void *hptw); -static int32_t task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id); -static void task_delete_wrapper(void *task_handle); -static bool IRAM_ATTR is_in_isr_wrapper(void); -static void *malloc_internal_wrapper(size_t size); -static int32_t IRAM_ATTR read_mac_wrapper(uint8_t mac[6]); -static void IRAM_ATTR srand_wrapper(unsigned int seed); -static int IRAM_ATTR rand_wrapper(void); -static uint32_t IRAM_ATTR btdm_lpcycles_2_hus(uint32_t cycles, uint32_t *error_corr); -static uint32_t IRAM_ATTR btdm_hus_2_lpcycles(uint32_t hus); -static bool IRAM_ATTR btdm_sleep_check_duration(int32_t *slot_cnt); -static void btdm_sleep_enter_phase1_wrapper(uint32_t lpcycles); -static void btdm_sleep_enter_phase2_wrapper(void); -static void btdm_sleep_exit_phase3_wrapper(void); -static void coex_wifi_sleep_set_hook(bool sleep); -static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status); -static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status); -static void interrupt_on_wrapper(int intr_num); -static void interrupt_off_wrapper(int intr_num); -static void btdm_hw_mac_power_up_wrapper(void); -static void btdm_hw_mac_power_down_wrapper(void); -static void btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); - -static void btdm_slp_tmr_callback(void *arg); - -static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end); - -static void bt_controller_deinit_internal(void); - -/* Local variable definition - *************************************************************************** - */ -/* OSI funcs */ -static const struct osi_funcs_t osi_funcs_ro = { - ._magic = OSI_MAGIC_VALUE, - ._version = OSI_VERSION, - ._interrupt_set = interrupt_set_wrapper, - ._interrupt_clear = interrupt_clear_wrapper, - ._interrupt_handler_set = interrupt_handler_set_wrapper, - ._interrupt_disable = interrupt_disable, - ._interrupt_restore = interrupt_restore, - ._task_yield = vPortYield, - ._task_yield_from_isr = task_yield_from_isr, - ._semphr_create = semphr_create_wrapper, - ._semphr_delete = semphr_delete_wrapper, - ._semphr_take_from_isr = semphr_take_from_isr_wrapper, - ._semphr_give_from_isr = semphr_give_from_isr_wrapper, - ._semphr_take = semphr_take_wrapper, - ._semphr_give = semphr_give_wrapper, - ._mutex_create = mutex_create_wrapper, - ._mutex_delete = mutex_delete_wrapper, - ._mutex_lock = mutex_lock_wrapper, - ._mutex_unlock = mutex_unlock_wrapper, - ._queue_create = queue_create_wrapper, - ._queue_delete = queue_delete_wrapper, - ._queue_send = queue_send_wrapper, - ._queue_send_from_isr = queue_send_from_isr_wrapper, - ._queue_recv = queue_recv_wrapper, - ._queue_recv_from_isr = queue_recv_from_isr_wrapper, - ._task_create = task_create_wrapper, - ._task_delete = task_delete_wrapper, - ._is_in_isr = is_in_isr_wrapper, - ._cause_sw_intr_to_core = NULL, - ._malloc = malloc, - ._malloc_internal = malloc_internal_wrapper, - ._free = free, - ._read_efuse_mac = read_mac_wrapper, - ._srand = srand_wrapper, - ._rand = rand_wrapper, - ._btdm_lpcycles_2_hus = btdm_lpcycles_2_hus, - ._btdm_hus_2_lpcycles = btdm_hus_2_lpcycles, - ._btdm_sleep_check_duration = btdm_sleep_check_duration, - ._btdm_sleep_enter_phase1 = btdm_sleep_enter_phase1_wrapper, - ._btdm_sleep_enter_phase2 = btdm_sleep_enter_phase2_wrapper, - ._btdm_sleep_exit_phase1 = NULL, - ._btdm_sleep_exit_phase2 = NULL, - ._btdm_sleep_exit_phase3 = btdm_sleep_exit_phase3_wrapper, - ._coex_wifi_sleep_set = coex_wifi_sleep_set_hook, - ._coex_core_ble_conn_dyn_prio_get = coex_core_ble_conn_dyn_prio_get, - ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, - ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, - ._interrupt_on = interrupt_on_wrapper, - ._interrupt_off = interrupt_off_wrapper, - ._esp_hw_power_down = btdm_hw_mac_power_down_wrapper, - ._esp_hw_power_up = btdm_hw_mac_power_up_wrapper, - ._ets_backup_dma_copy = btdm_backup_dma_copy_wrapper, -}; - -static DRAM_ATTR struct osi_funcs_t *osi_funcs_p; - -/* Static variable declare */ -static DRAM_ATTR esp_bt_controller_status_t btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; - -static DRAM_ATTR portMUX_TYPE global_int_mux = portMUX_INITIALIZER_UNLOCKED; - -// low power control struct -static DRAM_ATTR btdm_lpcntl_t s_lp_cntl; -// low power status struct -static DRAM_ATTR btdm_lpstat_t s_lp_stat; -// measured average low power clock period in micro seconds -static DRAM_ATTR uint32_t btdm_lpcycle_us = 0; -// number of fractional bit for btdm_lpcycle_us -static DRAM_ATTR uint8_t btdm_lpcycle_us_frac = 0; -// semaphore used for blocking VHCI API to wait for controller to wake up -static DRAM_ATTR QueueHandle_t s_wakeup_req_sem = NULL; -// wakeup timer -static DRAM_ATTR esp_timer_handle_t s_btdm_slp_tmr; - -#ifdef CONFIG_PM_ENABLE -static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock; -// pm_lock to prevent light sleep due to incompatibility currently -static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock; -#endif - -void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) -{ -#if CONFIG_MAC_BB_PD - esp_mac_bb_power_down(); -#endif -} - -void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) -{ -#if CONFIG_MAC_BB_PD - esp_mac_bb_power_up(); -#endif -} - -void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem) -{ -#if CONFIG_MAC_BB_PD - ets_backup_dma_copy(reg, mem_addr, num, to_mem); -#endif -} - -static inline void esp_bt_power_domain_on(void) -{ - // Bluetooth module power up - esp_wifi_bt_power_domain_on(); -} - -static inline void esp_bt_power_domain_off(void) -{ - // Bluetooth module power down - esp_wifi_bt_power_domain_off(); -} - -static void interrupt_set_wrapper(int32_t cpu_no, int32_t intr_source, int32_t intr_num, int32_t intr_prio) -{ - intr_matrix_set(cpu_no, intr_source, intr_num); -} - -static void interrupt_clear_wrapper(int32_t intr_source, int32_t intr_num) -{ -} - -static void interrupt_handler_set_wrapper(int32_t n, void *fn, void *arg) -{ - xt_set_interrupt_handler(n, (xt_handler)fn, arg); -} - -static void interrupt_on_wrapper(int intr_num) -{ - xt_ints_on(1 << intr_num); -} - -static void interrupt_off_wrapper(int intr_num) -{ - xt_ints_off(1 << intr_num); -} - -static void IRAM_ATTR interrupt_disable(void) -{ - if (xPortInIsrContext()) { - portENTER_CRITICAL_ISR(&global_int_mux); - } else { - portENTER_CRITICAL(&global_int_mux); - } -} - -static void IRAM_ATTR interrupt_restore(void) -{ - if (xPortInIsrContext()) { - portEXIT_CRITICAL_ISR(&global_int_mux); - } else { - portEXIT_CRITICAL(&global_int_mux); - } -} - -static void IRAM_ATTR task_yield_from_isr(void) -{ - portYIELD_FROM_ISR(); -} - -static void *semphr_create_wrapper(uint32_t max, uint32_t init) -{ - btdm_queue_item_t *semphr = heap_caps_calloc(1, sizeof(btdm_queue_item_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - assert(semphr); - -#if !CONFIG_SPIRAM_USE_MALLOC - semphr->handle = (void *)xSemaphoreCreateCounting(max, init); -#else - - semphr->storage = heap_caps_malloc(sizeof(StaticQueue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - assert(semphr->storage); - - semphr->handle = (void *)xSemaphoreCreateCountingStatic(max, init, semphr->storage); -#endif - assert(semphr->handle); - return semphr; -} - -static void semphr_delete_wrapper(void *semphr) -{ - if (semphr == NULL) { - return; - } - - btdm_queue_item_t *semphr_item = (btdm_queue_item_t *)semphr; - - if (semphr_item->handle) { - vSemaphoreDelete(semphr_item->handle); - } -#ifdef CONFIG_SPIRAM_USE_MALLOC - if (semphr_item->storage) { - free(semphr_item->storage); - } -#endif - - free(semphr); -} - -static int IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int)xSemaphoreTakeFromISR(((btdm_queue_item_t *)semphr)->handle, hptw); -} - -static int IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int)xSemaphoreGiveFromISR(((btdm_queue_item_t *)semphr)->handle, hptw); -} - -static int semphr_take_wrapper(void *semphr, uint32_t block_time_ms) -{ - if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xSemaphoreTake(((btdm_queue_item_t *)semphr)->handle, portMAX_DELAY); - } else { - return (int)xSemaphoreTake(((btdm_queue_item_t *)semphr)->handle, block_time_ms / portTICK_PERIOD_MS); - } -} - -static int semphr_give_wrapper(void *semphr) -{ - return (int)xSemaphoreGive(((btdm_queue_item_t *)semphr)->handle); -} - -static void *mutex_create_wrapper(void) -{ - return (void *)xSemaphoreCreateMutex(); -} - -static void mutex_delete_wrapper(void *mutex) -{ - vSemaphoreDelete(mutex); -} - -static int mutex_lock_wrapper(void *mutex) -{ - return (int)xSemaphoreTake(mutex, portMAX_DELAY); -} - -static int mutex_unlock_wrapper(void *mutex) -{ - return (int)xSemaphoreGive(mutex); -} - -static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size) -{ - btdm_queue_item_t *queue = NULL; - - queue = (btdm_queue_item_t*)heap_caps_malloc(sizeof(btdm_queue_item_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - assert(queue); - -#if CONFIG_SPIRAM_USE_MALLOC - - queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - assert(queue->storage); - - queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage)); - assert(queue->handle); - -#else - queue->handle = xQueueCreate( queue_len, item_size); - assert(queue->handle); -#endif - - return queue; -} - -static void queue_delete_wrapper(void *queue) -{ - btdm_queue_item_t *queue_item = (btdm_queue_item_t *)queue; - if (queue_item) { - if(queue_item->handle){ - vQueueDelete(queue_item->handle); - } - -#if CONFIG_SPIRAM_USE_MALLOC - if (queue_item->storage) { - free(queue_item->storage); - } -#endif - - free(queue_item); - } -} - -static int queue_send_wrapper(void *queue, void *item, uint32_t block_time_ms) -{ - if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xQueueSend(((btdm_queue_item_t*)queue)->handle, item, portMAX_DELAY); - } else { - return (int)xQueueSend(((btdm_queue_item_t*)queue)->handle, item, block_time_ms / portTICK_PERIOD_MS); - } -} - -static int IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw) -{ - return (int)xQueueSendFromISR(((btdm_queue_item_t*)queue)->handle, item, hptw); -} - -static int queue_recv_wrapper(void *queue, void *item, uint32_t block_time_ms) -{ - if (block_time_ms == OSI_FUNCS_TIME_BLOCKING) { - return (int)xQueueReceive(((btdm_queue_item_t*)queue)->handle, item, portMAX_DELAY); - } else { - return (int)xQueueReceive(((btdm_queue_item_t*)queue)->handle, item, block_time_ms / portTICK_PERIOD_MS); - } -} - -static int IRAM_ATTR queue_recv_from_isr_wrapper(void *queue, void *item, void *hptw) -{ - return (int)xQueueReceiveFromISR(((btdm_queue_item_t*)queue)->handle, item, hptw); -} - -static int task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id) -{ - return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY)); -} - -static void task_delete_wrapper(void *task_handle) -{ - vTaskDelete(task_handle); -} - -static bool IRAM_ATTR is_in_isr_wrapper(void) -{ - return (bool)xPortInIsrContext(); -} - -static void *malloc_internal_wrapper(size_t size) -{ - void *p = heap_caps_malloc(size, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA); - if(p == NULL) { - ESP_LOGE(BT_LOG_TAG, "Malloc failed"); - } - return p; -} - -static int IRAM_ATTR read_mac_wrapper(uint8_t mac[6]) -{ - int ret = esp_read_mac(mac, ESP_MAC_BT); - ESP_LOGI(BT_LOG_TAG, "Bluetooth MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - return ret; -} - -static void IRAM_ATTR srand_wrapper(unsigned int seed) -{ - /* empty function */ -} - -static int IRAM_ATTR rand_wrapper(void) -{ - return (int)esp_random(); -} - -static uint32_t IRAM_ATTR btdm_lpcycles_2_hus(uint32_t cycles, uint32_t *error_corr) -{ - uint64_t local_error_corr = (error_corr == NULL) ? 0 : (uint64_t)(*error_corr); - uint64_t res = (uint64_t)btdm_lpcycle_us * cycles * 2; - local_error_corr += res; - res = (local_error_corr >> btdm_lpcycle_us_frac); - local_error_corr -= (res << btdm_lpcycle_us_frac); - if (error_corr) { - *error_corr = (uint32_t) local_error_corr; - } - return (uint32_t)res; -} - -/* - * @brief Converts a duration in half us into a number of low power clock cycles. - */ -static uint32_t IRAM_ATTR btdm_hus_2_lpcycles(uint32_t hus) -{ - // The number of sleep duration(us) should not lead to overflow. Thrs: 100s - // Compute the sleep duration in us to low power clock cycles, with calibration result applied - // clock measurement is conducted - uint64_t cycles = ((uint64_t)(hus) << btdm_lpcycle_us_frac) / btdm_lpcycle_us; - cycles >>= 1; - - return (uint32_t)cycles; -} - -static bool IRAM_ATTR btdm_sleep_check_duration(int32_t *half_slot_cnt) -{ - if (*half_slot_cnt < BTDM_MIN_SLEEP_DURATION) { - return false; - } - /* wake up in advance considering the delay in enabling PHY/RF */ - *half_slot_cnt -= BTDM_MODEM_WAKE_UP_DELAY; - return true; -} - -static void btdm_sleep_enter_phase1_wrapper(uint32_t lpcycles) -{ - if (s_lp_cntl.wakeup_timer_required == 0) { - return; - } - - // start a timer to wake up and acquire the pm_lock before modem_sleep awakes - uint32_t us_to_sleep = btdm_lpcycles_2_hus(lpcycles, NULL) >> 1; - -#define BTDM_MIN_TIMER_UNCERTAINTY_US (1800) - assert(us_to_sleep > BTDM_MIN_TIMER_UNCERTAINTY_US); - // allow a maximum time uncertainty to be about 488ppm(1/2048) at least as clock drift - // and set the timer in advance - uint32_t uncertainty = (us_to_sleep >> 11); - if (uncertainty < BTDM_MIN_TIMER_UNCERTAINTY_US) { - uncertainty = BTDM_MIN_TIMER_UNCERTAINTY_US; - } - - assert (s_lp_stat.wakeup_timer_started == 0); - if (esp_timer_start_once(s_btdm_slp_tmr, us_to_sleep - uncertainty) == ESP_OK) { - s_lp_stat.wakeup_timer_started = 1; - } else { - ESP_LOGE(BT_LOG_TAG, "timer start failed"); - assert(0); - } -} - -static void btdm_sleep_enter_phase2_wrapper(void) -{ - if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) { - if (s_lp_stat.phy_enabled) { - esp_phy_disable(); - s_lp_stat.phy_enabled = 0; - } else { - assert(0); - } - - if (s_lp_stat.pm_lock_released == 0) { -#ifdef CONFIG_PM_ENABLE - esp_pm_lock_release(s_pm_lock); -#endif - s_lp_stat.pm_lock_released = 1; - } - } -} - -static void btdm_sleep_exit_phase3_wrapper(void) -{ -#ifdef CONFIG_PM_ENABLE - // If BT wakeup before esp timer coming due to timer task have no chance to run. - // Then we will not run into `btdm_sleep_exit_phase0` and acquire PM lock, - // Do it again here to fix this issue. - if (s_lp_stat.pm_lock_released) { - esp_pm_lock_acquire(s_pm_lock); - s_lp_stat.pm_lock_released = 0; - } -#endif - - if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) { - if (s_lp_stat.phy_enabled == 0) { - esp_phy_enable(); - s_lp_stat.phy_enabled = 1; - } - } - - // If BT wakeup before esp timer coming due to timer task have no chance to run. - // Then we will not run into `btdm_sleep_exit_phase0` and stop esp timer, - // Do it again here to fix this issue. - if (s_lp_cntl.wakeup_timer_required && s_lp_stat.wakeup_timer_started) { - esp_timer_stop(s_btdm_slp_tmr); - s_lp_stat.wakeup_timer_started = 0; - } - - // wait for the sleep state to change - // the procedure duration is at micro-second level or less - while (btdm_sleep_clock_sync()) { - ; - } -} - -static void IRAM_ATTR btdm_sleep_exit_phase0(void *param) -{ - assert(s_lp_cntl.enable == 1); - -#ifdef CONFIG_PM_ENABLE - if (s_lp_stat.pm_lock_released) { - esp_pm_lock_acquire(s_pm_lock); - s_lp_stat.pm_lock_released = 0; - } -#endif - - int event = (int) param; - if (event == BTDM_ASYNC_WAKEUP_SRC_VHCI || event == BTDM_ASYNC_WAKEUP_SRC_DISA) { - btdm_wakeup_request(); - } - - if (s_lp_cntl.wakeup_timer_required && s_lp_stat.wakeup_timer_started) { - esp_timer_stop(s_btdm_slp_tmr); - s_lp_stat.wakeup_timer_started = 0; - } - - if (event == BTDM_ASYNC_WAKEUP_SRC_VHCI || event == BTDM_ASYNC_WAKEUP_SRC_DISA) { - semphr_give_wrapper(s_wakeup_req_sem); - } -} - -static void IRAM_ATTR btdm_slp_tmr_callback(void *arg) -{ -#ifdef CONFIG_PM_ENABLE - btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)BTDM_ASYNC_WAKEUP_SRC_TMR); -#endif -} - - -static bool async_wakeup_request(int event) -{ - if (s_lp_cntl.enable == 0) { - return false; - } - - bool do_wakeup_request = false; - switch (event) { - case BTDM_ASYNC_WAKEUP_SRC_VHCI: - case BTDM_ASYNC_WAKEUP_SRC_DISA: - btdm_in_wakeup_requesting_set(true); - if (!btdm_power_state_active()) { - btdm_vnd_offload_post(BTDM_VND_OL_SIG_WAKEUP_TMR, (void *)event); - do_wakeup_request = true; - semphr_take_wrapper(s_wakeup_req_sem, OSI_FUNCS_TIME_BLOCKING); - } - break; - default: - break; - } - - return do_wakeup_request; -} - -static void async_wakeup_request_end(int event) -{ - if (s_lp_cntl.enable == 0) { - return; - } - - bool allow_to_sleep; - switch (event) { - case BTDM_ASYNC_WAKEUP_SRC_VHCI: - case BTDM_ASYNC_WAKEUP_SRC_DISA: - allow_to_sleep = true; - break; - default: - allow_to_sleep = true; - break; - } - - if (allow_to_sleep) { - btdm_in_wakeup_requesting_set(false); - } - - return; -} - -static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) -{ -#if CONFIG_SW_COEXIST_ENABLE - coex_schm_status_bit_set(type, status); -#endif -} - -static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) -{ -#if CONFIG_SW_COEXIST_ENABLE - coex_schm_status_bit_clear(type, status); -#endif -} - -bool esp_vhci_host_check_send_available(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return false; - } - return API_vhci_host_check_send_available(); -} - -void esp_vhci_host_send_packet(uint8_t *data, uint16_t len) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return; - } - async_wakeup_request(BTDM_ASYNC_WAKEUP_SRC_VHCI); - - API_vhci_host_send_packet(data, len); - - async_wakeup_request_end(BTDM_ASYNC_WAKEUP_SRC_VHCI); -} - -esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return ESP_FAIL; - } - return API_vhci_host_register_callback((const vhci_host_callback_t *)callback) == 0 ? ESP_OK : ESP_FAIL; -} - -static void btdm_controller_mem_init(void) -{ - extern void btdm_controller_rom_data_init(void ); - btdm_controller_rom_data_init(); -} - -esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode) -{ - intptr_t mem_start=(intptr_t) NULL, mem_end=(intptr_t) NULL; - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) { - return ESP_ERR_INVALID_STATE; - } - - if (mode & ESP_BT_MODE_BLE) { - /* if the addresses of rom btdm .data and .bss are consecutive, - they are registered in the system heap as a piece of memory - */ - if(ets_rom_layout_p->data_end_btdm == ets_rom_layout_p->bss_start_btdm) { - mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm; - mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } else { - mem_start = (intptr_t)ets_rom_layout_p->bss_start_btdm; - mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - - mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm; - mem_end = (intptr_t)ets_rom_layout_p->data_end_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } - /* if the addresses of rom interface btdm .data and .bss are consecutive, - they are registered in the system heap as a piece of memory - */ - if(ets_rom_layout_p->data_end_interface_btdm == ets_rom_layout_p->bss_start_interface_btdm) { - mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm; - mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } else { - mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm; - mem_end = (intptr_t)ets_rom_layout_p->data_end_interface_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - - mem_start = (intptr_t)ets_rom_layout_p->bss_start_interface_btdm; - mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release rom interface btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } - - } - return ESP_OK; -} - -esp_err_t esp_bt_mem_release(esp_bt_mode_t mode) -{ - int ret; - intptr_t mem_start, mem_end; - - ret = esp_bt_controller_mem_release(mode); - if (ret != ESP_OK) { - return ret; - } - - if (mode & ESP_BT_MODE_BLE) { - /* if the addresses of btdm .bss and bt .bss are consecutive, - they are registered in the system heap as a piece of memory - */ - if(_bt_bss_end == _btdm_bss_start) { - mem_start = (intptr_t)&_bt_bss_start; - mem_end = (intptr_t)&_btdm_bss_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } else { - mem_start = (intptr_t)&_bt_bss_start; - mem_end = (intptr_t)&_bt_bss_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release BT BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - - mem_start = (intptr_t)&_btdm_bss_start; - mem_end = (intptr_t)&_btdm_bss_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release BTDM BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } - /* if the addresses of btdm .data and bt .data are consecutive, - they are registered in the system heap as a piece of memory - */ - if(_bt_data_end == _btdm_data_start) { - mem_start = (intptr_t)&_bt_data_start; - mem_end = (intptr_t)&_btdm_data_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } else { - mem_start = (intptr_t)&_bt_data_start; - mem_end = (intptr_t)&_bt_data_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release BT Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - - mem_start = (intptr_t)&_btdm_data_start; - mem_end = (intptr_t)&_btdm_data_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release BTDM Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } - - mem_start = (intptr_t)&_nimble_bss_start; - mem_end = (intptr_t)&_nimble_bss_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release NimBLE BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - mem_start = (intptr_t)&_nimble_data_start; - mem_end = (intptr_t)&_nimble_data_end; - if (mem_start != mem_end) { - ESP_LOGD(BT_LOG_TAG, "Release NimBLE Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start); - ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end)); - } - } - return ESP_OK; -} - -static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end) -{ - int ret = heap_caps_add_region(start, end); - /* heap_caps_add_region() returns ESP_ERR_INVALID_SIZE if the memory region is - * is too small to fit a heap. This cannot be termed as a fatal error and hence - * we replace it by ESP_OK - */ - - if (ret == ESP_ERR_INVALID_SIZE) { - return ESP_OK; - } - return ret; -} - -#if CONFIG_MAC_BB_PD -static void IRAM_ATTR btdm_mac_bb_power_down_cb(void) -{ - if (s_lp_cntl.mac_bb_pd && s_lp_stat.mac_bb_pd == 0) { - btdm_ble_power_down_dma_copy(true); - s_lp_stat.mac_bb_pd = 1; - } -} - -static void IRAM_ATTR btdm_mac_bb_power_up_cb(void) -{ - if (s_lp_cntl.mac_bb_pd && s_lp_stat.mac_bb_pd) { - btdm_ble_power_down_dma_copy(false); - s_lp_stat.mac_bb_pd = 0; - } -} -#endif - -esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) -{ - esp_err_t err = ESP_FAIL; - - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) { - return ESP_ERR_INVALID_STATE; - } - - if (cfg == NULL) { - return ESP_ERR_INVALID_ARG; - } - - if (cfg->controller_task_prio != ESP_TASK_BT_CONTROLLER_PRIO - || cfg->controller_task_stack_size < ESP_TASK_BT_CONTROLLER_STACK) { - ESP_LOGE(BT_LOG_TAG, "Invalid controller task prioriy or stack size"); - return ESP_ERR_INVALID_ARG; - } - - if (cfg->bluetooth_mode != ESP_BT_MODE_BLE) { - ESP_LOGE(BT_LOG_TAG, "%s controller only support BLE only mode", __func__); - return ESP_ERR_NOT_SUPPORTED; - } - - if (cfg->bluetooth_mode & ESP_BT_MODE_BLE) { - if ((cfg->ble_max_act <= 0) || (cfg->ble_max_act > BT_CTRL_BLE_MAX_ACT_LIMIT)) { - ESP_LOGE(BT_LOG_TAG, "Invalid value of ble_max_act"); - return ESP_ERR_INVALID_ARG; - } - } - - if (cfg->sleep_mode == ESP_BT_SLEEP_MODE_1) { - if (cfg->sleep_clock == ESP_BT_SLEEP_CLOCK_NONE) { - ESP_LOGE(BT_LOG_TAG, "SLEEP_MODE_1 enabled but sleep clock not configured"); - return ESP_ERR_INVALID_ARG; - } - } - - // overwrite some parameters - cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL; - -#if CONFIG_MAC_BB_PD - esp_mac_bb_pd_mem_init(); -#endif - esp_phy_modem_init(); - esp_bt_power_domain_on(); - - btdm_controller_mem_init(); - -#if CONFIG_MAC_BB_PD - if (esp_register_mac_bb_pd_callback(btdm_mac_bb_power_down_cb) != 0) { - err = ESP_ERR_INVALID_ARG; - goto error; - } - - if (esp_register_mac_bb_pu_callback(btdm_mac_bb_power_up_cb) != 0) { - err = ESP_ERR_INVALID_ARG; - goto error; - } -#endif - - osi_funcs_p = (struct osi_funcs_t *)malloc_internal_wrapper(sizeof(struct osi_funcs_t)); - if (osi_funcs_p == NULL) { - return ESP_ERR_NO_MEM; - } - - memcpy(osi_funcs_p, &osi_funcs_ro, sizeof(struct osi_funcs_t)); - if (btdm_osi_funcs_register(osi_funcs_p) != 0) { - return ESP_ERR_INVALID_ARG; - } - - ESP_LOGI(BT_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version()); - - // init low-power control resources - do { - // set default values for global states or resources - s_lp_stat.val = 0; - s_lp_cntl.val = 0; - s_lp_cntl.main_xtal_pu = 0; - s_wakeup_req_sem = NULL; - s_btdm_slp_tmr = NULL; - - // configure and initialize resources - s_lp_cntl.enable = (cfg->sleep_mode == ESP_BT_SLEEP_MODE_1) ? 1 : 0; - s_lp_cntl.no_light_sleep = 0; - - if (s_lp_cntl.enable) { -#if CONFIG_MAC_BB_PD - if (!btdm_deep_sleep_mem_init()) { - err = ESP_ERR_NO_MEM; - goto error; - } - s_lp_cntl.mac_bb_pd = 1; -#endif -#ifdef CONFIG_PM_ENABLE - s_lp_cntl.wakeup_timer_required = 1; -#endif - // async wakeup semaphore for VHCI - s_wakeup_req_sem = semphr_create_wrapper(1, 0); - if (s_wakeup_req_sem == NULL) { - err = ESP_ERR_NO_MEM; - goto error; - } - btdm_vnd_offload_task_register(BTDM_VND_OL_SIG_WAKEUP_TMR, btdm_sleep_exit_phase0); - } - - if (s_lp_cntl.wakeup_timer_required) { - esp_timer_create_args_t create_args = { - .callback = btdm_slp_tmr_callback, - .arg = NULL, - .name = "btSlp", - }; - if ((err = esp_timer_create(&create_args, &s_btdm_slp_tmr)) != ESP_OK) { - goto error; - } - } - - // set default bluetooth sleep clock cycle and its fractional bits - btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; - btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac); - - // set default bluetooth sleep clock source - s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value -#if CONFIG_BT_CTRL_LPCLK_SEL_EXT_32K_XTAL - // check whether or not EXT_CRYS is working - if (rtc_clk_slow_freq_get() == RTC_SLOW_FREQ_32K_XTAL) { - s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_XTAL32K; // External 32 kHz XTAL - } else { - ESP_LOGW(BT_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock"); -#if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - s_lp_cntl.no_light_sleep = 1; -#endif - } -#elif CONFIG_BT_CTRL_LPCLK_SEL_MAIN_XTAL - ESP_LOGI(BT_LOG_TAG, "Bluetooth will use main XTAL as Bluetooth sleep clock."); -#if !CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - s_lp_cntl.no_light_sleep = 1; -#endif -#elif CONFIG_BT_CTRL_LPCLK_SEL_RTC_SLOW - // check whether or not internal 150 kHz RC oscillator is working - if (rtc_clk_slow_freq_get() == RTC_SLOW_FREQ_RTC) { - s_lp_cntl.lpclk_sel = BTDM_LPCLK_SEL_RTC_SLOW; // Internal 150 kHz RC oscillator - ESP_LOGW(BT_LOG_TAG, "Internal 150kHz RC osciallator. The accuracy of this clock is a lot larger than 500ppm which is " - "required in Bluetooth communication, so don't select this option in scenarios such as BLE connection state."); - } else { - ESP_LOGW(BT_LOG_TAG, "Internal 150kHz RC oscillator not detected."); - assert(0); - } -#endif - - bool select_src_ret __attribute__((unused)); - bool set_div_ret __attribute__((unused)); - if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) { -#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON)); - s_lp_cntl.main_xtal_pu = 1; -#endif - select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL); - set_div_ret = btdm_lpclk_set_div(rtc_clk_xtal_freq_get()); - assert(select_src_ret && set_div_ret); - btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; - btdm_lpcycle_us = 1 << (btdm_lpcycle_us_frac); - } else if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL32K) { - select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL32K); - set_div_ret = btdm_lpclk_set_div(0); - assert(select_src_ret && set_div_ret); - btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; - btdm_lpcycle_us = (RTC_CLK_CAL_FRACT > 15) ? (1000000 << (RTC_CLK_CAL_FRACT - 15)) : - (1000000 >> (15 - RTC_CLK_CAL_FRACT)); - assert(btdm_lpcycle_us != 0); - } else if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_RTC_SLOW) { - select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW); - set_div_ret = btdm_lpclk_set_div(0); - assert(select_src_ret && set_div_ret); - btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT; - btdm_lpcycle_us = esp_clk_slowclk_cal_get(); - } else { - err = ESP_ERR_INVALID_ARG; - goto error; - } -#if CONFIG_SW_COEXIST_ENABLE - coex_update_lpclk_interval(); -#endif - -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - if ((err = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "btLS", &s_light_sleep_pm_lock)) != ESP_OK) { - err = ESP_ERR_NO_MEM; - goto error; - } - ESP_LOGW(BT_LOG_TAG, "light sleep mode will not be able to apply when bluetooth is enabled."); - } - if ((err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock)) != ESP_OK) { - err = ESP_ERR_NO_MEM; - goto error; - } else { - s_lp_stat.pm_lock_released = 1; - } -#endif - } while (0); - -#if CONFIG_SW_COEXIST_ENABLE - coex_init(); -#endif - - periph_module_enable(PERIPH_BT_MODULE); - periph_module_reset(PERIPH_BT_MODULE); - - esp_phy_enable(); - s_lp_stat.phy_enabled = 1; - - if (btdm_controller_init(cfg) != 0) { - err = ESP_ERR_NO_MEM; - goto error; - } - coex_pti_v2(); - - btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; - - return ESP_OK; - -error: - - bt_controller_deinit_internal(); - - return err; -} - -esp_err_t esp_bt_controller_deinit(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { - return ESP_ERR_INVALID_STATE; - } - - btdm_controller_deinit(); - - bt_controller_deinit_internal(); - - return ESP_OK; -} - -static void bt_controller_deinit_internal(void) -{ - periph_module_disable(PERIPH_BT_MODULE); - - if (s_lp_stat.phy_enabled) { - esp_phy_disable(); - s_lp_stat.phy_enabled = 0; - } - - // deinit low power control resources - do { - -#if CONFIG_MAC_BB_PD - if (s_lp_cntl.mac_bb_pd) { - btdm_deep_sleep_mem_deinit(); - s_lp_cntl.mac_bb_pd = 0; - } -#endif - -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - if (s_light_sleep_pm_lock != NULL) { - esp_pm_lock_delete(s_light_sleep_pm_lock); - s_light_sleep_pm_lock = NULL; - } - } - - if (s_pm_lock != NULL) { - esp_pm_lock_delete(s_pm_lock); - s_pm_lock = NULL; - s_lp_stat.pm_lock_released = 0; - } - -#endif - - if (s_lp_cntl.wakeup_timer_required) { - if (s_lp_stat.wakeup_timer_started) { - esp_timer_stop(s_btdm_slp_tmr); - } - s_lp_stat.wakeup_timer_started = 0; - esp_timer_delete(s_btdm_slp_tmr); - s_btdm_slp_tmr = NULL; - } - - if (s_lp_cntl.enable) { - btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR); - if (s_wakeup_req_sem != NULL) { - semphr_delete_wrapper(s_wakeup_req_sem); - s_wakeup_req_sem = NULL; - } - } - - if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) { -#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - if (s_lp_cntl.main_xtal_pu) { - ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF)); - s_lp_cntl.main_xtal_pu = 0; - } -#endif - btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW); - btdm_lpclk_set_div(0); -#if CONFIG_SW_COEXIST_ENABLE - coex_update_lpclk_interval(); -#endif - } - - btdm_lpcycle_us = 0; - } while (0); - -#if CONFIG_MAC_BB_PD - esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb); - esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); -#endif - - esp_bt_power_domain_off(); -#if CONFIG_MAC_BB_PD - esp_mac_bb_pd_mem_deinit(); -#endif - esp_phy_modem_deinit(); - - if (osi_funcs_p != NULL) { - free(osi_funcs_p); - osi_funcs_p = NULL; - } - - btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; -} - -esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) -{ - esp_err_t ret = ESP_OK; - - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { - return ESP_ERR_INVALID_STATE; - } - - //As the history reason, mode should be equal to the mode which set in esp_bt_controller_init() - if (mode != btdm_controller_get_mode()) { - ESP_LOGE(BT_LOG_TAG, "invalid mode %d, controller support mode is %d", mode, btdm_controller_get_mode()); - return ESP_ERR_INVALID_ARG; - } - -#if CONFIG_SW_COEXIST_ENABLE - coex_enable(); -#endif - - // enable low power mode - do { -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - esp_pm_lock_acquire(s_light_sleep_pm_lock); - } - esp_pm_lock_acquire(s_pm_lock); - s_lp_stat.pm_lock_released = 0; -#endif - - if (s_lp_cntl.enable) { - btdm_controller_enable_sleep(true); - } - } while (0); - - if (btdm_controller_enable(mode) != 0) { - ret = ESP_ERR_INVALID_STATE; - goto error; - } - - btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED; - - return ret; - -error: - // disable low power mode - do { - btdm_controller_enable_sleep(false); -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - esp_pm_lock_release(s_light_sleep_pm_lock); - } - if (s_lp_stat.pm_lock_released == 0) { - esp_pm_lock_release(s_pm_lock); - s_lp_stat.pm_lock_released = 1; - } -#endif - } while (0); - -#if CONFIG_SW_COEXIST_ENABLE - coex_disable(); -#endif - return ret; -} - -esp_err_t esp_bt_controller_disable(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return ESP_ERR_INVALID_STATE; - } - - async_wakeup_request(BTDM_ASYNC_WAKEUP_SRC_DISA); - while (!btdm_power_state_active()){} - btdm_controller_disable(); - - async_wakeup_request_end(BTDM_ASYNC_WAKEUP_SRC_DISA); - -#if CONFIG_SW_COEXIST_ENABLE - coex_disable(); -#endif - - btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; - - // disable low power mode - do { -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - esp_pm_lock_release(s_light_sleep_pm_lock); - } - - if (s_lp_stat.pm_lock_released == 0) { - esp_pm_lock_release(s_pm_lock); - s_lp_stat.pm_lock_released = 1; - } else { - assert(0); - } -#endif - } while (0); - - return ESP_OK; -} - -esp_bt_controller_status_t esp_bt_controller_get_status(void) -{ - return btdm_controller_status; -} - -/* extra functions */ -esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level) -{ - esp_err_t stat = ESP_FAIL; - - switch (power_type) { - case ESP_BLE_PWR_TYPE_ADV: - case ESP_BLE_PWR_TYPE_SCAN: - case ESP_BLE_PWR_TYPE_DEFAULT: - if (ble_txpwr_set(power_type, power_level) == 0) { - stat = ESP_OK; - } - break; - default: - stat = ESP_ERR_NOT_SUPPORTED; - break; - } - - return stat; - -} - -esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type) -{ - esp_power_level_t lvl; - - switch (power_type) { - case ESP_BLE_PWR_TYPE_ADV: - case ESP_BLE_PWR_TYPE_SCAN: - lvl = (esp_power_level_t)ble_txpwr_get(power_type); - break; - case ESP_BLE_PWR_TYPE_CONN_HDL0: - case ESP_BLE_PWR_TYPE_CONN_HDL1: - case ESP_BLE_PWR_TYPE_CONN_HDL2: - case ESP_BLE_PWR_TYPE_CONN_HDL3: - case ESP_BLE_PWR_TYPE_CONN_HDL4: - case ESP_BLE_PWR_TYPE_CONN_HDL5: - case ESP_BLE_PWR_TYPE_CONN_HDL6: - case ESP_BLE_PWR_TYPE_CONN_HDL7: - case ESP_BLE_PWR_TYPE_CONN_HDL8: - case ESP_BLE_PWR_TYPE_DEFAULT: - lvl = (esp_power_level_t)ble_txpwr_get(ESP_BLE_PWR_TYPE_DEFAULT); - break; - default: - lvl = ESP_PWR_LVL_INVALID; - break; - } - - return lvl; - -} - -esp_err_t esp_bt_sleep_enable (void) -{ - esp_err_t status; - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return ESP_ERR_INVALID_STATE; - } - if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) { - btdm_controller_enable_sleep (true); - status = ESP_OK; - } else { - status = ESP_ERR_NOT_SUPPORTED; - } - - return status; -} - -esp_err_t esp_bt_sleep_disable (void) -{ - esp_err_t status; - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) { - return ESP_ERR_INVALID_STATE; - } - if (btdm_controller_get_sleep_mode() == ESP_BT_SLEEP_MODE_1) { - btdm_controller_enable_sleep (false); - status = ESP_OK; - } else { - status = ESP_ERR_NOT_SUPPORTED; - } - - return status; -} - -bool esp_bt_controller_is_sleeping(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED || - btdm_controller_get_sleep_mode() != ESP_BT_SLEEP_MODE_1) { - return false; - } - - return !btdm_power_state_active(); -} - -void esp_bt_controller_wakeup_request(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED || - btdm_controller_get_sleep_mode() != ESP_BT_SLEEP_MODE_1) { - return; - } - - btdm_wakeup_request(); - -} - -int IRAM_ATTR esp_bt_h4tl_eif_io_event_notify(int event) -{ - return btdm_hci_tl_io_event_post(event); -} - -uint16_t esp_bt_get_tx_buf_num(void) -{ - return l2c_ble_link_get_tx_buf_num(); -} - -static void coex_wifi_sleep_set_hook(bool sleep) -{ - -} -#endif /* CONFIG_BT_ENABLED */ diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index bba9af9259..d83f7d618a 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit bba9af9259e0999ef246426d31a793fe0a3ff4db +Subproject commit d83f7d618a7a86f4703b909f8fc0ddcf8fd48a89 diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index e86b2bd9cc..ee826bf595 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1071,9 +1071,8 @@ config BT_MAX_DEVICE_NAME_LEN config BT_BLE_RPA_SUPPORTED bool "Update RPA to Controller" - depends on BT_BLUEDROID_ENABLED - default y if (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) - default n if IDF_TARGET_ESP32 + depends on BT_BLUEDROID_ENABLED && IDF_TARGET_ESP32 + default n help This enables controller RPA list function. For ESP32, ESP32 only support network privacy mode. If this option is enabled, ESP32 will only accept @@ -1083,7 +1082,7 @@ config BT_BLE_RPA_SUPPORTED cannot be used. This option is disabled by default on ESP32, please enable or disable this option according to your own needs. - For ESP32C3 and esp32s3, devices support network privacy mode and device privacy mode, users can switch the + For BLE other chips, devices support network privacy mode and device privacy mode, users can switch the two modes according to their own needs. So this option is enabled by default. config BT_BLE_50_FEATURES_SUPPORTED diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index b0f34efef6..263500e380 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -18,6 +18,7 @@ /* All the configuration from SDK defined here */ #include "bt_common.h" #include "bt_user_config.h" +#include "soc/soc_caps.h" /********************************************************** * Thread/Task reference @@ -105,8 +106,12 @@ #ifdef CONFIG_BT_BLE_RPA_SUPPORTED #define UC_BT_BLE_RPA_SUPPORTED CONFIG_BT_BLE_RPA_SUPPORTED #else +#if SOC_BLE_DEVICE_PRIVACY_SUPPORTED +#define UC_BT_BLE_RPA_SUPPORTED TRUE +#else #define UC_BT_BLE_RPA_SUPPORTED FALSE #endif +#endif #ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED #define UC_BT_BLE_50_FEATURES_SUPPORTED CONFIG_BT_BLE_50_FEATURES_SUPPORTED diff --git a/components/bt/host/bluedroid/stack/gatt/include/gatt_int.h b/components/bt/host/bluedroid/stack/gatt/include/gatt_int.h index 31c2ce479a..05174ee638 100644 --- a/components/bt/host/bluedroid/stack/gatt/include/gatt_int.h +++ b/components/bt/host/bluedroid/stack/gatt/include/gatt_int.h @@ -78,7 +78,7 @@ typedef UINT8 tGATT_SEC_ACTION; /* wait for ATT cmd response timeout value */ #define GATT_WAIT_FOR_RSP_TOUT 30 -#define GATT_WAIT_FOR_DISC_RSP_TOUT 5 +#define GATT_WAIT_FOR_DISC_RSP_TOUT 15 #define GATT_REQ_RETRY_LIMIT 2 #define GATT_WAIT_FOR_IND_ACK_TOUT 5 diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 934a857211..985e4181e3 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -19,7 +19,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02212090 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02302140 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -66,7 +66,7 @@ typedef enum { ESP_BT_SLEEP_CLOCK_NONE = 0, /*!< Sleep clock not configured */ ESP_BT_SLEEP_CLOCK_MAIN_XTAL = 1, /*!< SoC main crystal */ ESP_BT_SLEEP_CLOCK_EXT_32K_XTAL = 2, /*!< External 32.768kHz crystal */ - ESP_BT_SLEEP_CLOCK_RTC_SLOW = 3, /*!< Internal 150kHz RC oscillator */ + ESP_BT_SLEEP_CLOCK_RTC_SLOW = 3, /*!< Internal 136kHz RC oscillator */ ESP_BT_SLEEP_CLOCK_FPGA_32K = 4, /*!< Hardwired 32KHz clock temporarily used for FPGA */ } esp_bt_sleep_clock_t; @@ -136,6 +136,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD #endif +#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#else +#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0 +#endif + #ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN #define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN #else @@ -148,20 +154,27 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #define BT_CTRL_CODED_AGC_RECORRECT 0 #endif -#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX -#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX +#if defined (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) || defined (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT) +#ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED +#define BT_CTRL_50_FEATURE_SUPPORT (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) +#endif +#ifdef CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT +#define BT_CTRL_50_FEATURE_SUPPORT (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT) +#endif #else -#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0 +#define BT_CTRL_50_FEATURE_SUPPORT (1) #endif #define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1)) - #define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0) -#define CFG_NASK CFG_MASK_BIT_SCAN_DUPLICATE_OPTION - -#define BLE_HW_TARGET_CODE_ESP32C3_CHIP_ECO0 (0x01010000) +#define CFG_MASK CFG_MASK_BIT_SCAN_DUPLICATE_OPTION +#if CONFIG_IDF_TARGET_ESP32C3 +#define BLE_HW_TARGET_CODE_CHIP_ECO0 (0x01010000) +#else // CONFIG_IDF_TARGET_ESP32S3 +#define BLE_HW_TARGET_CODE_CHIP_ECO0 (0x02010000) +#endif #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \ .magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL, \ @@ -184,18 +197,19 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .txant_dft = CONFIG_BT_CTRL_TX_ANTENNA_INDEX_EFF, \ .rxant_dft = CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF, \ .txpwr_dft = CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF, \ - .cfg_mask = CFG_NASK, \ + .cfg_mask = CFG_MASK, \ .scan_duplicate_mode = SCAN_DUPLICATE_MODE, \ .scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \ .normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE, \ .mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE, \ .coex_phy_coded_tx_rx_time_limit = CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF, \ - .hw_target_code = BLE_HW_TARGET_CODE_ESP32C3_CHIP_ECO0, \ + .hw_target_code = BLE_HW_TARGET_CODE_CHIP_ECO0, \ .slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \ .hw_recorrect_en = AGC_RECORRECT_EN, \ .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ .dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \ + .ble_50_feat_supp = BT_CTRL_50_FEATURE_SUPPORT, \ } #else @@ -260,11 +274,12 @@ typedef struct { uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */ uint8_t coex_phy_coded_tx_rx_time_limit; /*!< limit on max tx/rx time in case of connection using CODED-PHY with Wi-Fi coexistence */ uint32_t hw_target_code; /*!< hardware target */ - uint8_t slave_ce_len_min; + uint8_t slave_ce_len_min; /*!< slave minimum ce length*/ uint8_t hw_recorrect_en; uint8_t cca_thresh; /*!< cca threshold*/ uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */ uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */ + bool ble_50_feat_supp; /*!< BLE 5.0 feature support */ } esp_bt_controller_config_t; /** diff --git a/components/bt/include/esp32s3/include/esp_bt.h b/components/bt/include/esp32s3/include/esp_bt.h deleted file mode 100644 index ff02cf00d0..0000000000 --- a/components/bt/include/esp32s3/include/esp_bt.h +++ /dev/null @@ -1,558 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __ESP_BT_H__ -#define __ESP_BT_H__ - -#include -#include -#include "esp_err.h" -#include "sdkconfig.h" -#include "esp_task.h" -#include "esp_assert.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02212090 - -#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead -#define ESP_BT_HCI_TL_VERSION 0x00010000 - -/** - * @brief Bluetooth mode for controller enable/disable - */ -typedef enum { - ESP_BT_MODE_IDLE = 0x00, /*!< Bluetooth is not running */ - ESP_BT_MODE_BLE = 0x01, /*!< Run BLE mode */ - ESP_BT_MODE_CLASSIC_BT = 0x02, /*!< Run Classic BT mode */ - ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */ -} esp_bt_mode_t; - -/** - * @brief Type of controller HCI transport layer - */ -typedef enum { - ESP_BT_CTRL_HCI_TL_UART = 0, /*!< HCI UART h4 transport layer */ - ESP_BT_CTRL_HCI_TL_VHCI = 1, /*!< VHCI interface */ -} esp_bt_ctrl_hci_tl_t; - -/** - * @breif type of BLE connection event length computation - */ -typedef enum { - ESP_BLE_CE_LEN_TYPE_ORIG = 0, /*!< original */ - ESP_BLE_CE_LEN_TYPE_CE = 1, /*!< use CE_LEN parameter from HCI commands */ - ESP_BLE_CE_LEN_TYPE_SD = 1, /*!< Espressif vendor defined */ -} esp_ble_ce_len_t; - -/** - * @brief Bluetooth sleep mode - */ -typedef enum { - ESP_BT_SLEEP_MODE_NONE = 0, /*!< Bluetooth sleep mode disabled */ - ESP_BT_SLEEP_MODE_1 = 1, /*!< Bluetooth sleep mode 1 */ -} esp_bt_sleep_mode_t; - -/** - * @brief Bluetooth sleep clock - */ -typedef enum { - ESP_BT_SLEEP_CLOCK_NONE = 0, /*!< Sleep clock not configured */ - ESP_BT_SLEEP_CLOCK_MAIN_XTAL = 1, /*!< SoC main crystal */ - ESP_BT_SLEEP_CLOCK_EXT_32K_XTAL = 2, /*!< External 32.768kHz crystal */ - ESP_BT_SLEEP_CLOCK_RTC_SLOW = 3, /*!< Internal 90kHz RC oscillator */ - ESP_BT_SLEEP_CLOCK_FPGA_32K = 4, /*!< Hardwired 32KHz clock temporarily used for FPGA */ -} esp_bt_sleep_clock_t; - -/** - * @brief antenna index used for bluetooth - */ -enum { - ESP_BT_ANT_IDX_0 = 0, /*!< anntena NO 0 */ - ESP_BT_ANT_IDX_1 = 1, /*!< anntena NO 1 */ -}; - -/** - * @brief Maximum Tx/Rx time limit on Coded-PHY connection - */ -enum { - ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_DISABLE = 0, /*!< Disable the limit */ - ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_ENABLE, /*!< Always Enable the limit */ -}; - -#define ESP_BT_HCI_TL_STATUS_OK (0) /*!< HCI_TL Tx/Rx operation status OK */ - -/** - * @brief callback function for HCI Transport Layer send/receive operations - */ -typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); - -#ifdef CONFIG_BT_ENABLED - -#define BT_CTRL_BLE_MAX_ACT_LIMIT 10 //Maximum BLE activity limitation -#define SLAVE_CE_LEN_MIN_DEFAULT 5 - -#ifdef CONFIG_BT_CTRL_SCAN_DUPL_TYPE -#define SCAN_DUPLICATE_TYPE_VALUE CONFIG_BT_CTRL_SCAN_DUPL_TYPE -#else -#define SCAN_DUPLICATE_TYPE_VALUE 0 -#endif - -/* normal adv cache size */ -#ifdef CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE -#define NORMAL_SCAN_DUPLICATE_CACHE_SIZE CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE -#else -#define NORMAL_SCAN_DUPLICATE_CACHE_SIZE 20 -#endif - -#ifndef CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN -#define CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN FALSE -#endif - -#define SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY 0 -#define SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV 1 - -#if CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN - #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV - #ifdef CONFIG_BT_CTRL_MESH_DUPL_SCAN_CACHE_SIZE - #define MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BT_CTRL_MESH_DUPL_SCAN_CACHE_SIZE - #else - #define MESH_DUPLICATE_SCAN_CACHE_SIZE 50 - #endif -#else - #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY - #define MESH_DUPLICATE_SCAN_CACHE_SIZE 0 -#endif - -#ifndef CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD -#define DUPL_SCAN_CACHE_REFRESH_PERIOD 0 -#else -#define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD -#endif - -#ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX -#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX -#else -#define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0 -#endif - -#ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN -#define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN -#else -#define BT_CTRL_AGC_RECORRECT_EN 0 -#endif - -#ifdef CONFIG_BT_CTRL_CODED_AGC_RECORRECT_EN -#define BT_CTRL_CODED_AGC_RECORRECT CONFIG_BT_CTRL_CODED_AGC_RECORRECT_EN -#else -#define BT_CTRL_CODED_AGC_RECORRECT 0 -#endif - -#define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1)) - -#define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0) - -#define CFG_MASK CFG_MASK_BIT_SCAN_DUPLICATE_OPTION - -#define BLE_HW_TARGET_CODE_ESP32S3_CHIP_ECO0 (0x02010000) - -#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \ - .magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL, \ - .version = ESP_BT_CTRL_CONFIG_VERSION, \ - .controller_task_stack_size = ESP_TASK_BT_CONTROLLER_STACK, \ - .controller_task_prio = ESP_TASK_BT_CONTROLLER_PRIO, \ - .controller_task_run_cpu = CONFIG_BT_CTRL_PINNED_TO_CORE, \ - .bluetooth_mode = CONFIG_BT_CTRL_MODE_EFF, \ - .ble_max_act = CONFIG_BT_CTRL_BLE_MAX_ACT_EFF, \ - .sleep_mode = CONFIG_BT_CTRL_SLEEP_MODE_EFF, \ - .sleep_clock = CONFIG_BT_CTRL_SLEEP_CLOCK_EFF, \ - .ble_st_acl_tx_buf_nb = CONFIG_BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB, \ - .ble_hw_cca_check = CONFIG_BT_CTRL_HW_CCA_EFF, \ - .ble_adv_dup_filt_max = CONFIG_BT_CTRL_ADV_DUP_FILT_MAX, \ - .coex_param_en = false, \ - .ce_len_type = CONFIG_BT_CTRL_CE_LENGTH_TYPE_EFF, \ - .coex_use_hooks = false, \ - .hci_tl_type = CONFIG_BT_CTRL_HCI_TL_EFF, \ - .hci_tl_funcs = NULL, \ - .txant_dft = CONFIG_BT_CTRL_TX_ANTENNA_INDEX_EFF, \ - .rxant_dft = CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF, \ - .txpwr_dft = CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF, \ - .cfg_mask = CFG_MASK, \ - .scan_duplicate_mode = SCAN_DUPLICATE_MODE, \ - .scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \ - .normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE, \ - .mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE, \ - .coex_phy_coded_tx_rx_time_limit = CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF, \ - .hw_target_code = BLE_HW_TARGET_CODE_ESP32S3_CHIP_ECO0, \ - .slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT, \ - .hw_recorrect_en = AGC_RECORRECT_EN, \ - .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ - .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ - .dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \ -} - -#else -#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; ESP_STATIC_ASSERT(0, "please enable bluetooth in menuconfig to use esp_bt.h"); -#endif - -/** - * @brief Controller HCI transport layer function structure - * This structure shall be registered when HCI transport layer is UART - */ -typedef struct { - uint32_t _magic; /* Magic number */ - uint32_t _version; /* version number of the defined structure */ - uint32_t _reserved; /* reserved for future use */ - int (* _open)(void); /* hci tl open */ - void (* _close)(void); /* hci tl close */ - void (* _finish_transfers)(void); /* hci tl finish trasnfers */ - void (* _recv)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /* hci tl recv */ - void (* _send)(uint8_t *buf, uint32_t len, esp_bt_hci_tl_callback_t callback, void* arg); /* hci tl send */ - bool (* _flow_off)(void); /* hci tl flow off */ - void (* _flow_on)(void); /* hci tl flow on */ -} esp_bt_hci_tl_t; - -/** - * @brief Controller config options, depend on config mask. - * Config mask indicate which functions enabled, this means - * some options or parameters of some functions enabled by config mask. - */ -typedef struct { - /* - * Following parameters can not be configured runtime when call esp_bt_controller_init() - * They will be overwritten by constant values from menuconfig options or from macros. - * So, do not modify the value when esp_bt_controller_init() - */ - uint32_t magic; /*!< Magic number */ - uint32_t version; /*!< version number of the defined structure */ - /* - * Following parameters can be configured runtime, when call esp_bt_controller_init() - */ - uint16_t controller_task_stack_size; /*!< Bluetooth controller task stack size */ - uint8_t controller_task_prio; /*!< Bluetooth controller task priority */ - uint8_t controller_task_run_cpu; /*!< CPU num that Bluetooth controller task runs on */ - uint8_t bluetooth_mode; /*!< Controller mode: BR/EDR, BLE or Dual Mode */ - uint8_t ble_max_act; /*!< BLE maximum number of air activities */ - uint8_t sleep_mode; /*!< controller sleep mode */ - uint8_t sleep_clock; /*!< controller sleep clock */ - uint8_t ble_st_acl_tx_buf_nb; /*!< controller static ACL TX BUFFER number */ - uint8_t ble_hw_cca_check; /*!< controller hardware triggered CCA check */ - uint16_t ble_adv_dup_filt_max; /*!< maxinum number of duplicate scan filter */ - bool coex_param_en; /*!< deprecated */ - uint8_t ce_len_type; /*!< connection event length computation method */ - bool coex_use_hooks; /*!< deprecated */ - uint8_t hci_tl_type; /*!< HCI transport layer, UART, VHCI, etc */ - esp_bt_hci_tl_t *hci_tl_funcs; /*!< hci transport functions used, must be set when hci_tl_type is UART */ - uint8_t txant_dft; /*!< default Tx antenna */ - uint8_t rxant_dft; /*!< default Rx antenna */ - uint8_t txpwr_dft; /*!< default Tx power */ - uint32_t cfg_mask; - uint8_t scan_duplicate_mode; /*!< scan duplicate mode */ - uint8_t scan_duplicate_type; /*!< scan duplicate type */ - uint16_t normal_adv_size; /*!< Normal adv size for scan duplicate */ - uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */ - uint8_t coex_phy_coded_tx_rx_time_limit; /*!< limit on max tx/rx time in case of connection using CODED-PHY with Wi-Fi coexistence */ - uint32_t hw_target_code; /*!< hardware target */ - uint8_t slave_ce_len_min; /*!< slave minimum ce length*/ - uint8_t hw_recorrect_en; - uint8_t cca_thresh; /*!< cca threshold*/ - uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */ - uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */ -} esp_bt_controller_config_t; - -/** - * @brief Bluetooth controller enable/disable/initialised/de-initialised status - */ -typedef enum { - ESP_BT_CONTROLLER_STATUS_IDLE = 0, - ESP_BT_CONTROLLER_STATUS_INITED, - ESP_BT_CONTROLLER_STATUS_ENABLED, - ESP_BT_CONTROLLER_STATUS_NUM, -} esp_bt_controller_status_t; - -/** - * @brief BLE tx power type - * ESP_BLE_PWR_TYPE_CONN_HDL0-8: for each connection, and only be set after connection completed. - * when disconnect, the correspond TX power is not effected. - * ESP_BLE_PWR_TYPE_ADV : for advertising/scan response. - * ESP_BLE_PWR_TYPE_SCAN : for scan. - * ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value. - * if neither in scan mode nor in adv mode, it will use this default value. - * If none of power type is set, system will use ESP_PWR_LVL_P3 as default for ADV/SCAN/CONN0-9. - */ -typedef enum { - ESP_BLE_PWR_TYPE_CONN_HDL0 = 0, /*!< For connection handle 0 */ - ESP_BLE_PWR_TYPE_CONN_HDL1 = 1, /*!< For connection handle 1 */ - ESP_BLE_PWR_TYPE_CONN_HDL2 = 2, /*!< For connection handle 2 */ - ESP_BLE_PWR_TYPE_CONN_HDL3 = 3, /*!< For connection handle 3 */ - ESP_BLE_PWR_TYPE_CONN_HDL4 = 4, /*!< For connection handle 4 */ - ESP_BLE_PWR_TYPE_CONN_HDL5 = 5, /*!< For connection handle 5 */ - ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */ - ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */ - ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */ - ESP_BLE_PWR_TYPE_ADV = 9, /*!< For advertising */ - ESP_BLE_PWR_TYPE_SCAN = 10, /*!< For scan */ - ESP_BLE_PWR_TYPE_DEFAULT = 11, /*!< For default, if not set other, it will use default value */ - ESP_BLE_PWR_TYPE_NUM = 12, /*!< TYPE numbers */ -} esp_ble_power_type_t; - -/** - * @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm). - */ -typedef enum { - ESP_PWR_LVL_N24 = 0, /*!< Corresponding to -24dbm */ - ESP_PWR_LVL_N21 = 1, /*!< Corresponding to -21dbm */ - ESP_PWR_LVL_N18 = 2, /*!< Corresponding to -18dbm */ - ESP_PWR_LVL_N15 = 3, /*!< Corresponding to -15dbm */ - ESP_PWR_LVL_N12 = 4, /*!< Corresponding to -12dbm */ - ESP_PWR_LVL_N9 = 5, /*!< Corresponding to -9dbm */ - ESP_PWR_LVL_N6 = 6, /*!< Corresponding to -6dbm */ - ESP_PWR_LVL_N3 = 7, /*!< Corresponding to -3dbm */ - ESP_PWR_LVL_N0 = 8, /*!< Corresponding to 0dbm */ - ESP_PWR_LVL_P3 = 9, /*!< Corresponding to +3dbm */ - ESP_PWR_LVL_P6 = 10, /*!< Corresponding to +6dbm */ - ESP_PWR_LVL_P9 = 11, /*!< Corresponding to +9dbm */ - ESP_PWR_LVL_P12 = 12, /*!< Corresponding to +12dbm */ - ESP_PWR_LVL_P15 = 13, /*!< Corresponding to +15dbm */ - ESP_PWR_LVL_P18 = 14, /*!< Corresponding to +18dbm */ - ESP_PWR_LVL_P21 = 15, /*!< Corresponding to +21dbm */ - ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */ -} esp_power_level_t; - -/** - * @brief Set BLE TX power - * Connection Tx power should only be set after connection created. - * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc - * @param power_level: Power level(index) corresponding to absolute value(dbm) - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level); - -/** - * @brief Get BLE TX power - * Connection Tx power should only be get after connection created. - * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc - * @return >= 0 - Power level, < 0 - Invalid - */ -esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type); - -/** - * @brief Initialize BT controller to allocate task and other resource. - * This function should be called only once, before any other BT functions are called. - * @param cfg: Initial configuration of BT controller. Different from previous version, there's a mode and some - * connection configuration in "cfg" to configure controller work mode and allocate the resource which is needed. - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg); - -/** - * @brief De-initialize BT controller to free resource and delete task. - * You should stop advertising and scanning, as well as - * disconnect all existing connections before de-initializing BT controller. - * - * This function should be called only once, after any other BT functions are called. - * This function is not whole completed, esp_bt_controller_init cannot called after this function. - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_controller_deinit(void); - -/** - * @brief Enable BT controller. - * Due to a known issue, you cannot call esp_bt_controller_enable() a second time - * to change the controller mode dynamically. To change controller mode, call - * esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode. - * @param mode : the mode(BLE/BT/BTDM) to enable. For compatible of API, retain this argument. This mode must be - * equal as the mode in "cfg" of esp_bt_controller_init(). - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode); - -/** - * @brief Disable BT controller - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_controller_disable(void); - -/** - * @brief Get BT controller is initialised/de-initialised/enabled/disabled - * @return status value - */ -esp_bt_controller_status_t esp_bt_controller_get_status(void); - -uint16_t esp_bt_get_tx_buf_num(void); - -/** @brief esp_vhci_host_callback - * used for vhci call host function to notify what host need to do - */ -typedef struct esp_vhci_host_callback { - void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */ - int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/ -} esp_vhci_host_callback_t; - -/** @brief esp_vhci_host_check_send_available - * used for check actively if the host can send packet to controller or not. - * @return true for ready to send, false means cannot send packet - */ -bool esp_vhci_host_check_send_available(void); - -/** @brief esp_vhci_host_send_packet - * host send packet to controller - * - * Should not call this function from within a critical section - * or when the scheduler is suspended. - * - * @param data the packet point - * @param len the packet length - */ -void esp_vhci_host_send_packet(uint8_t *data, uint16_t len); - -/** @brief esp_vhci_host_register_callback - * register the vhci reference callback - * struct defined by vhci_host_callback structure. - * @param callback esp_vhci_host_callback type variable - * @return ESP_OK - success, ESP_FAIL - failed - */ -esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback); - -/** @brief esp_bt_controller_mem_release - * release the controller memory as per the mode - * - * This function releases the BSS, data and other sections of the controller to heap. The total size is about 70k bytes. - * - * esp_bt_controller_mem_release(mode) should be called only before esp_bt_controller_init() - * or after esp_bt_controller_deinit(). - * - * Note that once BT controller memory is released, the process cannot be reversed. It means you cannot use the bluetooth - * mode which you have released by this function. - * - * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled) - * then do not call this function. - * - * If the app calls esp_bt_controller_enable(ESP_BT_MODE_BLE) to use BLE only then it is safe to call - * esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) at initialization time to free unused BT Classic memory. - * - * If the mode is ESP_BT_MODE_BTDM, then it may be useful to call API esp_bt_mem_release(ESP_BT_MODE_BTDM) instead, - * which internally calls esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) and additionally releases the BSS and data - * consumed by the BT/BLE host stack to heap. For more details about usage please refer to the documentation of - * esp_bt_mem_release() function - * - * @param mode : the mode want to release memory - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode); - -/** @brief esp_bt_mem_release - * release controller memory and BSS and data section of the BT/BLE host stack as per the mode - * - * This function first releases controller memory by internally calling esp_bt_controller_mem_release(). - * Additionally, if the mode is set to ESP_BT_MODE_BTDM, it also releases the BSS and data consumed by the BT/BLE host stack to heap - * - * Note that once BT memory is released, the process cannot be reversed. It means you cannot use the bluetooth - * mode which you have released by this function. - * - * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled) - * then do not call this function. - * - * If you never intend to use bluetooth in a current boot-up cycle, you can call esp_bt_mem_release(ESP_BT_MODE_BTDM) - * before esp_bt_controller_init or after esp_bt_controller_deinit. - * - * For example, if a user only uses bluetooth for setting the WiFi configuration, and does not use bluetooth in the rest of the product operation". - * In such cases, after receiving the WiFi configuration, you can disable/deinit bluetooth and release its memory. - * Below is the sequence of APIs to be called for such scenarios: - * - * esp_bluedroid_disable(); - * esp_bluedroid_deinit(); - * esp_bt_controller_disable(); - * esp_bt_controller_deinit(); - * esp_bt_mem_release(ESP_BT_MODE_BTDM); - * - * @param mode : the mode whose memory is to be released - * @return ESP_OK - success, other - failed - */ -esp_err_t esp_bt_mem_release(esp_bt_mode_t mode); - -/** - * @brief enable bluetooth to enter modem sleep - * - * Note that this function shall not be invoked before esp_bt_controller_enable() - * - * There are currently two options for bluetooth modem sleep, one is ORIG mode, and another is EVED Mode. EVED Mode is intended for BLE only. - * - * For ORIG mode: - * Bluetooth modem sleep is enabled in controller start up by default if CONFIG_BTDM_CONTROLLER_MODEM_SLEEP is set and "ORIG mode" is selected. In ORIG modem sleep mode, bluetooth controller will switch off some components and pause to work every now and then, if there is no event to process; and wakeup according to the scheduled interval and resume the work. It can also wakeup earlier upon external request using function "esp_bt_controller_wakeup_request". - * - * @return - * - ESP_OK : success - * - other : failed - */ -esp_err_t esp_bt_sleep_enable(void); - - -/** - * @brief disable bluetooth modem sleep - * - * Note that this function shall not be invoked before esp_bt_controller_enable() - * - * If esp_bt_sleep_disable() is called, bluetooth controller will not be allowed to enter modem sleep; - * - * If ORIG modem sleep mode is in use, if this function is called, bluetooth controller may not immediately wake up if it is dormant then. - * In this case, esp_bt_controller_wakeup_request() can be used to shorten the time for wakeup. - * - * @return - * - ESP_OK : success - * - other : failed - */ -esp_err_t esp_bt_sleep_disable(void); - -/** - * @brief to check whether bluetooth controller is sleeping at the instant, if modem sleep is enabled - * - * Note that this function shall not be invoked before esp_bt_controller_enable() - * This function is supposed to be used ORIG mode of modem sleep - * - * @return true if in modem sleep state, false otherwise - */ -bool esp_bt_controller_is_sleeping(void); - -/** - * @brief request controller to wakeup from sleeping state during sleep mode - * - * Note that this function shall not be invoked before esp_bt_controller_enable() - * Note that this function is supposed to be used ORIG mode of modem sleep - * Note that after this request, bluetooth controller may again enter sleep as long as the modem sleep is enabled - * - * Profiling shows that it takes several milliseconds to wakeup from modem sleep after this request. - * Generally it takes longer if 32kHz XTAL is used than the main XTAL, due to the lower frequency of the former as the bluetooth low power clock source. - */ -void esp_bt_controller_wakeup_request(void); - -/** - * @brief notify bluetooth controller task to process the event upon Tx or Rx done - * - * Note that this function shall not be invoked before esp_bt_controller_enable() - * This function can be called in both ISR and non-ISR context - * - */ -int esp_bt_h4tl_eif_io_event_notify(int event); - -/** - * @brief bt Wi-Fi power domain power on - */ -void esp_wifi_bt_power_domain_on(void); - -/** - * @brief bt Wi-Fi power domain power off - */ -void esp_wifi_bt_power_domain_off(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __ESP_BT_H__ */ diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld index 390cf6a06c..60fa15b7ea 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld @@ -57,14 +57,18 @@ r_lld_ext_adv_dynamic_pti_process = 0x40001b48; r_lld_adv_ext_pkt_prepare_set = 0x40001b4c; r_lld_adv_ext_chain_none_construct = 0x40001b50; r_lld_adv_ext_chain_connectable_construct = 0x40001b54; +/* r_lld_adv_ext_chain_scannable_construct = 0x40001b58; +*/ r_lld_adv_pkt_rx_connect_post = 0x40001b5c; r_lld_adv_start_init_evt_param = 0x40001b60; r_lld_adv_start_set_cs = 0x40001b64; r_lld_adv_start_update_filter_policy = 0x40001b68; r_lld_adv_start_schedule_asap = 0x40001b6c; r_lld_con_tx_prog_new_packet_coex = 0x40001b70; +/* r_lld_con_tx_prog_new_packet = 0x40001b74; +*/ r_lld_per_adv_dynamic_pti_get = 0x40001b78; r_lld_per_adv_evt_start_chm_upd = 0x40001b7c; r_lld_ext_scan_dynamic_pti_get = 0x40001b80; diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 967a860661..8b71701fe1 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -703,10 +703,14 @@ r_ble_util_data_rx_buf_reset = 0x40000b8c; r_bt_bb_get_intr_mask = 0x40000b90; r_bt_bb_intr_clear = 0x40000b94; r_bt_bb_intr_mask_set = 0x40000b98; +/* r_bt_bb_isr = 0x40000b9c; +*/ r_bt_rf_coex_cfg_set = 0x40000ba0; r_bt_rf_coex_conn_dynamic_pti_en_get = 0x40000ba4; +/* r_bt_rf_coex_conn_phy_coded_data_time_limit_en_get = 0x40000ba8; +*/ r_bt_rf_coex_ext_adv_dynamic_pti_en_get = 0x40000bac; r_bt_rf_coex_ext_scan_dynamic_pti_en_get = 0x40000bb0; r_bt_rf_coex_legacy_adv_dynamic_pti_en_get = 0x40000bb4; @@ -728,14 +732,18 @@ r_bt_rtp_apply_rule_cs_fmt = 0x40000bf0; r_bt_rtp_apply_rule_cs_idx = 0x40000bf4; r_bt_rtp_deregister_rule_cs_fmt = 0x40000bf8; r_bt_rtp_deregister_rule_cs_idx = 0x40000bfc; +/* r_bt_rtp_get_txpwr_idx_by_act = 0x40000c00; +*/ r_bt_rtp_init = 0x40000c04; r_bt_rtp_register_rule_cs_fmt = 0x40000c08; r_bt_rtp_register_rule_cs_idx = 0x40000c0c; r_btdm_isr = 0x40000c10; +/* r_btdm_task_post = 0x40000c14; r_btdm_task_post_from_isr = 0x40000c18; r_btdm_task_recycle = 0x40000c1c; +*/ r_cali_phase_match_p = 0x40000c20; r_cmp_abs_time = 0x40000c24; r_cmp_dest_id = 0x40000c28; @@ -831,7 +839,9 @@ r_hci_look_for_evt_desc = 0x40000d8c; r_hci_look_for_le_evt_desc = 0x40000d90; r_hci_look_for_le_evt_desc_esp = 0x40000d94; r_hci_pack_bytes = 0x40000d98; +/* r_hci_register_vendor_desc_tab = 0x40000d9c; +*/ r_hci_send_2_controller = 0x40000da0; r_hci_send_2_host = 0x40000da4; r_hci_tl_c2h_data_flow_on = 0x40000da8; @@ -888,7 +898,9 @@ r_ke_task_handler_get = 0x40000e70; r_ke_task_init = 0x40000e74; r_ke_task_msg_flush = 0x40000e78; r_ke_task_saved_update = 0x40000e7c; +/* r_ke_task_schedule = 0x40000e80; +*/ r_ke_time = 0x40000e84; r_ke_time_cmp = 0x40000e88; r_ke_time_past = 0x40000e8c; @@ -916,7 +928,9 @@ r_llc_dl_chg_check = 0x40000ee0; r_llc_dle_proc_err_cb = 0x40000ee4; r_llc_feats_exch_proc_err_cb = 0x40000ee8; r_llc_hci_cmd_handler_tab_p_get = 0x40000eec; +/* r_llc_hci_command_handler = 0x40000ef0; +*/ r_llc_hci_con_param_req_evt_send = 0x40000ef4; r_llc_hci_con_upd_info_send = 0x40000ef8; r_llc_hci_disconnected_dis = 0x40000efc; @@ -944,7 +958,9 @@ r_llc_llcp_state_set = 0x40000f50; r_llc_llcp_trans_timer_set = 0x40000f54; r_llc_llcp_tx_check = 0x40000f58; r_llc_loc_ch_map_proc_continue = 0x40000f5c; +/* r_llc_loc_con_upd_proc_continue = 0x40000f60; +*/ r_llc_loc_con_upd_proc_err_cb = 0x40000f64; r_llc_loc_dl_upd_proc_continue = 0x40000f68; r_llc_loc_encrypt_proc_continue = 0x40000f6c; @@ -965,7 +981,9 @@ r_llc_proc_timer_pause_set = 0x40000fa4; r_llc_proc_timer_set = 0x40000fa8; r_llc_proc_unreg = 0x40000fac; r_llc_rem_ch_map_proc_continue = 0x40000fb0; +/* r_llc_rem_con_upd_proc_continue = 0x40000fb4; +*/ r_llc_rem_con_upd_proc_err_cb = 0x40000fb8; r_llc_rem_dl_upd_proc = 0x40000fbc; r_llc_rem_encrypt_proc_continue = 0x40000fc0; @@ -1054,10 +1072,14 @@ r_lld_con_rx_isr = 0x40001108; r_lld_con_rx_link_info_check = 0x4000110c; r_lld_con_rx_llcp_check = 0x40001110; r_lld_con_rx_sync_time_update = 0x40001114; +/* r_lld_con_sched = 0x40001118; +*/ r_lld_con_set_tx_power = 0x4000111c; r_lld_con_start = 0x40001120; +/* r_lld_con_stop = 0x40001124; +*/ r_lld_con_tx = 0x40001128; r_lld_con_tx_enc = 0x4000112c; r_lld_con_tx_isr = 0x40001130; @@ -1092,7 +1114,9 @@ r_lld_init_set_tx_power = 0x400011a0; r_lld_init_start = 0x400011a4; r_lld_init_stop = 0x400011a8; r_lld_instant_proc_end = 0x400011ac; +/* r_lld_llcp_rx_ind_handler = 0x400011b0; +*/ r_lld_per_adv_ch_map_update = 0x400011b4; r_lld_per_adv_chain_construct = 0x400011b8; r_lld_per_adv_cleanup = 0x400011bc; @@ -1110,7 +1134,9 @@ r_lld_per_adv_init = 0x400011e8; r_lld_per_adv_init_info_get = 0x400011ec; r_lld_per_adv_list_add = 0x400011f0; r_lld_per_adv_list_rem = 0x400011f4; +/* r_lld_per_adv_sched = 0x400011f8; +*/ r_lld_per_adv_set_tx_power = 0x400011fc; r_lld_per_adv_start = 0x40001200; r_lld_per_adv_stop = 0x40001204; @@ -1144,8 +1170,10 @@ r_lld_scan_frm_rx_isr = 0x40001270; r_lld_scan_frm_skip_isr = 0x40001274; r_lld_scan_init = 0x40001278; r_lld_scan_params_update = 0x4000127c; +/* r_lld_scan_process_pkt_rx = 0x40001280; r_lld_scan_process_pkt_rx_adv_rep = 0x40001284; +*/ r_lld_scan_process_pkt_rx_aux_adv_ind = 0x40001288; r_lld_scan_process_pkt_rx_aux_chain_ind = 0x4000128c; r_lld_scan_process_pkt_rx_aux_scan_rsp = 0x40001290; @@ -1220,7 +1248,9 @@ r_llm_is_dev_synced = 0x400013a0; r_llm_is_non_con_act_ongoing_check = 0x400013a4; r_llm_is_wl_accessible = 0x400013a8; r_llm_le_evt_mask_check = 0x400013ac; +/* r_llm_le_features_get = 0x400013b0; +*/ r_llm_link_disc = 0x400013b4; r_llm_master_ch_map_get = 0x400013b8; r_llm_msg_handler_tab_p_get = 0x400013bc; @@ -1240,7 +1270,9 @@ r_misc_msg_handler_tab_p_get = 0x400013f0; r_notEqual256 = 0x400013f4; r_phy_upd_proc_start = 0x400013f8; r_platform_reset = 0x400013fc; +/* r_register_esp_vendor_cmd_handler = 0x40001400; +*/ r_rf_em_init = 0x40001404; r_rf_force_agc_enable = 0x40001408; r_rf_reg_rd = 0x4000140c; @@ -1250,8 +1282,10 @@ r_rf_rssi_convert = 0x40001418; r_rf_rw_v9_le_disable = 0x4000141c; r_rf_rw_v9_le_enable = 0x40001420; r_rf_sleep = 0x40001424; +/* r_rf_txpwr_cs_get = 0x40001428; r_rf_txpwr_dbm_get = 0x4000142c; +*/ r_rf_util_cs_fmt_convert = 0x40001430; r_rw_crypto_aes_ccm = 0x40001434; r_rw_crypto_aes_encrypt = 0x40001438; @@ -1265,7 +1299,9 @@ r_rw_crypto_aes_result_handler = 0x40001454; r_rw_crypto_aes_s1 = 0x40001458; r_rw_cryto_aes_cmac = 0x4000145c; r_rw_v9_init_em_radio_table = 0x40001460; +/* r_rwble_isr = 0x40001464; +*/ r_rwble_sleep_enter = 0x40001468; r_rwble_sleep_wakeup_end = 0x4000146c; r_rwbtdm_isr_wrapper = 0x40001470; @@ -1302,7 +1338,9 @@ r_sch_alarm_set = 0x400014e8; r_sch_alarm_timer_isr = 0x400014ec; r_sch_arb_conflict_check = 0x400014f0; r_sch_arb_elt_cancel = 0x400014f4; +/* r_sch_arb_event_start_isr = 0x400014f8; +*/ r_sch_arb_init = 0x400014fc; r_sch_arb_insert = 0x40001500; r_sch_arb_prog_timer = 0x40001504; @@ -1317,8 +1355,10 @@ r_sch_plan_offset_req = 0x40001524; r_sch_plan_position_range_compute = 0x40001528; r_sch_plan_rem = 0x4000152c; r_sch_plan_req = 0x40001530; +/* r_sch_plan_set = 0x40001534; r_sch_prog_end_isr = 0x40001538; +*/ r_sch_prog_init = 0x4000153c; r_sch_prog_push = 0x40001540; r_sch_prog_rx_isr = 0x40001544; @@ -1491,6 +1531,49 @@ rwip_coex_cfg = 0x3ff1eeac; rwip_priority = 0x3ff1ee94; veryBigHexP256 = 0x3ff1ee48; +/* bluetooth hook funcs */ +r_llc_loc_encrypt_proc_continue_hook = 0x40001c60; +r_llc_loc_phy_upd_proc_continue_hook = 0x40001c64; +r_llc_rem_phy_upd_proc_continue_hook = 0x40001c68; +r_lld_scan_frm_eof_isr_hook = 0x40001c6c; +r_lld_scan_evt_start_cbk_hook = 0x40001c70; +/* +r_lld_scan_start_hook = 0x40001c74; +*/ +r_lld_scan_process_pkt_rx_ext_adv_hook = 0x40001c78; +r_lld_scan_sched_hook = 0x40001c7c; +/* +r_lld_adv_start_hook = 0x40001c80; +*/ +r_lld_adv_evt_start_cbk_hook = 0x40001c84; +r_lld_adv_aux_evt_start_cbk_hook = 0x40001c88; +r_lld_adv_frm_isr_hook = 0x40001c8c; +r_lld_adv_start_init_evt_param_hook = 0x40001c90; +r_lld_con_evt_canceled_cbk_hook = 0x40001c94; +r_lld_con_frm_isr_hook = 0x40001c98; +r_lld_con_tx_hook = 0x40001c9c; +r_lld_con_rx_hook = 0x40001ca0; +r_lld_con_evt_start_cbk_hook = 0x40001ca4; +/* +r_lld_con_start_hook = 0x40001ca8; +*/ +r_lld_con_tx_prog_new_packet_hook = 0x40001cac; +r_lld_init_frm_eof_isr_hook = 0x40001cb0; +r_lld_init_evt_start_cbk_hook = 0x40001cb4; +/* +r_lld_init_start_hook = 0x40001cb8; +*/ +r_lld_init_sched_hook = 0x40001cbc; +r_lld_init_process_pkt_tx_hook = 0x40001cc0; +r_lld_per_adv_evt_start_cbk_hook = 0x40001cc4; +r_lld_per_adv_frm_isr_hook = 0x40001cc8; +r_lld_per_adv_start_hook = 0x40001ccc; +r_lld_sync_frm_eof_isr_hook = 0x40001cd0; +r_lld_sync_evt_start_cbk_hook = 0x40001cd4; +r_lld_sync_start_hook = 0x40001cd8; +r_lld_sync_process_pkt_rx_pkt_check_hook = 0x40001cdc; +r_sch_arb_insert_hook = 0x40001ce0; +r_sch_plan_offset_req_hook = 0x40001ce4; /*************************************** Group rom_pp diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index 4137d9cd3e..55b04b8111 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -976,10 +976,14 @@ r_ble_util_data_rx_buf_reset = 0x40003288; r_bt_bb_get_intr_mask = 0x40003294; r_bt_bb_intr_clear = 0x400032a0; r_bt_bb_intr_mask_set = 0x400032ac; +/* r_bt_bb_isr = 0x400032b8; +*/ r_bt_rf_coex_cfg_set = 0x400032c4; r_bt_rf_coex_conn_dynamic_pti_en_get = 0x400032d0; +/* r_bt_rf_coex_conn_phy_coded_data_time_limit_en_get = 0x400032dc; +*/ r_bt_rf_coex_ext_adv_dynamic_pti_en_get = 0x400032e8; r_bt_rf_coex_ext_scan_dynamic_pti_en_get = 0x400032f4; r_bt_rf_coex_legacy_adv_dynamic_pti_en_get = 0x40003300; @@ -1001,14 +1005,18 @@ r_bt_rtp_apply_rule_cs_fmt = 0x400033b4; r_bt_rtp_apply_rule_cs_idx = 0x400033c0; r_bt_rtp_deregister_rule_cs_fmt = 0x400033cc; r_bt_rtp_deregister_rule_cs_idx = 0x400033d8; +/* r_bt_rtp_get_txpwr_idx_by_act = 0x400033e4; +*/ r_bt_rtp_init = 0x400033f0; r_bt_rtp_register_rule_cs_fmt = 0x400033fc; r_bt_rtp_register_rule_cs_idx = 0x40003408; r_btdm_isr = 0x40003414; +/* r_btdm_task_post = 0x40003420; r_btdm_task_post_from_isr = 0x4000342c; r_btdm_task_recycle = 0x40003438; +*/ r_cali_phase_match_p = 0x40003444; r_cmp_abs_time = 0x40003450; r_cmp_dest_id = 0x4000345c; @@ -1104,7 +1112,9 @@ r_hci_look_for_evt_desc = 0x40003888; r_hci_look_for_le_evt_desc = 0x40003894; r_hci_look_for_le_evt_desc_esp = 0x400038a0; r_hci_pack_bytes = 0x400038ac; +/* r_hci_register_vendor_desc_tab = 0x400038b8; +*/ r_hci_send_2_controller = 0x400038c4; r_hci_send_2_host = 0x400038d0; r_hci_tl_c2h_data_flow_on = 0x400038dc; @@ -1161,7 +1171,9 @@ r_ke_task_handler_get = 0x40003b34; r_ke_task_init = 0x40003b40; r_ke_task_msg_flush = 0x40003b4c; r_ke_task_saved_update = 0x40003b58; +/* r_ke_task_schedule = 0x40003b64; +*/ r_ke_time = 0x40003b70; r_ke_time_cmp = 0x40003b7c; r_ke_time_past = 0x40003b88; @@ -1189,7 +1201,9 @@ r_llc_dl_chg_check = 0x40003c84; r_llc_dle_proc_err_cb = 0x40003c90; r_llc_feats_exch_proc_err_cb = 0x40003c9c; r_llc_hci_cmd_handler_tab_p_get = 0x40003ca8; +/* r_llc_hci_command_handler = 0x40003cb4; +*/ r_llc_hci_con_param_req_evt_send = 0x40003cc0; r_llc_hci_con_upd_info_send = 0x40003ccc; r_llc_hci_disconnected_dis = 0x40003cd8; @@ -1217,7 +1231,9 @@ r_llc_llcp_state_set = 0x40003dd4; r_llc_llcp_trans_timer_set = 0x40003de0; r_llc_llcp_tx_check = 0x40003dec; r_llc_loc_ch_map_proc_continue = 0x40003df8; +/* r_llc_loc_con_upd_proc_continue = 0x40003e04; +*/ r_llc_loc_con_upd_proc_err_cb = 0x40003e10; r_llc_loc_dl_upd_proc_continue = 0x40003e1c; r_llc_loc_encrypt_proc_continue = 0x40003e28; @@ -1238,7 +1254,9 @@ r_llc_proc_timer_pause_set = 0x40003ed0; r_llc_proc_timer_set = 0x40003edc; r_llc_proc_unreg = 0x40003ee8; r_llc_rem_ch_map_proc_continue = 0x40003ef4; +/* r_llc_rem_con_upd_proc_continue = 0x40003f00; +*/ r_llc_rem_con_upd_proc_err_cb = 0x40003f0c; r_llc_rem_dl_upd_proc = 0x40003f18; r_llc_rem_encrypt_proc_continue = 0x40003f24; @@ -1327,10 +1345,14 @@ r_lld_con_rx_isr = 0x400042fc; r_lld_con_rx_link_info_check = 0x40004308; r_lld_con_rx_llcp_check = 0x40004314; r_lld_con_rx_sync_time_update = 0x40004320; +/* r_lld_con_sched = 0x4000432c; +*/ r_lld_con_set_tx_power = 0x40004338; r_lld_con_start = 0x40004344; +/* r_lld_con_stop = 0x40004350; +*/ r_lld_con_tx = 0x4000435c; r_lld_con_tx_enc = 0x40004368; r_lld_con_tx_isr = 0x40004374; @@ -1365,7 +1387,9 @@ r_lld_init_set_tx_power = 0x400044c4; r_lld_init_start = 0x400044d0; r_lld_init_stop = 0x400044dc; r_lld_instant_proc_end = 0x400044e8; +/* r_lld_llcp_rx_ind_handler = 0x400044f4; +*/ r_lld_per_adv_ch_map_update = 0x40004500; r_lld_per_adv_chain_construct = 0x4000450c; r_lld_per_adv_cleanup = 0x40004518; @@ -1383,7 +1407,9 @@ r_lld_per_adv_init = 0x4000459c; r_lld_per_adv_init_info_get = 0x400045a8; r_lld_per_adv_list_add = 0x400045b4; r_lld_per_adv_list_rem = 0x400045c0; +/* r_lld_per_adv_sched = 0x400045cc; +*/ r_lld_per_adv_set_tx_power = 0x400045d8; r_lld_per_adv_start = 0x400045e4; r_lld_per_adv_stop = 0x400045f0; @@ -1417,8 +1443,10 @@ r_lld_scan_frm_rx_isr = 0x40004734; r_lld_scan_frm_skip_isr = 0x40004740; r_lld_scan_init = 0x4000474c; r_lld_scan_params_update = 0x40004758; +/* r_lld_scan_process_pkt_rx = 0x40004764; r_lld_scan_process_pkt_rx_adv_rep = 0x40004770; +*/ r_lld_scan_process_pkt_rx_aux_adv_ind = 0x4000477c; r_lld_scan_process_pkt_rx_aux_chain_ind = 0x40004788; r_lld_scan_process_pkt_rx_aux_scan_rsp = 0x40004794; @@ -1493,7 +1521,9 @@ r_llm_is_dev_synced = 0x40004ac4; r_llm_is_non_con_act_ongoing_check = 0x40004ad0; r_llm_is_wl_accessible = 0x40004adc; r_llm_le_evt_mask_check = 0x40004ae8; +/* r_llm_le_features_get = 0x40004af4; +*/ r_llm_link_disc = 0x40004b00; r_llm_master_ch_map_get = 0x40004b0c; r_llm_msg_handler_tab_p_get = 0x40004b18; @@ -1513,7 +1543,9 @@ r_misc_msg_handler_tab_p_get = 0x40004bb4; r_notEqual256 = 0x40004bc0; r_phy_upd_proc_start = 0x40004bcc; r_platform_reset = 0x40004bd8; +/* r_register_esp_vendor_cmd_handler = 0x40004be4; +*/ r_rf_em_init = 0x40004bf0; r_rf_force_agc_enable = 0x40004bfc; r_rf_reg_rd = 0x40004c08; @@ -1523,8 +1555,10 @@ r_rf_rssi_convert = 0x40004c2c; r_rf_rw_v9_le_disable = 0x40004c38; r_rf_rw_v9_le_enable = 0x40004c44; r_rf_sleep = 0x40004c50; +/* r_rf_txpwr_cs_get = 0x40004c5c; r_rf_txpwr_dbm_get = 0x40004c68; +*/ r_rf_util_cs_fmt_convert = 0x40004c74; r_rw_crypto_aes_ccm = 0x40004c80; r_rw_crypto_aes_encrypt = 0x40004c8c; @@ -1538,7 +1572,9 @@ r_rw_crypto_aes_result_handler = 0x40004ce0; r_rw_crypto_aes_s1 = 0x40004cec; r_rw_cryto_aes_cmac = 0x40004cf8; r_rw_v9_init_em_radio_table = 0x40004d04; +/* r_rwble_isr = 0x40004d10; +*/ r_rwble_sleep_enter = 0x40004d1c; r_rwble_sleep_wakeup_end = 0x40004d28; r_rwbtdm_isr_wrapper = 0x40004d34; @@ -1575,7 +1611,9 @@ r_sch_alarm_set = 0x40004e9c; r_sch_alarm_timer_isr = 0x40004ea8; r_sch_arb_conflict_check = 0x40004eb4; r_sch_arb_elt_cancel = 0x40004ec0; +/* r_sch_arb_event_start_isr = 0x40004ecc; +*/ r_sch_arb_init = 0x40004ed8; r_sch_arb_insert = 0x40004ee4; r_sch_arb_prog_timer = 0x40004ef0; @@ -1590,8 +1628,10 @@ r_sch_plan_offset_req = 0x40004f50; r_sch_plan_position_range_compute = 0x40004f5c; r_sch_plan_rem = 0x40004f68; r_sch_plan_req = 0x40004f74; +/* r_sch_plan_set = 0x40004f80; r_sch_prog_end_isr = 0x40004f8c; +*/ r_sch_prog_init = 0x40004f98; r_sch_prog_push = 0x40004fa4; r_sch_prog_rx_isr = 0x40004fb0; @@ -1629,14 +1669,18 @@ r_lld_ext_adv_dynamic_pti_process = 0x40005124; r_lld_adv_ext_pkt_prepare_set = 0x40005130; r_lld_adv_ext_chain_none_construct = 0x4000513c; r_lld_adv_ext_chain_connectable_construct = 0x40005148; +/* r_lld_adv_ext_chain_scannable_construct = 0x40005154; +*/ r_lld_adv_pkt_rx_connect_post = 0x40005160; r_lld_adv_start_init_evt_param = 0x4000516c; r_lld_adv_start_set_cs = 0x40005178; r_lld_adv_start_update_filter_policy = 0x40005184; r_lld_adv_start_schedule_asap = 0x40005190; r_lld_con_tx_prog_new_packet_coex = 0x4000519c; +/* r_lld_con_tx_prog_new_packet = 0x400051a8; +*/ r_lld_per_adv_dynamic_pti_get = 0x400051b4; r_lld_per_adv_evt_start_chm_upd = 0x400051c0; r_lld_ext_scan_dynamic_pti_get = 0x400051cc; @@ -1793,6 +1837,49 @@ rwip_coex_cfg = 0x3ff1eebe; rwip_priority = 0x3ff1eea8; veryBigHexP256 = 0x3ff1ee5c; +/* bluetooth hook funcs */ +r_llc_loc_encrypt_proc_continue_hook = 0x40001c60; +r_llc_loc_phy_upd_proc_continue_hook = 0x40001c64; +r_llc_rem_phy_upd_proc_continue_hook = 0x40001c68; +r_lld_scan_frm_eof_isr_hook = 0x40001c6c; +r_lld_scan_evt_start_cbk_hook = 0x40001c70; +/* +r_lld_scan_start_hook = 0x40001c74; +*/ +r_lld_scan_process_pkt_rx_ext_adv_hook = 0x40001c78; +r_lld_scan_sched_hook = 0x40001c7c; +/* +r_lld_adv_start_hook = 0x40001c80; +*/ +r_lld_adv_evt_start_cbk_hook = 0x40001c84; +r_lld_adv_aux_evt_start_cbk_hook = 0x40001c88; +r_lld_adv_frm_isr_hook = 0x40001c8c; +r_lld_adv_start_init_evt_param_hook = 0x40001c90; +r_lld_con_evt_canceled_cbk_hook = 0x40001c94; +r_lld_con_frm_isr_hook = 0x40001c98; +r_lld_con_tx_hook = 0x40001c9c; +r_lld_con_rx_hook = 0x40001ca0; +r_lld_con_evt_start_cbk_hook = 0x40001ca4; +/* +r_lld_con_start_hook = 0x40001ca8; +*/ +r_lld_con_tx_prog_new_packet_hook = 0x40001cac; +r_lld_init_frm_eof_isr_hook = 0x40001cb0; +r_lld_init_evt_start_cbk_hook = 0x40001cb4; +/* +r_lld_init_start_hook = 0x40001cb8; +*/ +r_lld_init_sched_hook = 0x40001cbc; +r_lld_init_process_pkt_tx_hook = 0x40001cc0; +r_lld_per_adv_evt_start_cbk_hook = 0x40001cc4; +r_lld_per_adv_frm_isr_hook = 0x40001cc8; +r_lld_per_adv_start_hook = 0x40001ccc; +r_lld_sync_frm_eof_isr_hook = 0x40001cd0; +r_lld_sync_evt_start_cbk_hook = 0x40001cd4; +r_lld_sync_start_hook = 0x40001cd8; +r_lld_sync_process_pkt_rx_pkt_check_hook = 0x40001cdc; +r_sch_arb_insert_hook = 0x40001ce0; +r_sch_plan_offset_req_hook = 0x40001ce4; /*************************************** Group rom_pp diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index da51423424..76222b0e31 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -321,3 +321,8 @@ */ #define SOC_SDMMC_USE_IOMUX 1 #define SOC_SDMMC_NUM_SLOTS 2 + + +/*-------------------------- Bluetooth CAPS ----------------------------*/ + +#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (0) diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index 7e1fb5a935..e0fa714429 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -306,3 +306,7 @@ #define SOC_PM_SUPPORT_WIFI_PD (1) #define SOC_PM_SUPPORT_BT_PD (1) + +/*-------------------------- Bluetooth CAPS ----------------------------*/ + +#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 245f39c08c..4b03d845e8 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -279,3 +279,7 @@ #define SOC_PM_SUPPORT_CPU_PD (1) #define SOC_PM_SUPPORT_BT_PD (1) + +/*-------------------------- Bluetooth CAPS ----------------------------*/ + +#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 5c9fbc1d64..d8fa7e995a 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -360,3 +360,7 @@ #define SOC_SDMMC_NUM_SLOTS 2 /* Indicates that there is an option to use XTAL clock instead of PLL for SDMMC */ #define SOC_SDMMC_SUPPORT_XTAL_CLOCK 1 + +/*-------------------------- Bluetooth CAPS ----------------------------*/ + +#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) diff --git a/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c b/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c index b3fb958afa..8c066272a9 100644 --- a/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c @@ -251,7 +251,7 @@ void app_main(void) FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_adv_data_raw(2, sizeof(legacy_adv_data), &legacy_adv_data[0]), test_sem); FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(2, sizeof(legacy_scan_rsp_data), &legacy_scan_rsp_data[0]), test_sem); - // coded phy extend adv, Connectable advertising + // coded phy extend adv, Scannable advertising FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_params(3, &ext_adv_params_coded), test_sem); FUNC_SEND_WAIT_SEM(esp_ble_gap_ext_adv_set_rand_addr(3, addr_coded), test_sem); FUNC_SEND_WAIT_SEM(esp_ble_gap_config_ext_scan_rsp_data_raw(3, sizeof(raw_scan_rsp_data_coded), &raw_scan_rsp_data_coded[0]), test_sem);