From 5a17387c3de8b39171bbea860bd0b97c6ea285b3 Mon Sep 17 00:00:00 2001 From: Xia Xiaotian Date: Wed, 9 Dec 2020 14:26:35 +0800 Subject: [PATCH] esp_wifi: decouple Wi-Fi and bluetooth with coexist to reduce binary file size --- components/bt/controller/bt.c | 158 +++++++++++++++++- components/bt/controller/lib | 2 +- components/esp_wifi/esp32/esp_adapter.c | 75 +++++++-- components/esp_wifi/esp32s2/esp_adapter.c | 75 +++++++-- .../esp_wifi/include/esp_coexist_internal.h | 71 +++++--- .../include/esp_private/wifi_os_adapter.h | 13 +- components/esp_wifi/lib | 2 +- 7 files changed, 334 insertions(+), 62 deletions(-) diff --git a/components/bt/controller/bt.c b/components/bt/controller/bt.c index 632bd0dfaf..e71a306ea9 100644 --- a/components/bt/controller/bt.c +++ b/components/bt/controller/bt.c @@ -174,6 +174,14 @@ struct osi_funcs_t { int (* _coex_register_bt_cb)(coex_func_cb_t cb); uint32_t (* _coex_bb_reset_lock)(void); void (* _coex_bb_reset_unlock)(uint32_t restore); + int (* _coex_schm_register_btdm_callback)(void *callback); + void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); + void (* _coex_schm_status_bit_set)(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); + int (* _coex_wifi_channel_get)(uint8_t *primary, uint8_t *secondary); + int (* _coex_register_wifi_channel_change_callback)(void *cb); uint32_t _magic; }; @@ -217,11 +225,19 @@ extern int bredr_txpwr_get(int *min_power_level, int *max_power_level); extern void bredr_sco_datapath_set(uint8_t data_path); extern void btdm_controller_scan_duplicate_list_clear(void); /* Coexistence */ -extern int coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration); -extern int coex_bt_release_wrapper(uint32_t event); -extern int coex_register_bt_cb_wrapper(coex_func_cb_t cb); -extern uint32_t coex_bb_reset_lock_wrapper(void); -extern void coex_bb_reset_unlock_wrapper(uint32_t restore); +extern int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration); +extern int coex_bt_release(uint32_t event); +extern int coex_register_bt_cb(coex_func_cb_t cb); +extern uint32_t coex_bb_reset_lock(void); +extern void coex_bb_reset_unlock(uint32_t restore); +extern int coex_schm_register_btdm_callback(void *callback); +extern void coex_schm_status_bit_clear(uint32_t type, uint32_t status); +extern void coex_schm_status_bit_set(uint32_t type, uint32_t status); +extern uint32_t coex_schm_interval_get(void); +extern uint8_t coex_schm_curr_period_get(void); +extern void * coex_schm_curr_phase_get(void); +extern int coex_wifi_channel_get(uint8_t *primary, uint8_t *secondary); +extern int coex_register_wifi_channel_change_callback(void *cb); extern void coex_ble_adv_priority_high_set(bool high); extern char _bss_start_btdm; @@ -287,6 +303,19 @@ static void btdm_sleep_enter_phase2_wrapper(void); static void btdm_sleep_exit_phase3_wrapper(void); static bool coex_bt_wakeup_request(void); static void coex_bt_wakeup_request_end(void); +static int coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration); +static int coex_bt_release_wrapper(uint32_t event); +static int coex_register_bt_cb_wrapper(coex_func_cb_t cb); +static uint32_t coex_bb_reset_lock_wrapper(void); +static void coex_bb_reset_unlock_wrapper(uint32_t restore); +static int coex_schm_register_btdm_callback_wrapper(void *callback); +static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status); +static void coex_schm_status_bit_set_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 int coex_wifi_channel_get_wrapper(uint8_t *primary, uint8_t *secondary); +static int coex_register_wifi_channel_change_callback_wrapper(void *cb); /* Local variable definition *************************************************************************** @@ -341,6 +370,14 @@ static const struct osi_funcs_t osi_funcs_ro = { ._coex_register_bt_cb = coex_register_bt_cb_wrapper, ._coex_bb_reset_lock = coex_bb_reset_lock_wrapper, ._coex_bb_reset_unlock = coex_bb_reset_unlock_wrapper, + ._coex_schm_register_btdm_callback = coex_schm_register_btdm_callback_wrapper, + ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_status_bit_set = coex_schm_status_bit_set_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, + ._coex_wifi_channel_get = coex_wifi_channel_get_wrapper, + ._coex_register_wifi_channel_change_callback = coex_register_wifi_channel_change_callback_wrapper, ._magic = OSI_MAGIC_VALUE, }; @@ -996,6 +1033,117 @@ static void coex_bt_wakeup_request_end(void) return; } +static int IRAM_ATTR coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_bt_request(event, latency, duration); +#else + return 0; +#endif +} + +static int IRAM_ATTR coex_bt_release_wrapper(uint32_t event) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_bt_release(event); +#else + return 0; +#endif +} + +static int coex_register_bt_cb_wrapper(coex_func_cb_t cb) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_bt_cb(cb); +#else + return 0; +#endif +} + +static uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_bb_reset_lock(); +#else + return 0; +#endif +} + +static void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +{ +#if CONFIG_SW_COEXIST_ENABLE + coex_bb_reset_unlock(restore); +#endif +} + +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 0; +#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 +} + +static int coex_wifi_channel_get_wrapper(uint8_t *primary, uint8_t *secondary) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_wifi_channel_get(primary, secondary); +#else + return 0; +#endif +} + +static int coex_register_wifi_channel_change_callback_wrapper(void *cb) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_register_wifi_channel_change_callback(cb); +#else + return 0; +#endif +} + bool esp_vhci_host_check_send_available(void) { return API_vhci_host_check_send_available(); diff --git a/components/bt/controller/lib b/components/bt/controller/lib index 0ba611fc0d..6bc8cb91ac 160000 --- a/components/bt/controller/lib +++ b/components/bt/controller/lib @@ -1 +1 @@ -Subproject commit 0ba611fc0d5b692a94744389ebd0833bcad210ba +Subproject commit 6bc8cb91ac66473a0cd43a92b19af09f7abb35a1 diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index 09c283ba7e..79eb14d35f 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -495,46 +495,80 @@ static int coex_wifi_release_wrapper(uint32_t event) #endif } -int IRAM_ATTR coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) +static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_request(event, latency, duration); +#if CONFIG_SW_COEXIST_ENABLE + return coex_wifi_channel_set(primary, secondary); #else return 0; #endif } -int IRAM_ATTR coex_bt_release_wrapper(uint32_t event) +static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_release(event); +#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 IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_set(interval); #else return 0; #endif } -int coex_register_bt_cb_wrapper(coex_func_cb_t cb) +static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_register_bt_cb(cb); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_get(); #else return 0; #endif } -uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bb_reset_lock(); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_period_get(); #else return 0; #endif } -void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +static void * coex_schm_curr_phase_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_bb_reset_unlock(restore); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_get(); +#else + return NULL; +#endif +} + +static int coex_schm_curr_phase_idx_set_wrapper(int idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_idx_set(idx); +#else + return 0; +#endif +} + +static int coex_schm_curr_phase_idx_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_idx_get(); +#else + return 0; #endif } @@ -548,6 +582,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._set_isr = set_isr_wrapper, ._ints_on = xt_ints_on, ._ints_off = xt_ints_off, + ._is_from_isr = is_from_isr_wrapper, ._spin_lock_create = spin_lock_create_wrapper, ._spin_lock_delete = free, ._wifi_int_disable = wifi_int_disable_wrapper, @@ -641,7 +676,15 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_condition_set = coex_condition_set_wrapper, ._coex_wifi_request = coex_wifi_request_wrapper, ._coex_wifi_release = coex_wifi_release_wrapper, - ._is_from_isr = is_from_isr_wrapper, + ._coex_wifi_channel_set = coex_wifi_channel_set_wrapper, + ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, + ._coex_schm_interval_set = coex_schm_interval_set_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, + ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, + ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 2399f81c46..19d5f39b8a 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -493,46 +493,80 @@ static int coex_wifi_release_wrapper(uint32_t event) #endif } -int IRAM_ATTR coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) +static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_request(event, latency, duration); +#if CONFIG_SW_COEXIST_ENABLE + return coex_wifi_channel_set(primary, secondary); #else return 0; #endif } -int IRAM_ATTR coex_bt_release_wrapper(uint32_t event) +static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_release(event); +#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 IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_set(interval); #else return 0; #endif } -int coex_register_bt_cb_wrapper(coex_func_cb_t cb) +static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_register_bt_cb(cb); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_get(); #else return 0; #endif } -uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bb_reset_lock(); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_period_get(); #else return 0; #endif } -void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +static void * coex_schm_curr_phase_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_bb_reset_unlock(restore); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_get(); +#else + return NULL; +#endif +} + +static int coex_schm_curr_phase_idx_set_wrapper(int idx) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_idx_set(idx); +#else + return 0; +#endif +} + +static int coex_schm_curr_phase_idx_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_curr_phase_idx_get(); +#else + return 0; #endif } @@ -546,6 +580,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._set_isr = set_isr_wrapper, ._ints_on = xt_ints_on, ._ints_off = xt_ints_off, + ._is_from_isr = is_from_isr_wrapper, ._spin_lock_create = spin_lock_create_wrapper, ._spin_lock_delete = free, ._wifi_int_disable = wifi_int_disable_wrapper, @@ -640,7 +675,15 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_condition_set = coex_condition_set_wrapper, ._coex_wifi_request = coex_wifi_request_wrapper, ._coex_wifi_release = coex_wifi_release_wrapper, - ._is_from_isr = is_from_isr_wrapper, + ._coex_wifi_channel_set = coex_wifi_channel_set_wrapper, + ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, + ._coex_schm_interval_set = coex_schm_interval_set_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, + ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper, + ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper, ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index bdd023a93d..9f279ce3b1 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -112,44 +112,73 @@ int coex_wifi_request(uint32_t event, uint32_t latency, uint32_t duration); int coex_wifi_release(uint32_t event); /** - * @brief Blue tooth requests coexistence. + * @brief Set WiFi channel to coexistence module. * - * @param event : blue tooth event - * @param latency : blue tooth will request coexistence after latency - * @param duration : duration for blue tooth to request coexistence + * @param primary : WiFi primary channel + * @param secondary : WiFi secondary channel * @return : 0 - success, other - failed */ -int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration); +int coex_wifi_channel_set(uint8_t primary, uint8_t secondary); /** - * @brief Blue tooth release coexistence. + * @brief Clear coexistence status. * - * @param event : blue tooth event + * @param type : Coexistence status type + * @param status: Coexistence status + */ +void coex_schm_status_bit_clear(uint32_t type, uint32_t status); + +/** + * @brief Set coexistence status. + * + * @param type : Coexistence status type + * @param status: Coexistence status + */ +void coex_schm_status_bit_set(uint32_t type, uint32_t status); + +/** + * @brief Set coexistence scheme interval. + * + * @param interval : Coexistence scheme interval * @return : 0 - success, other - failed */ -int coex_bt_release(uint32_t event); +int coex_schm_interval_set(uint32_t interval); /** - * @brief Register callback function for blue tooth. + * @brief Get coexistence scheme interval. * - * @param cb : callback function + * @return : Coexistence scheme interval + */ +uint32_t coex_schm_interval_get(void); + +/** + * @brief Get current coexistence scheme period. + * + * @return : Coexistence scheme period + */ +uint8_t coex_schm_curr_period_get(void); + +/** + * @brief Get current coexistence scheme phase. + * + * @return : Coexistence scheme phase + */ +void * coex_schm_curr_phase_get(void); + +/** + * @brief Set current coexistence scheme phase index. + * + * @param interval : Coexistence scheme phase index * @return : 0 - success, other - failed */ -int coex_register_bt_cb(coex_func_cb_t cb); +int coex_schm_curr_phase_idx_set(int idx); /** - * @brief Lock before reset base band. + * @brief Get current coexistence scheme phase index. * - * @return : lock value + * @return : Coexistence scheme phase index */ -uint32_t coex_bb_reset_lock(void); - -/** - * @brief Unlock after reset base band. - * - * @param restore : lock value - */ -void coex_bb_reset_unlock(uint32_t restore); +int coex_schm_curr_phase_idx_get(void); /** * @brief Register coexistence adapter functions. diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index ad4245b705..1430731c0f 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -21,7 +21,7 @@ extern "C" { #endif -#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000007 +#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000008 #define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF #define OSI_FUNCS_TIME_BLOCKING 0xffffffff @@ -35,6 +35,7 @@ typedef struct { void (*_set_isr)(int32_t n, void *f, void *arg); void (*_ints_on)(uint32_t mask); void (*_ints_off)(uint32_t mask); + bool (* _is_from_isr)(void); void *(* _spin_lock_create)(void); void (* _spin_lock_delete)(void *lock); uint32_t (*_wifi_int_disable)(void *wifi_int_mux); @@ -133,7 +134,15 @@ typedef struct { void (* _coex_condition_set)(uint32_t type, bool dissatisfy); int32_t (* _coex_wifi_request)(uint32_t event, uint32_t latency, uint32_t duration); int32_t (* _coex_wifi_release)(uint32_t event); - bool (* _is_from_isr)(void); + int (* _coex_wifi_channel_set)(uint8_t primary, uint8_t secondary); + void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); + void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status); + int (* _coex_schm_interval_set)(uint32_t interval); + uint32_t (* _coex_schm_interval_get)(void); + uint8_t (* _coex_schm_curr_period_get)(void); + void * (* _coex_schm_curr_phase_get)(void); + int (* _coex_schm_curr_phase_idx_set)(int idx); + int (* _coex_schm_curr_phase_idx_get)(void); int32_t _magic; } wifi_osi_funcs_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 8075af81e8..a3d7b94fa2 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 8075af81e896da21dfdb25fed98ff5c96b899ed4 +Subproject commit a3d7b94fa2f36c9e3c68eb45b0f516de5d24dfcb