From 02bfd5749f109f2ae126b233c87f3c5aff7254a5 Mon Sep 17 00:00:00 2001 From: baohongde Date: Tue, 19 Mar 2024 16:46:37 +0800 Subject: [PATCH] feat(ble/controller): Add coexist schm for BLE --- components/bt/controller/esp32c3/bt.c | 115 ++++++++++++++++-- components/bt/controller/lib_esp32c3_family | 2 +- .../esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld | 1 - .../esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld | 6 - components/esp_rom/esp32s3/ld/esp32s3.rom.ld | 1 - 5 files changed, 107 insertions(+), 18 deletions(-) diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index e93a1a886d..353fda692b 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -64,6 +64,7 @@ // wakeup request sources enum { BTDM_ASYNC_WAKEUP_SRC_VHCI = 0, + BTDM_ASYNC_WAKEUP_REQ_COEX, BTDM_ASYNC_WAKEUP_SRC_DISA, BTDM_ASYNC_WAKEUP_SRC_TMR, BTDM_ASYNC_WAKEUP_SRC_MAX, @@ -110,7 +111,7 @@ do{\ } while(0) #define OSI_FUNCS_TIME_BLOCKING 0xffffffff -#define OSI_VERSION 0x00010007 +#define OSI_VERSION 0x00010008 #define OSI_MAGIC_VALUE 0xFADEBEAD /* Types definition @@ -185,8 +186,12 @@ struct osi_funcs_t { 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); + int (* _coex_schm_register_btdm_callback)(void *callback); void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status); void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); + uint32_t (* _coex_schm_interval_get)(void); + uint8_t (* _coex_schm_curr_period_get)(void); + void *(* _coex_schm_curr_phase_get)(void); void (* _interrupt_on)(int intr_num); void (* _interrupt_off)(int intr_num); void (* _esp_hw_power_down)(void); @@ -194,6 +199,8 @@ struct osi_funcs_t { void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem); void (* _ets_delay_us)(uint32_t us); void (* _btdm_rom_table_ready)(void); + bool (* _coex_bt_wakeup_request)(void); + void (* _coex_bt_wakeup_request_end)(void); }; @@ -241,6 +248,7 @@ 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 int coex_schm_register_btdm_callback(void *callback); extern bool btdm_deep_sleep_mem_init(void); extern void btdm_deep_sleep_mem_deinit(void); @@ -307,14 +315,20 @@ 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 int coex_schm_register_btdm_callback_wrapper(void *callback); 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 uint32_t coex_schm_interval_get_wrapper(void); +static uint8_t coex_schm_curr_period_get_wrapper(void); +static void * coex_schm_curr_phase_get_wrapper(void); 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_funcs_table_ready_wrapper(void); +static bool coex_bt_wakeup_request(void); +static void coex_bt_wakeup_request_end(void); static void btdm_slp_tmr_callback(void *arg); @@ -372,8 +386,12 @@ static const struct osi_funcs_t osi_funcs_ro = { ._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_register_btdm_callback = coex_schm_register_btdm_callback_wrapper, ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_interval_get = coex_schm_interval_get_wrapper, + ._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper, + ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, ._interrupt_on = interrupt_on_wrapper, ._interrupt_off = interrupt_off_wrapper, ._esp_hw_power_down = btdm_hw_mac_power_down_wrapper, @@ -381,6 +399,8 @@ static const struct osi_funcs_t osi_funcs_ro = { ._ets_backup_dma_copy = btdm_backup_dma_copy_wrapper, ._ets_delay_us = esp_rom_delay_us, ._btdm_rom_table_ready = btdm_funcs_table_ready_wrapper, + ._coex_bt_wakeup_request = coex_bt_wakeup_request, + ._coex_bt_wakeup_request_end = coex_bt_wakeup_request_end, }; static DRAM_ATTR struct osi_funcs_t *osi_funcs_p; @@ -895,6 +915,22 @@ static bool async_wakeup_request(int event) semphr_take_wrapper(s_wakeup_req_sem, OSI_FUNCS_TIME_BLOCKING); } break; + case BTDM_ASYNC_WAKEUP_REQ_COEX: + if (!btdm_power_state_active()) { + do_wakeup_request = true; +#if 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 + 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; + } + } default: break; } @@ -914,6 +950,9 @@ static void async_wakeup_request_end(int event) case BTDM_ASYNC_WAKEUP_SRC_DISA: allow_to_sleep = true; break; + case BTDM_ASYNC_WAKEUP_REQ_COEX: + allow_to_sleep = false; + break; default: allow_to_sleep = true; break; @@ -933,18 +972,25 @@ static void btdm_funcs_table_ready_wrapper(void) #endif } -static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) +bool bt_async_wakeup_request(void) { -#if CONFIG_SW_COEXIST_ENABLE - coex_schm_status_bit_set(type, status); -#endif + return async_wakeup_request(BTDM_ASYNC_WAKEUP_SRC_VHCI); } -static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) +void bt_wakeup_request_end(void) { -#if CONFIG_SW_COEXIST_ENABLE - coex_schm_status_bit_clear(type, status); -#endif + async_wakeup_request_end(BTDM_ASYNC_WAKEUP_SRC_VHCI); +} + +static bool coex_bt_wakeup_request(void) +{ + return async_wakeup_request(BTDM_ASYNC_WAKEUP_REQ_COEX); +} + +static void coex_bt_wakeup_request_end(void) +{ + async_wakeup_request_end(BTDM_ASYNC_WAKEUP_REQ_COEX); + return; } bool esp_vhci_host_check_send_available(void) @@ -1739,4 +1785,55 @@ static void coex_wifi_sleep_set_hook(bool sleep) { } + +static int coex_schm_register_btdm_callback_wrapper(void *callback) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_register_btdm_callback(callback); +#else + return 0; +#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 +} + +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 uint32_t coex_schm_interval_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_get(); +#else + return 0; +#endif +} + +static uint8_t coex_schm_curr_period_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_period_get(); +#else + return 1; +#endif +} + +static void * coex_schm_curr_phase_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_get(); +#else + return NULL; +#endif +} + #endif /* CONFIG_BT_ENABLED */ diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index e5c0f7256e..0698a0dac0 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit e5c0f7256ecf5b5f8eb28c1793051a6b88f95124 +Subproject commit 0698a0dac04e7762ec555dca86bbfa2a631cefa3 diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld index c0c6ecf9cd..d0c46522ff 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld @@ -65,7 +65,6 @@ r_lld_con_tx_prog_new_packet_coex = 0x40001b70; 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; -r_lld_scan_try_sched = 0x40001b84; r_lld_sync_insert = 0x40001b88; r_sch_prog_ble_push = 0x40001b8c; r_sch_prog_bt_push = 0x40001b90; diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld index 1fbf2e9de6..ba3406f990 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco7.ld @@ -138,15 +138,9 @@ r_sch_plan_conflict_check = 0x40001d7c; r_rwble_isr_hw_fixed = 0x40001d80; r_bt_bb_recorrect_is_dead = 0x40001d84; r_bt_bb_restart_hw_recorrect = 0x40001d88; -r_btdm_task_post_impl = 0x40001d8c; -r_btdm_task_post_from_isr_impl = 0x40001d90; -r_btdm_vnd_offload_post_from_isr = 0x40001d94; -r_btdm_vnd_offload_post = 0x40001d98; -r_btdm_vnd_offload_process = 0x40001d9c; r_ke_task_handler_pre = 0x40001da0; r_ke_task_handler_end = 0x40001da4; r_ke_task_handler_get_overwrite = 0x40001da8; -r_lld_scan_try_sched_eco = 0x40001dac; r_lld_scan_frm_skip_isr_eco = 0x40001db0; r_lld_ext_scan_dynamic_pti_reset = 0x40001db4; r_llc_rem_phy_upd_proc_continue_eco = 0x40001db8; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index 1d5fc854b7..c5d28d2d13 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -1609,7 +1609,6 @@ r_lld_con_tx_prog_new_packet_coex = 0x4000519c; 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; -r_lld_scan_try_sched = 0x400051d8; r_lld_sync_insert = 0x400051e4; r_sch_prog_ble_push = 0x400051f0; r_sch_prog_bt_push = 0x400051fc;