From b96b76fc107816c84e9bc119d11e84f7d75cabb4 Mon Sep 17 00:00:00 2001 From: "alex.li" Date: Mon, 11 Oct 2021 13:54:54 +0800 Subject: [PATCH 1/3] esp_wifi: Support external coex only for esp32c3/esp32s2.(c1a3efe0) --- components/esp_wifi/lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 6f9d2a1185..049fbb7f22 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 6f9d2a11850b9fc0d4fd4ce89c492129e06fd77c +Subproject commit 049fbb7f22962fc4e2316e732ad08fc95b14149f From 26d8b7ee178a3e913f2c5f3c97c88b1403a24e62 Mon Sep 17 00:00:00 2001 From: "alex.li" Date: Mon, 18 Jan 2021 15:55:14 +0800 Subject: [PATCH 2/3] Add HW external coexist api. Simplify the external coex flow. And replace gpio of driver interface with hal one. --- components/esp_system/startup.c | 2 +- components/esp_wifi/Kconfig | 12 +++ components/esp_wifi/esp32c3/esp_adapter.c | 38 ++++---- components/esp_wifi/esp32s2/esp_adapter.c | 73 ++++++++++---- components/esp_wifi/include/esp_coexist.h | 67 ++++++++++--- .../esp_wifi/include/esp_coexist_internal.h | 42 +++++--- components/esp_wifi/sdkconfig.rename | 1 + components/esp_wifi/src/coexist.c | 96 +++++++++++++++++++ components/esp_wifi/src/wifi_init.c | 2 +- components/soc/esp32s2/include/soc/soc_caps.h | 2 + examples/wifi/iperf/main/cmd_wifi.c | 11 +++ tools/ci/check_copyright_ignore.txt | 2 - 12 files changed, 281 insertions(+), 67 deletions(-) diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index ddf6c82b77..66edbccf4d 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -474,7 +474,7 @@ IRAM_ATTR ESP_SYSTEM_INIT_FN(init_components0, BIT(0)) esp_apb_backup_dma_lock_init(); #endif -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE esp_coex_adapter_register(&g_coex_adapter_funcs); coex_pre_init(); #endif diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 35f76ff95e..7d20d8f451 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -300,4 +300,16 @@ menu "Wi-Fi" Select this option to enable power_management for station when disconnected. Chip will do modem-sleep when rf module is not in use any more. + config ESP_WIFI_EXTERNAL_COEXIST_ENABLE + bool "WiFi External Coexistence" + default n + depends on (!BT_ENABLED && (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3)) + help + If enabled, HW External coexistence arbitration is managed by GPIO pins. + It can support three types of wired combinations so far which are 1-wired/2-wired/3-wired. + User can select GPIO pins in application code with configure interfaces. + + This function depends on BT-off + because currently we don't support external coex and internal coex simultaneously. + endmenu # Wi-Fi diff --git a/components/esp_wifi/esp32c3/esp_adapter.c b/components/esp_wifi/esp32c3/esp_adapter.c index f00466c862..c0ff97f841 100644 --- a/components/esp_wifi/esp32c3/esp_adapter.c +++ b/components/esp_wifi/esp32c3/esp_adapter.c @@ -489,7 +489,7 @@ static esp_err_t esp_read_mac_wrapper(uint8_t* mac, uint32_t type) static int coex_init_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_init(); #else return 0; @@ -498,14 +498,14 @@ static int coex_init_wrapper(void) static void coex_deinit_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE coex_deinit(); #endif } static int coex_enable_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_enable(); #else return 0; @@ -514,14 +514,14 @@ static int coex_enable_wrapper(void) static void coex_disable_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE coex_disable(); #endif } static IRAM_ATTR uint32_t coex_status_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_status_get(); #else return 0; @@ -530,14 +530,14 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void) static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE coex_condition_set(type, dissatisfy); #endif } static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_request(event, latency, duration); #else return 0; @@ -546,7 +546,7 @@ static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_release(event); #else return 0; @@ -555,7 +555,7 @@ static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_channel_set(primary, secondary); #else return 0; @@ -564,7 +564,7 @@ static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_event_duration_get(event, duration); #else return 0; @@ -573,7 +573,7 @@ static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *d static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_pti_get(event, pti); #else return 0; @@ -582,21 +582,21 @@ static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_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 +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_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 +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_interval_set(interval); #else return 0; @@ -605,7 +605,7 @@ static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_interval_get(); #else return 0; @@ -614,7 +614,7 @@ static uint32_t coex_schm_interval_get_wrapper(void) static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_period_get(); #else return 0; @@ -623,7 +623,7 @@ static uint8_t coex_schm_curr_period_get_wrapper(void) static void * coex_schm_curr_phase_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_get(); #else return NULL; @@ -632,7 +632,7 @@ static void * coex_schm_curr_phase_get_wrapper(void) static int coex_schm_curr_phase_idx_set_wrapper(int idx) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_idx_set(idx); #else return 0; @@ -641,7 +641,7 @@ static int coex_schm_curr_phase_idx_set_wrapper(int idx) static int coex_schm_curr_phase_idx_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_idx_get(); #else return 0; diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 59f1ffda2d..049b2f4588 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -48,6 +48,8 @@ #include "nvs.h" #include "os.h" #include "esp_smartconfig.h" +#include "esp_coexist_internal.h" +#include "esp_coexist_adapter.h" #define TAG "esp_adapter" @@ -277,6 +279,16 @@ 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) { @@ -483,7 +495,7 @@ static void * IRAM_ATTR zalloc_internal_wrapper(size_t size) static int coex_init_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_init(); #else return 0; @@ -492,14 +504,14 @@ static int coex_init_wrapper(void) static void coex_deinit_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE coex_deinit(); #endif } static int coex_enable_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_enable(); #else return 0; @@ -508,14 +520,14 @@ static int coex_enable_wrapper(void) static void coex_disable_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE coex_disable(); #endif } static IRAM_ATTR uint32_t coex_status_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_status_get(); #else return 0; @@ -524,14 +536,14 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void) static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE coex_condition_set(type, dissatisfy); #endif } static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_request(event, latency, duration); #else return 0; @@ -540,7 +552,7 @@ static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_release(event); #else return 0; @@ -549,7 +561,7 @@ static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_wifi_channel_set(primary, secondary); #else return 0; @@ -558,7 +570,7 @@ static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_event_duration_get(event, duration); #else return 0; @@ -567,26 +579,30 @@ static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *d static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) { +#if CONFIG_EXTERNAL_COEX_ENABLE + return coex_pti_get(event, pti); +#else return 0; +#endif } static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_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 +#if CONFIG_EXTERNAL_COEX_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 +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_interval_set(interval); #else return 0; @@ -595,7 +611,7 @@ static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) static uint32_t coex_schm_interval_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_interval_get(); #else return 0; @@ -604,7 +620,7 @@ static uint32_t coex_schm_interval_get_wrapper(void) static uint8_t coex_schm_curr_period_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_period_get(); #else return 0; @@ -613,7 +629,7 @@ static uint8_t coex_schm_curr_period_get_wrapper(void) static void * coex_schm_curr_phase_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_get(); #else return NULL; @@ -622,7 +638,7 @@ static void * coex_schm_curr_phase_get_wrapper(void) static int coex_schm_curr_phase_idx_set_wrapper(int idx) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_idx_set(idx); #else return 0; @@ -631,7 +647,7 @@ static int coex_schm_curr_phase_idx_set_wrapper(int idx) static int coex_schm_curr_phase_idx_get_wrapper(void) { -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_EXTERNAL_COEX_ENABLE return coex_schm_curr_phase_idx_get(); #else return 0; @@ -643,6 +659,11 @@ static void IRAM_ATTR esp_empty_wrapper(void) } +int32_t IRAM_ATTR coex_is_in_isr_wrapper(void) +{ + return !xPortCanYield(); +} + wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, ._env_is_chip = env_is_chip_wrapper, @@ -761,3 +782,19 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._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, + ._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 = coex_is_in_isr_wrapper, + ._malloc_internal = malloc_internal_wrapper, + ._free = free, + ._esp_timer_get_time = esp_timer_get_time, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_wifi/include/esp_coexist.h b/components/esp_wifi/include/esp_coexist.h index 1ff624d9b5..14b7c9aa50 100644 --- a/components/esp_wifi/include/esp_coexist.h +++ b/components/esp_wifi/include/esp_coexist.h @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_COEXIST_H__ #define __ESP_COEXIST_H__ @@ -32,6 +24,13 @@ typedef enum { ESP_COEX_PREFER_NUM, /*!< Prefer value numbers */ } esp_coex_prefer_t; +typedef enum { + EXTERN_COEX_WIRE_1 = 0, + EXTERN_COEX_WIRE_2, + EXTERN_COEX_WIRE_3, + EXTERN_COEX_WIRE_NUM, +} external_coex_wire_t; + /** * @brief coex status type */ @@ -41,6 +40,36 @@ typedef enum { ESP_COEX_ST_TYPE_BT, } esp_coex_status_type_t; +/** + * @brief external coex gpio pti + */ +typedef struct { + int32_t in_pin0; + int32_t in_pin1; + int32_t out_pin0; +} esp_external_coex_gpio_set_t; + +/** + * @brief external coex pti level + */ +typedef enum { + EXTERN_COEX_PTI_MID = 0, + EXTERN_COEX_PTI_HIGH, + EXTERN_COEX_PTI_NUM, +} esp_coex_pti_level_t; + +/** + * @brief external coex pti + */ +typedef struct { + uint32_t in_pti1; + uint32_t in_pti2; + uint32_t in_pti3; + uint32_t out_pti1; + uint32_t out_pti2; + uint32_t out_pti3; +} esp_external_coex_pti_set_t; + #define ESP_COEX_BLE_ST_MESH_CONFIG 0x08 #define ESP_COEX_BLE_ST_MESH_TRAFFIC 0x10 #define ESP_COEX_BLE_ST_MESH_STANDBY 0x20 @@ -84,6 +113,18 @@ esp_err_t esp_coex_status_bit_set(esp_coex_status_type_t type, uint32_t status); */ esp_err_t esp_coex_status_bit_clear(esp_coex_status_type_t type, uint32_t status); +#if CONFIG_EXTERNAL_COEX_ENABLE +/** + * @brief Setup gpio pin and corresponding pti level, start external coex. + * @param wire_type : to select the whole external coex gpio number. + * @param gpio_pin : gpio pin number to choose. + * @return : ESP_OK - success, other - failed + */ +esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, + esp_external_coex_gpio_set_t gpio_pin); + +esp_err_t esp_disable_extern_coex_gpio_pin(); +#endif #ifdef __cplusplus } diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_wifi/include/esp_coexist_internal.h index 3501f0da6f..7ba06d4c69 100644 --- a/components/esp_wifi/include/esp_coexist_internal.h +++ b/components/esp_wifi/include/esp_coexist_internal.h @@ -1,21 +1,14 @@ -// Copyright 2018-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef __ESP_COEXIST_INTERNAL_H__ #define __ESP_COEXIST_INTERNAL_H__ #include +#include "esp_coexist.h" #include "esp_coexist_adapter.h" #ifdef __cplusplus @@ -210,6 +203,29 @@ int coex_schm_curr_phase_idx_get(void); */ esp_err_t esp_coex_adapter_register(coex_adapter_funcs_t *funcs); +#if CONFIG_EXTERNAL_COEX_ENABLE +/** + * @brief Set external coexistence pti level and enable it. + * + * @param level1 external coex low pti + * @param level2 external coex mid pti + * @param level3 external coex high pti + * + * @return + * - ESP_OK: succeed + */ +esp_err_t esp_coex_external_set(esp_coex_pti_level_t level1, + esp_coex_pti_level_t level2, esp_coex_pti_level_t level3); + +/** + * @brief Disable external coexist + * + * @return + * - ESP_OK: succeed + */ +void esp_coex_external_stop(void); +#endif /*External Coex*/ + /** * @brief Check the MD5 values of the coexistence adapter header files in IDF and WiFi library * diff --git a/components/esp_wifi/sdkconfig.rename b/components/esp_wifi/sdkconfig.rename index 8d55abed31..61b2e5fafd 100644 --- a/components/esp_wifi/sdkconfig.rename +++ b/components/esp_wifi/sdkconfig.rename @@ -2,3 +2,4 @@ # CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION CONFIG_SW_COEXIST_ENABLE CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE +CONFIG_EXTERNAL_COEX_ENABLE CONFIG_ESP_WIFI_EXTERNAL_COEXIST_ENABLE diff --git a/components/esp_wifi/src/coexist.c b/components/esp_wifi/src/coexist.c index 6282699427..bbfbdfa718 100644 --- a/components/esp_wifi/src/coexist.c +++ b/components/esp_wifi/src/coexist.c @@ -15,6 +15,14 @@ #include "esp_coexist.h" #include "esp_coexist_internal.h" +#if CONFIG_EXTERNAL_COEX_ENABLE +#include "driver/gpio.h" +#include "esp_rom_gpio.h" +#include "hal/gpio_hal.h" +#include "hal/gpio_types.h" +#include "soc/gpio_periph.h" +#endif + const char *esp_coex_version_get(void) { return coex_version_get(); @@ -24,3 +32,91 @@ esp_err_t esp_coex_preference_set(esp_coex_prefer_t prefer) { return coex_preference_set((coex_prefer_t)prefer); } + +#if CONFIG_EXTERNAL_COEX_ENABLE +#define GPIO_PIN_REG(a) (GPIO_PIN0_REG + a * 0x04) +esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, esp_external_coex_gpio_set_t gpio_pin) +{ + switch (wire_type) + { + case EXTERN_COEX_WIRE_3: + { + /*Input gpio pin setup --> GPIO_BT_PRIORITY_IDX:GPIO_BT_ACTIVE_IDX*/ + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.in_pin0], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.in_pin0, GPIO_MODE_INPUT); + esp_rom_gpio_connect_in_signal(gpio_pin.in_pin0, GPIO_BT_ACTIVE_IDX, false); + + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.in_pin1], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.in_pin1, GPIO_MODE_INPUT); + esp_rom_gpio_connect_in_signal(gpio_pin.in_pin1, GPIO_BT_PRIORITY_IDX, false); + + /*Output gpio pin setup --> GPIO_WLAN_ACTIVE_IDX: 1 BT, 0 WiFi*/ + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.out_pin0], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.out_pin0, GPIO_MODE_OUTPUT); + REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.out_pin0)); + esp_rom_gpio_connect_out_signal(gpio_pin.out_pin0, GPIO_WLAN_ACTIVE_IDX, false, false); + + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC1_BYPASS, 2); + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC2_BYPASS, 2); + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin1), GPIO_PIN1_SYNC1_BYPASS, 2); + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin1), GPIO_PIN1_SYNC2_BYPASS, 2); + + int ret = esp_coex_external_set(EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_HIGH); + if (ESP_OK != ret) { + return ESP_FAIL; + } + break; + } + case EXTERN_COEX_WIRE_2: + { + /*Input gpio pin setup --> GPIO_BT_PRIORITY_IDX:GPIO_BT_ACTIVE_IDX*/ + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.in_pin0], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.in_pin0, GPIO_MODE_INPUT); + esp_rom_gpio_connect_in_signal(gpio_pin.in_pin0, GPIO_BT_ACTIVE_IDX, false); + + /*Output gpio pin setup --> GPIO_WLAN_ACTIVE_IDX: 1 BT, 0 WiFi*/ + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.out_pin0], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.out_pin0, GPIO_MODE_OUTPUT); + REG_WRITE(GPIO_ENABLE_W1TC_REG, BIT(gpio_pin.out_pin0)); + esp_rom_gpio_connect_out_signal(gpio_pin.out_pin0, GPIO_WLAN_ACTIVE_IDX, false, false); + + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC1_BYPASS, 2); + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC2_BYPASS, 2); + + int ret = esp_coex_external_set(EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_MID, EXTERN_COEX_PTI_MID); + if (ESP_OK != ret) { + return ESP_FAIL; + } + break; + } + case EXTERN_COEX_WIRE_1: + { + /*Input gpio pin setup --> GPIO_BT_PRIORITY_IDX:GPIO_BT_ACTIVE_IDX*/ + gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[gpio_pin.in_pin0], PIN_FUNC_GPIO); + gpio_set_direction(gpio_pin.in_pin0, GPIO_MODE_INPUT); + esp_rom_gpio_connect_in_signal(gpio_pin.in_pin0, GPIO_BT_ACTIVE_IDX, false); + + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC1_BYPASS, 2); + REG_SET_FIELD(GPIO_PIN_REG(gpio_pin.in_pin0), GPIO_PIN1_SYNC2_BYPASS, 2); + + int ret = esp_coex_external_set(EXTERN_COEX_PTI_HIGH, EXTERN_COEX_PTI_HIGH, EXTERN_COEX_PTI_HIGH); + if (ESP_OK != ret) { + return ESP_FAIL; + } + break; + } + default: + { + return ESP_FAIL; + } + } + return ESP_OK; +} + +esp_err_t esp_disable_extern_coex_gpio_pin() +{ + esp_coex_external_stop(); + + return ESP_OK; +} +#endif/*External Coex*/ diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 04fe932331..784fca6489 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -237,7 +237,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) ESP_LOGW(TAG, "Failed to set default Wi-Fi event handlers (0x%x)", err); } #endif -#if CONFIG_SW_COEXIST_ENABLE +#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE coex_init(); #endif esp_wifi_set_log_level(); diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index e039fd969a..620c5dc9ac 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -332,5 +332,7 @@ #define SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP (1) /*! Date: Thu, 30 Sep 2021 15:12:55 +0800 Subject: [PATCH 3/3] pre-commit fix --- components/esp_system/startup.c | 18 +++++------------- components/esp_wifi/esp32c3/esp_adapter.c | 18 +++++------------- components/esp_wifi/esp32s2/esp_adapter.c | 18 +++++------------- components/esp_wifi/src/coexist.c | 18 +++++------------- components/esp_wifi/src/wifi_init.c | 18 +++++------------- tools/ci/check_copyright_ignore.txt | 5 ----- 6 files changed, 25 insertions(+), 70 deletions(-) diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 66edbccf4d..e977be4c26 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/esp_wifi/esp32c3/esp_adapter.c b/components/esp_wifi/esp32c3/esp_adapter.c index c0ff97f841..9394f3cc55 100644 --- a/components/esp_wifi/esp32c3/esp_adapter.c +++ b/components/esp_wifi/esp32c3/esp_adapter.c @@ -1,16 +1,8 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 049b2f4588..0b7bfa3556 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -1,16 +1,8 @@ -// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/esp_wifi/src/coexist.c b/components/esp_wifi/src/coexist.c index bbfbdfa718..b0509d4570 100644 --- a/components/esp_wifi/src/coexist.c +++ b/components/esp_wifi/src/coexist.c @@ -1,16 +1,8 @@ -// Copyright 2018-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "esp_coexist.h" #include "esp_coexist_internal.h" diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 784fca6489..f8ec7fbcca 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -1,16 +1,8 @@ -// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index d1089a1256..2a5fa2434b 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1178,7 +1178,6 @@ components/esp_system/port/soc/esp32s3/reset_reason.c components/esp_system/port/soc/esp32s3/system_internal.c components/esp_system/port/soc/esp32s3/usb_console.c components/esp_system/stack_check.c -components/esp_system/startup.c components/esp_system/system_time.c components/esp_system/task_wdt.c components/esp_system/test/test_delay.c @@ -1207,8 +1206,6 @@ components/esp_websocket_client/esp_websocket_client.c components/esp_websocket_client/include/esp_websocket_client.h components/esp_websocket_client/test/test_websocket_client.c components/esp_wifi/esp32/esp_adapter.c -components/esp_wifi/esp32c3/esp_adapter.c -components/esp_wifi/esp32s2/esp_adapter.c components/esp_wifi/esp32s3/esp_adapter.c components/esp_wifi/include/esp_coexist_adapter.h components/esp_wifi/include/esp_mesh.h @@ -1225,13 +1222,11 @@ components/esp_wifi/include/esp_wifi_crypto_types.h components/esp_wifi/include/esp_wifi_default.h components/esp_wifi/include/esp_wifi_netif.h components/esp_wifi/include/smartconfig_ack.h -components/esp_wifi/src/coexist.c components/esp_wifi/src/lib_printf.c components/esp_wifi/src/mesh_event.c components/esp_wifi/src/smartconfig.c components/esp_wifi/src/smartconfig_ack.c components/esp_wifi/src/wifi_default.c -components/esp_wifi/src/wifi_init.c components/esp_wifi/src/wifi_netif.c components/esp_wifi/test/test_wifi.c components/esp_wifi/test/test_wifi_init.c