From bdbe74693f1ea3994fd3723be807fec19bdd10ec Mon Sep 17 00:00:00 2001 From: Xia Xiaotian Date: Wed, 26 Aug 2020 17:51:13 +0800 Subject: [PATCH] esp_wifi: refactor wifi code in order to adapter to new chips --- components/bt/controller/bt.c | 74 ++++++- components/bt/controller/lib | 2 +- components/esp_system/startup.c | 4 +- components/esp_wifi/esp32/esp_adapter.c | 175 ++++++++++++--- components/esp_wifi/esp32s2/esp_adapter.c | 204 +++++++++++++----- .../esp_wifi/include/esp_coexist_adapter.h | 6 +- .../esp_wifi/include/esp_coexist_internal.h | 86 ++++++-- .../include/esp_private/wifi_os_adapter.h | 24 ++- components/esp_wifi/include/esp_wifi_types.h | 13 +- components/esp_wifi/lib | 2 +- components/esp_wifi/src/wifi_init.c | 4 + .../src/esp_supplicant/esp_wifi_driver.h | 5 +- components/wpa_supplicant/src/rsn_supp/wpa.c | 4 +- 13 files changed, 479 insertions(+), 124 deletions(-) diff --git a/components/bt/controller/bt.c b/components/bt/controller/bt.c index 29aa7bb105..b04108de5b 100644 --- a/components/bt/controller/bt.c +++ b/components/bt/controller/bt.c @@ -217,11 +217,11 @@ 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 void coex_ble_adv_priority_high_set(bool high); extern char _bss_start_btdm; @@ -288,6 +288,11 @@ static void IRAM_ATTR btdm_sleep_exit_phase1_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); /* Local variable definition *************************************************************************** @@ -961,6 +966,49 @@ static void coex_bt_wakeup_request_end(void) return; } +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 +} + +int IRAM_ATTR coex_bt_release_wrapper(uint32_t event) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_bt_release(event); +#else + return 0; +#endif +} + +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 +} + +uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + return coex_bb_reset_lock(); +#else + return 0; +#endif +} + +void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +{ +#if CONFIG_SW_COEXIST_ENABLE + coex_bb_reset_unlock(restore); +#endif +} + bool esp_vhci_host_check_send_available(void) { return API_vhci_host_check_send_available(); @@ -1271,6 +1319,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) } #endif +#if CONFIG_SW_COEXIST_ENABLE + coex_init(); +#endif + btdm_cfg_mask = btdm_config_mask_load(); if (btdm_controller_init(btdm_cfg_mask, cfg) != 0) { @@ -1375,8 +1427,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) esp_phy_enable(); -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_init(); +#if CONFIG_SW_COEXIST_ENABLE + coex_enable(); #endif if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) { @@ -1388,8 +1440,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) ret = btdm_controller_enable(mode); if (ret != 0) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_deinit(); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); #endif esp_phy_disable(); #ifdef CONFIG_PM_ENABLE @@ -1425,8 +1477,8 @@ esp_err_t esp_bt_controller_disable(void) btdm_controller_disable(); -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_deinit(); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); #endif esp_phy_disable(); diff --git a/components/bt/controller/lib b/components/bt/controller/lib index d2fd8129aa..97375274e9 160000 --- a/components/bt/controller/lib +++ b/components/bt/controller/lib @@ -1 +1 @@ -Subproject commit d2fd8129aaea47408a76590508443192d82fe2f1 +Subproject commit 97375274e9446551835697c23357e23f3cf23146 diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index d65ce54d75..d08b390621 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -391,12 +391,10 @@ esp_pm_config_esp32s2_t cfg = { #endif #endif -#if CONFIG_IDF_TARGET_ESP32 -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE esp_coex_adapter_register(&g_coex_adapter_funcs); coex_pre_init(); #endif -#endif #ifdef CONFIG_BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE const esp_partition_t *efuse_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_EFUSE_EM, NULL); diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index 551633e1dd..d6e17d013e 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -51,6 +51,11 @@ #define TAG "esp_adapter" +#ifdef CONFIG_PM_ENABLE +extern void wifi_apb80m_request(void); +extern void wifi_apb80m_release(void); +#endif + static void IRAM_ATTR s_esp_dport_access_stall_other_cpu_start(void) { DPORT_STALL_OTHER_CPU_START(); @@ -174,6 +179,25 @@ static void wifi_delete_queue_wrapper(void *queue) wifi_delete_queue(queue); } +static bool IRAM_ATTR env_is_chip_wrapper(void) +{ +#ifdef CONFIG_IDF_ENV_FPGA + return false; +#else + return true; +#endif +} + +static void set_intr_wrapper(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio) +{ + intr_matrix_set(cpu_no, intr_source, intr_num); +} + +static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num) +{ + +} + static void set_isr_wrapper(int32_t n, void *f, void *arg) { xt_set_interrupt_handler(n, (xt_handler)f, arg); @@ -213,7 +237,7 @@ static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) static bool IRAM_ATTR is_from_isr_wrapper(void) { - return xPortInIsrContext(); + return !xPortCanYield(); } static void IRAM_ATTR task_yield_from_isr_wrapper(void) @@ -391,6 +415,20 @@ static int32_t esp_event_post_wrapper(const char* event_base, int32_t event_id, } } +static void IRAM_ATTR wifi_apb80m_request_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_request(); +#endif +} + +static void IRAM_ATTR wifi_apb80m_release_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_release(); +#endif +} + static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat) { ets_timer_arm(timer, tmout, repeat); @@ -463,7 +501,7 @@ static void * IRAM_ATTR zalloc_internal_wrapper(size_t size) static int coex_init_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_init(); #else return 0; @@ -472,14 +510,30 @@ static int coex_init_wrapper(void) static void coex_deinit_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE coex_deinit(); #endif } -static uint32_t coex_status_get_wrapper(void) +static int coex_enable_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE + return coex_enable(); +#else + return 0; +#endif +} + +static void coex_disable_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif +} + +static IRAM_ATTR uint32_t coex_status_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE return coex_status_get(); #else return 0; @@ -495,65 +549,118 @@ static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy) static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_wifi_request(event, latency, duration); #else return 0; #endif } -static int coex_wifi_release_wrapper(uint32_t event) +static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_wifi_release(event); #else return 0; #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 IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_release(event); +#if CONFIG_SW_COEXIST_ENABLE + return coex_event_duration_get(event, duration); #else return 0; #endif } -int coex_register_bt_cb_wrapper(coex_func_cb_t cb) +static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_register_bt_cb(cb); + return 0; +} + +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 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 } -uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bb_reset_lock(); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_get(); #else return 0; #endif } -void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_bb_reset_unlock(restore); +#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_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 +} + +static void IRAM_ATTR esp_empty_wrapper(void) +{ + +} + int32_t IRAM_ATTR coex_is_in_isr_wrapper(void) { return !xPortCanYield(); @@ -561,9 +668,13 @@ int32_t IRAM_ATTR coex_is_in_isr_wrapper(void) wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, + ._env_is_chip = env_is_chip_wrapper, + ._set_intr = set_intr_wrapper, + ._clear_intr = clear_intr_wrapper, ._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, @@ -606,6 +717,8 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._rand = esp_random, ._dport_access_stall_other_cpu_start_wrap = s_esp_dport_access_stall_other_cpu_start, ._dport_access_stall_other_cpu_end_wrap = s_esp_dport_access_stall_other_cpu_end, + ._wifi_apb80m_request = wifi_apb80m_request_wrapper, + ._wifi_apb80m_release = wifi_apb80m_release_wrapper, ._phy_disable = esp_phy_disable, ._phy_enable = esp_phy_enable, ._phy_common_clock_enable = esp_phy_common_clock_enable, @@ -620,6 +733,8 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._wifi_reset_mac = wifi_reset_mac_wrapper, ._wifi_clock_enable = wifi_clock_enable_wrapper, ._wifi_clock_disable = wifi_clock_disable_wrapper, + ._wifi_rtc_enable_iso = esp_empty_wrapper, + ._wifi_rtc_disable_iso = esp_empty_wrapper, ._esp_timer_get_time = esp_timer_get_time, ._nvs_set_i8 = nvs_set_i8, ._nvs_get_i8 = nvs_get_i8, @@ -651,11 +766,23 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._wifi_delete_queue = wifi_delete_queue_wrapper, ._coex_init = coex_init_wrapper, ._coex_deinit = coex_deinit_wrapper, + ._coex_enable = coex_enable_wrapper, + ._coex_disable = coex_disable_wrapper, ._coex_status_get = coex_status_get_wrapper, ._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_event_duration_get = coex_event_duration_get_wrapper, + ._coex_pti_get = coex_pti_get_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 c236ef6079..af6ea90bc3 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -46,11 +46,14 @@ #include "nvs.h" #include "os.h" #include "esp_smartconfig.h" -#include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #define TAG "esp_adapter" +#ifdef CONFIG_PM_ENABLE +extern void wifi_apb80m_request(void); +extern void wifi_apb80m_release(void); +#endif + /* If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly. If failed, try to allocate it in internal memory then. @@ -164,6 +167,25 @@ static void wifi_delete_queue_wrapper(void *queue) wifi_delete_queue(queue); } +static bool IRAM_ATTR env_is_chip_wrapper(void) +{ +#ifdef CONFIG_IDF_ENV_FPGA + return false; +#else + return true; +#endif +} + +static void set_intr_wrapper(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio) +{ + intr_matrix_set(cpu_no, intr_source, intr_num); +} + +static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num) +{ + +} + static void set_isr_wrapper(int32_t n, void *f, void *arg) { xt_set_interrupt_handler(n, (xt_handler)f, arg); @@ -203,7 +225,7 @@ static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) static bool IRAM_ATTR is_from_isr_wrapper(void) { - return xPortInIsrContext(); + return !xPortCanYield(); } static void IRAM_ATTR task_yield_from_isr_wrapper(void) @@ -256,16 +278,6 @@ static void * wifi_thread_semphr_get_wrapper(void) return (void*)sem; } -static int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreTakeFromISR(semphr, hptw); -} - -static int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreGiveFromISR(semphr, hptw); -} - static int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick) { if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { @@ -381,6 +393,20 @@ static int32_t esp_event_post_wrapper(const char* event_base, int32_t event_id, } } +static void IRAM_ATTR wifi_apb80m_request_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_request(); +#endif +} + +static void IRAM_ATTR wifi_apb80m_release_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_release(); +#endif +} + static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat) { ets_timer_arm(timer, tmout, repeat); @@ -461,7 +487,7 @@ static void * IRAM_ATTR zalloc_internal_wrapper(size_t size) static int coex_init_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_init(); #else return 0; @@ -470,14 +496,30 @@ static int coex_init_wrapper(void) static void coex_deinit_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE coex_deinit(); #endif } -static uint32_t coex_status_get_wrapper(void) +static int coex_enable_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE + return coex_enable(); +#else + return 0; +#endif +} + +static void coex_disable_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif +} + +static IRAM_ATTR uint32_t coex_status_get_wrapper(void) +{ +#if CONFIG_SW_COEXIST_ENABLE return coex_status_get(); #else return 0; @@ -493,7 +535,7 @@ static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy) static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_wifi_request(event, latency, duration); #else return 0; @@ -502,53 +544,101 @@ static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t static int coex_wifi_release_wrapper(uint32_t event) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE return coex_wifi_release(event); #else return 0; #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 IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bt_release(event); +#if CONFIG_SW_COEXIST_ENABLE + return coex_event_duration_get(event, duration); #else return 0; #endif } -int coex_register_bt_cb_wrapper(coex_func_cb_t cb) +static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_register_bt_cb(cb); + return 0; +} + +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 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 } -uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void) +static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - return coex_bb_reset_lock(); +#if CONFIG_SW_COEXIST_ENABLE + return coex_schm_interval_get(); #else return 0; #endif } -void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore) +static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE - coex_bb_reset_unlock(restore); +#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_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 } @@ -559,9 +649,13 @@ static void IRAM_ATTR esp_empty_wrapper(void) wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, + ._env_is_chip = env_is_chip_wrapper, + ._set_intr = set_intr_wrapper, + ._clear_intr = clear_intr_wrapper, ._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, @@ -604,6 +698,8 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._rand = esp_random, ._dport_access_stall_other_cpu_start_wrap = esp_empty_wrapper, ._dport_access_stall_other_cpu_end_wrap = esp_empty_wrapper, + ._wifi_apb80m_request = wifi_apb80m_request_wrapper, + ._wifi_apb80m_release = wifi_apb80m_release_wrapper, ._phy_disable = esp_phy_disable, ._phy_enable = esp_phy_enable, ._phy_update_country_info = esp_phy_update_country_info, @@ -616,6 +712,8 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._wifi_reset_mac = wifi_reset_mac_wrapper, ._wifi_clock_enable = wifi_clock_enable_wrapper, ._wifi_clock_disable = wifi_clock_disable_wrapper, + ._wifi_rtc_enable_iso = esp_empty_wrapper, + ._wifi_rtc_disable_iso = esp_empty_wrapper, ._esp_timer_get_time = esp_timer_get_time, ._nvs_set_i8 = nvs_set_i8, ._nvs_get_i8 = nvs_get_i8, @@ -648,34 +746,22 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._wifi_delete_queue = wifi_delete_queue_wrapper, ._coex_init = coex_init_wrapper, ._coex_deinit = coex_deinit_wrapper, + ._coex_enable = coex_enable_wrapper, + ._coex_disable = coex_disable_wrapper, ._coex_status_get = coex_status_get_wrapper, ._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_event_duration_get = coex_event_duration_get_wrapper, + ._coex_pti_get = coex_pti_get_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, }; - -coex_adapter_funcs_t g_coex_adapter_funcs = { - ._version = COEX_ADAPTER_VERSION, - ._spin_lock_create = spin_lock_create_wrapper, - ._spin_lock_delete = free, - ._int_disable = wifi_int_disable_wrapper, - ._int_enable = wifi_int_restore_wrapper, - ._task_yield_from_isr = task_yield_from_isr_wrapper, - ._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, - ._is_in_isr = xPortInIsrContext, - ._malloc_internal = malloc_internal_wrapper, - ._free = free, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._esp_timer_get_time = esp_timer_get_time, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/include/esp_coexist_adapter.h b/components/esp_wifi/include/esp_coexist_adapter.h index f2a38c31e6..ecf5f6e67a 100644 --- a/components/esp_wifi/include/esp_coexist_adapter.h +++ b/components/esp_wifi/include/esp_coexist_adapter.h @@ -21,17 +21,19 @@ extern "C" { #endif -#define COEX_ADAPTER_VERSION 0x00000001 +#define COEX_ADAPTER_VERSION 0x00000002 #define COEX_ADAPTER_MAGIC 0xDEADBEAF #define COEX_ADAPTER_FUNCS_TIME_BLOCKING 0xffffffff typedef struct { int32_t _version; +#if CONFIG_IDF_TARGET_ESP32 void *(* _spin_lock_create)(void); void (* _spin_lock_delete)(void *lock); uint32_t (*_int_disable)(void *mux); void (*_int_enable)(void *mux, uint32_t tmp); +#endif void (*_task_yield_from_isr)(void); void *(*_semphr_create)(uint32_t max, uint32_t init); void (*_semphr_delete)(void *semphr); @@ -42,10 +44,12 @@ typedef struct { int32_t (* _is_in_isr)(void); void * (* _malloc_internal)(size_t size); void (* _free)(void *p); +#if CONFIG_IDF_TARGET_ESP32 void (* _timer_disarm)(void *timer); void (* _timer_done)(void *ptimer); void (* _timer_setfn)(void *ptimer, void *pfunction, void *parg); void (* _timer_arm_us)(void *ptimer, uint32_t us, bool repeat); +#endif int64_t (* _esp_timer_get_time)(void); int32_t _magic; } coex_adapter_funcs_t; diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index 8e1dec81a9..848e6d11ab 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -53,6 +53,20 @@ esp_err_t coex_init(void); */ void coex_deinit(void); +/** + * @brief Enable software coexist + * extern function for internal use. + * + * @return Enable ok or failed. + */ +esp_err_t coex_enable(void); + +/** + * @brief Disable software coexist + * extern function for internal use. + */ +void coex_disable(void); + /** * @brief Get software coexist version string * extern function for internal use. @@ -100,44 +114,82 @@ 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 Get coexistence event duration. * - * @param event : blue tooth event + * @param event : Coexistence event + * @param duration: Coexistence event duration * @return : 0 - success, other - failed */ -int coex_bt_release(uint32_t event); +int coex_event_duration_get(uint32_t event, uint32_t *duration); /** - * @brief Register callback function for blue tooth. + * @brief Clear coexistence status. * - * @param cb : callback function + * @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_register_bt_cb(coex_func_cb_t cb); +int coex_schm_interval_set(uint32_t interval); /** - * @brief Lock before reset base band. + * @brief Get coexistence scheme interval. * - * @return : lock value + * @return : Coexistence scheme interval */ -uint32_t coex_bb_reset_lock(void); +uint32_t coex_schm_interval_get(void); /** - * @brief Unlock after reset base band. + * @brief Get current coexistence scheme period. * - * @param restore : lock value + * @return : Coexistence scheme period */ -void coex_bb_reset_unlock(uint32_t restore); +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_schm_curr_phase_idx_set(int idx); + +/** + * @brief Get current coexistence scheme phase index. + * + * @return : Coexistence scheme phase index + */ +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 637caf0fa2..b3011b9a2b 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -32,9 +32,13 @@ extern "C" { typedef struct { int32_t _version; + bool (* _env_is_chip)(void); + void (*_set_intr)(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio); + void (*_clear_intr)(uint32_t intr_source, uint32_t intr_num); 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); @@ -77,6 +81,8 @@ typedef struct { uint32_t (* _rand)(void); void (* _dport_access_stall_other_cpu_start_wrap)(void); void (* _dport_access_stall_other_cpu_end_wrap)(void); + void (* _wifi_apb80m_request)(void); + void (* _wifi_apb80m_release)(void); void (* _phy_disable)(void); void (* _phy_enable)(void); #if CONFIG_IDF_TARGET_ESP32 @@ -93,6 +99,8 @@ typedef struct { void (* _wifi_reset_mac)(void); void (* _wifi_clock_enable)(void); void (* _wifi_clock_disable)(void); + void (* _wifi_rtc_enable_iso)(void); + void (* _wifi_rtc_disable_iso)(void); int64_t (* _esp_timer_get_time)(void); int32_t (* _nvs_set_i8)(uint32_t handle, const char* key, int8_t value); int32_t (* _nvs_get_i8)(uint32_t handle, const char* key, int8_t* out_value); @@ -109,7 +117,7 @@ typedef struct { int32_t (* _get_random)(uint8_t *buf, size_t len); int32_t (* _get_time)(void *t); unsigned long (* _random)(void); -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 uint32_t (* _slowclk_cal_get)(void); #endif void (* _log_write)(uint32_t level, const char* tag, const char* format, ...); @@ -127,11 +135,23 @@ typedef struct { void (* _wifi_delete_queue)(void * queue); int (* _coex_init)(void); void (* _coex_deinit)(void); + int (* _coex_enable)(void); + void (* _coex_disable)(void); uint32_t (* _coex_status_get)(void); 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); + int (* _coex_event_duration_get)(uint32_t event, uint32_t *duration); + int (* _coex_pti_get)(uint32_t event, uint8_t *pti); + 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/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index af3c856934..d54e97d258 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -329,7 +329,7 @@ typedef struct { unsigned sgi:1; /**< Short Guide Interval(SGI). 0: Long GI; 1: Short GI */ #if CONFIG_IDF_TARGET_ESP32 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 unsigned :8; /**< reserved */ #endif unsigned ampdu_cnt:8; /**< ampdu cnt */ @@ -340,12 +340,20 @@ typedef struct { unsigned :32; /**< reserved */ #if CONFIG_IDF_TARGET_ESP32S2 unsigned :32; /**< reserved */ +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 + signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ + unsigned :24; /**< reserved */ + unsigned :32; /**< reserved */ #endif unsigned :31; /**< reserved */ unsigned ant:1; /**< antenna number from which this packet is received. 0: WiFi antenna 0; 1: WiFi antenna 1 */ #if CONFIG_IDF_TARGET_ESP32S2 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ unsigned :24; /**< reserved */ +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 + unsigned :32; /**< reserved */ + unsigned :32; /**< reserved */ + unsigned :32; /**< reserved */ #endif unsigned sig_len:12; /**< length of packet including Frame Check Sequence(FCS) */ unsigned :12; /**< reserved */ @@ -531,6 +539,8 @@ typedef enum { WIFI_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */ WIFI_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */ + WIFI_EVENT_FTM_REPORT, /**< Receive report of FTM procedure */ + WIFI_EVENT_MAX, /**< Invalid WiFi event ID */ } wifi_event_t; @@ -616,6 +626,7 @@ typedef struct { #define WIFI_STATIS_RXTX (1<<1) #define WIFI_STATIS_HW (1<<2) #define WIFI_STATIS_DIAG (1<<3) +#define WIFI_STATIS_PS (1<<4) #define WIFI_STATIS_ALL (-1) #ifdef __cplusplus diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 12e949d5ab..c02243cd78 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 12e949d5ab93a3c82972a8a57a813726f0f3737f +Subproject commit c02243cd78ee8d1f366e4853e75b9c7183523ecf diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 0159e48fa4..cbea8077b9 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -24,6 +24,7 @@ #include "esp_netif.h" #include "tcpip_adapter_compatible/tcpip_adapter_compat.h" #include "driver/adc2_wifi_private.h" +#include "esp_coexist_internal.h" #if (CONFIG_ESP32_WIFI_RX_BA_WIN > CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM) #error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than WIFI_DYNAMIC_RX_BUFFER_NUM!" @@ -199,6 +200,9 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) if (err != ESP_OK) { ESP_LOGW(TAG, "Failed to set default Wi-Fi event handlers (0x%x)", err); } +#endif +#if CONFIG_SW_COEXIST_ENABLE + coex_init(); #endif esp_err_t result = esp_wifi_init_internal(config); if (result == ESP_OK) { diff --git a/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h b/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h index 2b2a7ca008..140d6d1e8a 100644 --- a/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h +++ b/components/wpa_supplicant/src/esp_supplicant/esp_wifi_driver.h @@ -40,7 +40,7 @@ enum { WIFI_WPA_ALG_GCMP }; -enum { +typedef enum { WIFI_APPIE_PROBEREQ = 0, WIFI_APPIE_ASSOC_REQ, WIFI_APPIE_ASSOC_RESP, @@ -53,7 +53,7 @@ enum { WIFI_APPIE_ESP_MANUFACTOR, WIFI_APPIE_COUNTRY, WIFI_APPIE_MAX, -}; +} wifi_appie_t; enum { NONE_AUTH = 0x01, @@ -195,6 +195,7 @@ void esp_wifi_deauthenticate_internal(u8 reason_code); bool esp_wifi_sta_is_running_internal(void); bool esp_wifi_auth_done_internal(void); int esp_wifi_set_ap_key_internal(int alg, const u8 *addr, int idx, u8 *key, size_t key_len); +int esp_wifi_get_sta_hw_key_idx_internal(int key_idx); int esp_wifi_set_sta_key_internal(int alg, u8 *addr, int key_idx, int set_tx, u8 *seq, size_t seq_len, u8 *key, size_t key_len, int key_entry_valid); int esp_wifi_get_sta_key_internal(uint8_t *ifx, int *alg, u8 *addr, int *key_idx, diff --git a/components/wpa_supplicant/src/rsn_supp/wpa.c b/components/wpa_supplicant/src/rsn_supp/wpa.c index 064bd59a6f..deafceac15 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa.c @@ -672,7 +672,7 @@ int wpa_supplicant_install_ptk(struct wpa_sm *sm) } //now only use keyentry 0 for pairwise key - sm->key_entry_valid = 5; + sm->key_entry_valid = esp_wifi_get_sta_hw_key_idx_internal(0); //KEY_IDX_STA_PTK if (wpa_sm_set_key(&(sm->install_ptk), alg, sm->bssid, 0, 1, (sm->install_ptk).seq, WPA_KEY_RSC_LEN, (u8 *) sm->ptk.tk1, keylen,sm->key_entry_valid) < 0) { @@ -808,7 +808,7 @@ int wpa_supplicant_install_gtk(struct wpa_sm *sm, _gtk = gtk_buf; } //now only use keycache entry1 for group key - sm->key_entry_valid = gd->keyidx; + sm->key_entry_valid = esp_wifi_get_sta_hw_key_idx_internal(gd->keyidx); if (sm->pairwise_cipher == WPA_CIPHER_NONE) { if (wpa_sm_set_key(&(sm->install_gtk), gd->alg, sm->bssid, //(u8 *) "\xff\xff\xff\xff\xff\xff",