From 38316b38b5b37392efae6eb9cb3e1c11d13cd492 Mon Sep 17 00:00:00 2001 From: liuning Date: Wed, 14 Dec 2022 17:10:54 +0800 Subject: [PATCH] esp_wifi: move coex part from esp_wifi to esp_coex --- .gitlab/ci/pre_check.yml | 7 +- .gitlab/ci/rules.yml | 1 + .gitmodules | 4 + components/bt/CMakeLists.txt | 2 +- components/esp_coex/CMakeLists.txt | 46 ++++ components/esp_coex/Kconfig | 29 +++ components/esp_coex/esp32/esp_coex_adapter.c | 196 ++++++++++++++++++ .../esp_coex/esp32c2/esp_coex_adapter.c | 131 ++++++++++++ .../esp_coex/esp32c3/esp_coex_adapter.c | 110 ++++++++++ .../esp_coex/esp32s2/esp_coex_adapter.c | 160 ++++++++++++++ .../esp_coex/esp32s3/esp_coex_adapter.c | 160 ++++++++++++++ .../include/esp_coexist.h | 0 .../include/esp_coexist_adapter.h | 0 .../include/esp_coexist_internal.h | 0 .../esp_coex/include/esp_modem_wrapper.h | 78 +++++++ components/esp_coex/lib | 1 + components/esp_coex/linker.lf | 5 + .../{esp_wifi => esp_coex}/sdkconfig.rename | 0 .../{esp_wifi => esp_coex}/src/coexist.c | 0 components/esp_coex/test_md5/test_md5.sh | 66 ++++++ components/esp_phy/src/phy_init.c | 1 - components/esp_system/CMakeLists.txt | 2 +- components/esp_wifi/CMakeLists.txt | 7 +- components/esp_wifi/Kconfig | 24 --- components/esp_wifi/esp32/esp_adapter.c | 169 +-------------- components/esp_wifi/esp32c2/esp_adapter.c | 105 +--------- components/esp_wifi/esp32c3/esp_adapter.c | 86 +------- components/esp_wifi/esp32s2/esp_adapter.c | 131 +----------- components/esp_wifi/esp32s3/esp_adapter.c | 131 +----------- components/esp_wifi/linker.lf | 6 - components/esp_wifi/test_md5/test_md5.sh | 2 - tools/ci/check_public_headers_exceptions.txt | 4 +- tools/ci/executable-list.txt | 1 + 33 files changed, 1006 insertions(+), 659 deletions(-) create mode 100644 components/esp_coex/CMakeLists.txt create mode 100644 components/esp_coex/Kconfig create mode 100644 components/esp_coex/esp32/esp_coex_adapter.c create mode 100644 components/esp_coex/esp32c2/esp_coex_adapter.c create mode 100644 components/esp_coex/esp32c3/esp_coex_adapter.c create mode 100644 components/esp_coex/esp32s2/esp_coex_adapter.c create mode 100644 components/esp_coex/esp32s3/esp_coex_adapter.c rename components/{esp_wifi => esp_coex}/include/esp_coexist.h (100%) rename components/{esp_wifi => esp_coex}/include/esp_coexist_adapter.h (100%) rename components/{esp_wifi => esp_coex}/include/esp_coexist_internal.h (100%) create mode 100644 components/esp_coex/include/esp_modem_wrapper.h create mode 160000 components/esp_coex/lib create mode 100644 components/esp_coex/linker.lf rename components/{esp_wifi => esp_coex}/sdkconfig.rename (100%) rename components/{esp_wifi => esp_coex}/src/coexist.c (100%) create mode 100755 components/esp_coex/test_md5/test_md5.sh diff --git a/.gitlab/ci/pre_check.yml b/.gitlab/ci/pre_check.yml index 1df0ed62d0..df697a8699 100644 --- a/.gitlab/ci/pre_check.yml +++ b/.gitlab/ci/pre_check.yml @@ -77,13 +77,18 @@ test_check_kconfigs: check_blobs: extends: .pre_check_template variables: - SUBMODULES_TO_FETCH: "components/esp_wifi/lib;components/esp_phy/lib" + SUBMODULES_TO_FETCH: "components/esp_wifi/lib;components/esp_phy/lib;components/esp_coex/lib" script: # Check if Wi-Fi library header files match between IDF and the version used when compiling the libraries - IDF_TARGET=esp32 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh - IDF_TARGET=esp32s2 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh - IDF_TARGET=esp32s3 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh - IDF_TARGET=esp32c3 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh + # Check if Coexistence library header files match between IDF and the version used when compiling the libraries + - IDF_TARGET=esp32 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh + - IDF_TARGET=esp32s2 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh + - IDF_TARGET=esp32s3 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh + - IDF_TARGET=esp32c3 $IDF_PATH/components/esp_coex/test_md5/test_md5.sh # Check if Wi-Fi, PHY, BT blobs contain references to specific symbols - bash $IDF_PATH/tools/ci/check_blobs.sh diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index 6c115428af..f60d97973d 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -183,6 +183,7 @@ - "components/cmock/CMock" - "components/esp_phy/lib" - "components/esp_wifi/lib" + - "components/esp_coex/lib" - "components/ieee802154/lib" - "components/json/cJSON" - "components/lwip/lwip" diff --git a/.gitmodules b/.gitmodules index d162ff483e..b3b9edd1be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -86,3 +86,7 @@ [submodule "components/heap/tlsf"] path = components/heap/tlsf url = ../../espressif/tlsf.git + +[submodule "components/esp_coex/lib"] + path = components/esp_coex/lib + url = ../../espressif/esp-coex-lib.git diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index a51b78b951..e6f14e925a 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -691,7 +691,7 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" PRIV_INCLUDE_DIRS "${priv_include_dirs}" - REQUIRES esp_timer esp_wifi + REQUIRES esp_timer esp_wifi esp_coex PRIV_REQUIRES nvs_flash soc esp_pm esp_phy mbedtls driver vfs LDFRAGMENTS "linker.lf") diff --git a/components/esp_coex/CMakeLists.txt b/components/esp_coex/CMakeLists.txt new file mode 100644 index 0000000000..053068b1b8 --- /dev/null +++ b/components/esp_coex/CMakeLists.txt @@ -0,0 +1,46 @@ +idf_build_get_property(idf_target IDF_TARGET) + +if(CONFIG_SW_COEXIST_ENABLE OR CONFIG_EXTERNAL_COEX_ENABLE) + if(CONFIG_APP_NO_BLOBS) + set(link_binary_libs 0) + set(ldfragments) + else() + set(link_binary_libs 1) + set(ldfragments "linker.lf") + endif() + + set(srcs + "src/coexist.c" + "${idf_target}/esp_coex_adapter.c") +endif() + +if(CONFIG_ESP32_WIFI_ENABLED) + list(APPEND srcs "${idf_target}/esp_coex_adapter.c") +endif() + +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS "include" + PRIV_REQUIRES esp_timer driver + LDFRAGMENTS "${ldfragments}") + +if(CONFIG_SW_COEXIST_ENABLE OR CONFIG_EXTERNAL_COEX_ENABLE) + idf_build_get_property(build_dir BUILD_DIR) + + set(target_name "${idf_target}") + target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") + + if(link_binary_libs) + set(blobs coexist) + + foreach(blob ${blobs}) + add_prebuilt_library(${blob} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib${blob}.a" + REQUIRES ${COMPONENT_NAME}) + set(blob_reqs ${blobs}) + list(REMOVE_ITEM blob_reqs ${blob}) # remove itself from requirements + set_property(TARGET ${blob} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${blob_reqs}) + target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob}) + endforeach() + endif() + + target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") +endif() diff --git a/components/esp_coex/Kconfig b/components/esp_coex/Kconfig new file mode 100644 index 0000000000..894a77df76 --- /dev/null +++ b/components/esp_coex/Kconfig @@ -0,0 +1,29 @@ + +menu "ESP-COEX" + visible if !IDF_TARGET_ESP32H4 + + config ESP_WIFI_SW_COEXIST_ENABLE + bool "Software controls WiFi/Bluetooth coexistence" + depends on ESP_WIFI_ENABLED && BT_ENABLED + default y + select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE + help + If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware. + Recommended for heavy traffic scenarios. Both coexistence configuration options are + automatically managed, no user intervention is required. + If only Bluetooth is used, it is recommended to disable this option to reduce binary file + size. + + config ESP_WIFI_EXTERNAL_COEXIST_ENABLE + bool "WiFi External Coexistence" + default n + depends on (!(BT_ENABLED||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32)) + 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 do not support external coex and internal coex simultaneously. + +endmenu # Wi-Fi diff --git a/components/esp_coex/esp32/esp_coex_adapter.c b/components/esp_coex/esp32/esp_coex_adapter.c new file mode 100644 index 0000000000..4053565d78 --- /dev/null +++ b/components/esp_coex/esp32/esp_coex_adapter.c @@ -0,0 +1,196 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/portmacro.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_coexist_adapter.h" +#include "esp32/rom/ets_sys.h" + +#define TAG "esp_coex_adapter" + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +typedef struct { + QueueHandle_t handle; /**< FreeRTOS queue handler */ + void *storage; /**< storage for FreeRTOS queue */ +} modem_static_queue_t; + +void * spin_lock_create_wrapper(void) +{ + portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED; + void *mux = heap_caps_malloc(sizeof(portMUX_TYPE), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + + if (mux) { + memcpy(mux,&tmp,sizeof(portMUX_TYPE)); + return mux; + } + return NULL; +} + +uint32_t IRAM_ATTR wifi_int_disable_wrapper(void *wifi_int_mux) +{ + if (xPortInIsrContext()) { + portENTER_CRITICAL_ISR(wifi_int_mux); + } else { + portENTER_CRITICAL(wifi_int_mux); + } + + return 0; +} + +void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) +{ + if (xPortInIsrContext()) { + portEXIT_CRITICAL_ISR(wifi_int_mux); + } else { + portEXIT_CRITICAL(wifi_int_mux); + } +} + +void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) +{ + modem_static_queue_t *semphr = heap_caps_calloc(1, sizeof(modem_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr) { + return NULL; + } + +#ifdef CONFIG_SPIRAM_USE_MALLOC + semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr->storage) { + goto _error; + } + + semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); + if (!semphr->handle) { + goto _error; + } + return (void *)semphr; + +_error: + if (semphr) { + if (semphr->storage) { + free(semphr->storage); + } + + free(semphr); + } + return NULL; +#else + semphr->handle = xSemaphoreCreateCounting(max, init); + return (void *)semphr; +#endif +} + +void internal_semphr_delete_wrapper(void *semphr) +{ + modem_static_queue_t *semphr_item = (modem_static_queue_t *)semphr; + if (semphr_item) { + if (semphr_item->handle) { + vSemaphoreDelete(semphr_item->handle); + } +#ifdef CONFIG_SPIRAM_USE_MALLOC + if (semphr_item->storage) { + free(semphr_item->storage); + } +#endif + free(semphr_item); + } +} + +int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, block_time_tick); + } +} + +int32_t internal_semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(((modem_static_queue_t *)semphr)->handle); +} + +void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +int IRAM_ATTR coex_is_in_isr_wrapper(void) +{ + return !xPortCanYield(); +} + +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 = internal_semphr_create_wrapper, + ._semphr_delete = internal_semphr_delete_wrapper, + ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, + ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, + ._semphr_take = internal_semphr_take_wrapper, + ._semphr_give = internal_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, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_coex/esp32c2/esp_coex_adapter.c b/components/esp_coex/esp32c2/esp_coex_adapter.c new file mode 100644 index 0000000000..218f72cf07 --- /dev/null +++ b/components/esp_coex/esp32c2/esp_coex_adapter.c @@ -0,0 +1,131 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/portmacro.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "soc/rtc.h" +#include "esp_private/esp_clk.h" +#include "esp_coexist_adapter.h" +#include "esp32c2/rom/ets_sys.h" + +#define TAG "esp_coex_adapter" + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +bool IRAM_ATTR env_is_chip_wrapper(void) +{ +#ifdef CONFIG_IDF_ENV_FPGA + return false; +#else + return true; +#endif +} + +void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void * semphr_create_wrapper(uint32_t max, uint32_t init) +{ + return (void *)xSemaphoreCreateCounting(max, init); +} + +void semphr_delete_wrapper(void *semphr) +{ + vSemaphoreDelete(semphr); +} + +int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(semphr, hptw); +} + +int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(semphr, hptw); +} + +int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(semphr, block_time_tick); + } +} + +int32_t semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(semphr); +} + +void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +uint32_t esp_clk_slowclk_cal_get_wrapper(void) +{ + /* The bit width of WiFi light sleep clock calibration is 12 while the one of + * system is 19. It should shift 19 - 12 = 7. + */ + return (esp_clk_slowclk_cal_get() >> (RTC_CLK_CAL_FRACT - SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH)); +} + +void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +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 = xPortInIsrContext, + ._malloc_internal = malloc_internal_wrapper, + ._free = free, + ._esp_timer_get_time = esp_timer_get_time, + ._env_is_chip = env_is_chip_wrapper, + ._slowclk_cal_get = esp_clk_slowclk_cal_get_wrapper, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_coex/esp32c3/esp_coex_adapter.c b/components/esp_coex/esp32c3/esp_coex_adapter.c new file mode 100644 index 0000000000..a64ba30ab7 --- /dev/null +++ b/components/esp_coex/esp32c3/esp_coex_adapter.c @@ -0,0 +1,110 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/portmacro.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_coexist_adapter.h" +#include "esp32c3/rom/ets_sys.h" + +#define TAG "esp_coex_adapter" + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void * semphr_create_wrapper(uint32_t max, uint32_t init) +{ + return (void *)xSemaphoreCreateCounting(max, init); +} + +void semphr_delete_wrapper(void *semphr) +{ + vSemaphoreDelete(semphr); +} + +int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(semphr, hptw); +} + +int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(semphr, hptw); +} + +int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(semphr, block_time_tick); + } +} + +int32_t semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(semphr); +} + +void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +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 = xPortInIsrContext, + ._malloc_internal = malloc_internal_wrapper, + ._free = free, + ._esp_timer_get_time = esp_timer_get_time, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_coex/esp32s2/esp_coex_adapter.c b/components/esp_coex/esp32s2/esp_coex_adapter.c new file mode 100644 index 0000000000..10e2176be6 --- /dev/null +++ b/components/esp_coex/esp32s2/esp_coex_adapter.c @@ -0,0 +1,160 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/portmacro.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_coexist_adapter.h" +#include "esp32s2/rom/ets_sys.h" + +#define TAG "esp_coex_adapter" + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +typedef struct { + QueueHandle_t handle; /**< FreeRTOS queue handler */ + void *storage; /**< storage for FreeRTOS queue */ +} modem_static_queue_t; + +void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) +{ + modem_static_queue_t *semphr = heap_caps_calloc(1, sizeof(modem_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr) { + return NULL; + } + +#ifdef CONFIG_SPIRAM_USE_MALLOC + semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr->storage) { + goto _error; + } + + semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); + if (!semphr->handle) { + goto _error; + } + return (void *)semphr; + +_error: + if (semphr) { + if (semphr->storage) { + free(semphr->storage); + } + + free(semphr); + } + return NULL; +#else + semphr->handle = xSemaphoreCreateCounting(max, init); + return (void *)semphr; +#endif +} + +void internal_semphr_delete_wrapper(void *semphr) +{ + modem_static_queue_t *semphr_item = (modem_static_queue_t *)semphr; + if (semphr_item) { + if (semphr_item->handle) { + vSemaphoreDelete(semphr_item->handle); + } +#ifdef CONFIG_SPIRAM_USE_MALLOC + if (semphr_item->storage) { + free(semphr_item->storage); + } +#endif + free(semphr_item); + } +} + +int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, block_time_tick); + } +} + +int32_t internal_semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(((modem_static_queue_t *)semphr)->handle); +} + +void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +int IRAM_ATTR coex_is_in_isr_wrapper(void) +{ + return !xPortCanYield(); +} + +coex_adapter_funcs_t g_coex_adapter_funcs = { + ._version = COEX_ADAPTER_VERSION, + ._task_yield_from_isr = task_yield_from_isr_wrapper, + ._semphr_create = internal_semphr_create_wrapper, + ._semphr_delete = internal_semphr_delete_wrapper, + ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, + ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, + ._semphr_take = internal_semphr_take_wrapper, + ._semphr_give = internal_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, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_coex/esp32s3/esp_coex_adapter.c b/components/esp_coex/esp32s3/esp_coex_adapter.c new file mode 100644 index 0000000000..7182d1f763 --- /dev/null +++ b/components/esp_coex/esp32s3/esp_coex_adapter.c @@ -0,0 +1,160 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/portmacro.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_coexist_adapter.h" +#include "esp32s3/rom/ets_sys.h" + +#define TAG "esp_coex_adapter" + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff + +typedef struct { + QueueHandle_t handle; /**< FreeRTOS queue handler */ + void *storage; /**< storage for FreeRTOS queue */ +} modem_static_queue_t; + +void IRAM_ATTR task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) +{ + modem_static_queue_t *semphr = heap_caps_calloc(1, sizeof(modem_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr) { + return NULL; + } + +#ifdef CONFIG_SPIRAM_USE_MALLOC + semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + if (!semphr->storage) { + goto _error; + } + + semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); + if (!semphr->handle) { + goto _error; + } + return (void *)semphr; + +_error: + if (semphr) { + if (semphr->storage) { + free(semphr->storage); + } + + free(semphr); + } + return NULL; +#else + semphr->handle = xSemaphoreCreateCounting(max, init); + return (void *)semphr; +#endif +} + +void internal_semphr_delete_wrapper(void *semphr) +{ + modem_static_queue_t *semphr_item = (modem_static_queue_t *)semphr; + if (semphr_item) { + if (semphr_item->handle) { + vSemaphoreDelete(semphr_item->handle); + } +#ifdef CONFIG_SPIRAM_USE_MALLOC + if (semphr_item->storage) { + free(semphr_item->storage); + } +#endif + free(semphr_item); + } +} + +int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreTakeFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) +{ + return (int32_t)xSemaphoreGiveFromISR(((modem_static_queue_t *)semphr)->handle, hptw); +} + +int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(((modem_static_queue_t *)semphr)->handle, block_time_tick); + } +} + +int32_t internal_semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(((modem_static_queue_t *)semphr)->handle); +} + +void IRAM_ATTR timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +void * IRAM_ATTR malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +int IRAM_ATTR coex_is_in_isr_wrapper(void) +{ + return !xPortCanYield(); +} + +coex_adapter_funcs_t g_coex_adapter_funcs = { + ._version = COEX_ADAPTER_VERSION, + ._task_yield_from_isr = task_yield_from_isr_wrapper, + ._semphr_create = internal_semphr_create_wrapper, + ._semphr_delete = internal_semphr_delete_wrapper, + ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, + ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, + ._semphr_take = internal_semphr_take_wrapper, + ._semphr_give = internal_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, + ._timer_disarm = timer_disarm_wrapper, + ._timer_done = timer_done_wrapper, + ._timer_setfn = timer_setfn_wrapper, + ._timer_arm_us = timer_arm_us_wrapper, + ._magic = COEX_ADAPTER_MAGIC, +}; diff --git a/components/esp_wifi/include/esp_coexist.h b/components/esp_coex/include/esp_coexist.h similarity index 100% rename from components/esp_wifi/include/esp_coexist.h rename to components/esp_coex/include/esp_coexist.h diff --git a/components/esp_wifi/include/esp_coexist_adapter.h b/components/esp_coex/include/esp_coexist_adapter.h similarity index 100% rename from components/esp_wifi/include/esp_coexist_adapter.h rename to components/esp_coex/include/esp_coexist_adapter.h diff --git a/components/esp_wifi/include/esp_coexist_internal.h b/components/esp_coex/include/esp_coexist_internal.h similarity index 100% rename from components/esp_wifi/include/esp_coexist_internal.h rename to components/esp_coex/include/esp_coexist_internal.h diff --git a/components/esp_coex/include/esp_modem_wrapper.h b/components/esp_coex/include/esp_modem_wrapper.h new file mode 100644 index 0000000000..c9277bdf9b --- /dev/null +++ b/components/esp_coex/include/esp_modem_wrapper.h @@ -0,0 +1,78 @@ +/* + * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ESP_MODEM_WRAPPER_INTERNAL_H__ +#define __ESP_MODEM_WRAPPER_INTERNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#ifdef CONFIG_IDF_TARGET_ESP32 +void * spin_lock_create_wrapper(void); + +uint32_t wifi_int_disable_wrapper(void *wifi_int_mux); + +void wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp); +#endif + +void task_yield_from_isr_wrapper(void); + +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + +void *internal_semphr_create_wrapper(uint32_t max, uint32_t init); + +void internal_semphr_delete_wrapper(void *semphr); + +int32_t internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw); + +int32_t internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw); + +int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick); + +int32_t internal_semphr_give_wrapper(void *semphr); + +#else + +void * semphr_create_wrapper(uint32_t max, uint32_t init); + +void semphr_delete_wrapper(void *semphr); + +int32_t semphr_take_from_isr_wrapper(void *semphr, void *hptw); + +int32_t semphr_give_from_isr_wrapper(void *semphr, void *hptw); + +int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick); + +int32_t semphr_give_wrapper(void *semphr); + +#endif + +void timer_disarm_wrapper(void *timer); + +void timer_done_wrapper(void *ptimer); + +void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg); + +void timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat); + +void * malloc_internal_wrapper(size_t size); + +#if CONFIG_IDF_TARGET_ESP32C2 +bool env_is_chip_wrapper(void); + +uint32_t esp_clk_slowclk_cal_get_wrapper(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/esp_coex/lib b/components/esp_coex/lib new file mode 160000 index 0000000000..22df5f0064 --- /dev/null +++ b/components/esp_coex/lib @@ -0,0 +1 @@ +Subproject commit 22df5f006409c215a6856c954eb3d32d19ec8fdc diff --git a/components/esp_coex/linker.lf b/components/esp_coex/linker.lf new file mode 100644 index 0000000000..89f1fd620d --- /dev/null +++ b/components/esp_coex/linker.lf @@ -0,0 +1,5 @@ +[mapping:coexist] +archive: libcoexist.a +entries: + if ESP_WIFI_SLP_IRAM_OPT = y: + * (wifi_slp_iram) diff --git a/components/esp_wifi/sdkconfig.rename b/components/esp_coex/sdkconfig.rename similarity index 100% rename from components/esp_wifi/sdkconfig.rename rename to components/esp_coex/sdkconfig.rename diff --git a/components/esp_wifi/src/coexist.c b/components/esp_coex/src/coexist.c similarity index 100% rename from components/esp_wifi/src/coexist.c rename to components/esp_coex/src/coexist.c diff --git a/components/esp_coex/test_md5/test_md5.sh b/components/esp_coex/test_md5/test_md5.sh new file mode 100755 index 0000000000..96874832d9 --- /dev/null +++ b/components/esp_coex/test_md5/test_md5.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ -z "${IDF_PATH:-}" ]; then + echo "IDF_PATH must be set before running this script" + exit 1 +fi + +if [ -z "${IDF_TARGET:-}" ]; then + echo "IDF_TARGET must be set before running this script" + exit 1 +fi + +case $IDF_TARGET in + esp32) + PREFIX=xtensa-esp32-elf- + ;; + esp32s2) + PREFIX=xtensa-esp32s2-elf- + ;; + esp32s3) + PREFIX=xtensa-esp32s3-elf- + ;; + esp32c3) + PREFIX=riscv32-esp-elf- + ;; + *) + echo "Invalid IDF_TARGET value: \"${IDF_TARGET}\"" + exit 1 + ;; +esac +LIB_DIR=${IDF_TARGET} + +ELF_FILE=test.elf + +${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${ELF_FILE} \ + -u g_coex_adapter_funcs_md5 \ + ${IDF_PATH}/components/esp_coex/lib/${LIB_DIR}/*.a + +FAILURES=0 + +function check_md5() +{ + FILENAME=$1 + SYMBOL=$2 + + GDB_COMMAND="printf \"%s\\n\", (const char*) ${SYMBOL}" + MD5_FROM_LIB=$(${PREFIX}gdb -n -batch ${ELF_FILE} -ex "${GDB_COMMAND}") + MD5_FROM_HEADER=$(md5sum ${FILENAME} | cut -c 1-7) + + echo "Checking ${FILENAME}:" + echo " ${MD5_FROM_HEADER} - from header file" + echo " ${MD5_FROM_LIB} - from library" + if [ "${MD5_FROM_LIB}" != "${MD5_FROM_HEADER}" ]; then + echo " error: MD5 mismatch!" + FAILURES=$(($FAILURES+1)) + fi +} + +echo "Checking libraries for target ${IDF_TARGET}..." +check_md5 ${IDF_PATH}/components/esp_coex/include/esp_coexist_adapter.h g_coex_adapter_funcs_md5 + +if [ $FAILURES -gt 0 ]; then + exit 1 +fi diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index b3cff57720..371a13ffa6 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -25,7 +25,6 @@ #include "endian.h" #include "esp_private/phy.h" #include "phy_init_data.h" -#include "esp_coexist_internal.h" #include "esp_private/periph_ctrl.h" #include "esp_private/wifi.h" #include "esp_rom_crc.h" diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 14a2349548..1fd108bdb3 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -121,7 +121,7 @@ if(CONFIG_VFS_SUPPORT_IO) endif() if(CONFIG_SW_COEXIST_ENABLE OR CONFIG_EXTERNAL_COEX_ENABLE) - idf_component_optional_requires(PRIVATE esp_wifi) + idf_component_optional_requires(PRIVATE esp_coex) endif() if(NOT BOOTLOADER_BUILD) diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index 74291c9bf3..a78c273998 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -17,7 +17,6 @@ if(CONFIG_ESP_WIFI_ENABLED) endif() set(srcs - "src/coexist.c" "src/mesh_event.c" "src/smartconfig.c" "src/wifi_init.c" @@ -36,7 +35,7 @@ idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" REQUIRES esp_event esp_phy esp_netif PRIV_REQUIRES driver esptool_py esp_pm esp_timer nvs_flash - wpa_supplicant hal lwip ${extra_priv_requires} + wpa_supplicant hal lwip esp_coex ${extra_priv_requires} LDFRAGMENTS "${ldfragments}") if(CONFIG_ESP_WIFI_ENABLED) @@ -47,9 +46,9 @@ if(CONFIG_ESP_WIFI_ENABLED) if(link_binary_libs) if(CONFIG_IDF_TARGET_ESP32C2) - set(blobs coexist core espnow net80211 pp smartconfig) + set(blobs core espnow net80211 pp smartconfig) else() - set(blobs coexist core espnow mesh net80211 pp smartconfig wapi) + set(blobs core espnow mesh net80211 pp smartconfig wapi) endif() foreach(blob ${blobs}) diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 0c234bea7e..cfa1d77aaa 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -6,18 +6,6 @@ menu "Wi-Fi" bool default y if SOC_WIFI_SUPPORTED - config ESP_WIFI_SW_COEXIST_ENABLE - bool "Software controls WiFi/Bluetooth coexistence" - depends on ESP_WIFI_ENABLED && BT_ENABLED - default y - select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE - help - If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware. - Recommended for heavy traffic scenarios. Both coexistence configuration options are - automatically managed, no user intervention is required. - If only Bluetooth is used, it is recommended to disable this option to reduce binary file - size. - config ESP_WIFI_STATIC_RX_BUFFER_NUM int "Max number of WiFi static RX buffers" range 2 25 if !SOC_WIFI_HE_SUPPORT @@ -323,18 +311,6 @@ 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||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32)) - 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 do not support external coex and internal coex simultaneously. - config ESP_WIFI_GCMP_SUPPORT bool "WiFi GCMP Support(GCMP128 and GCMP256)" default n diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index ce103cc1f6..b2ab1f0674 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -40,10 +40,10 @@ #include "os.h" #include "esp_smartconfig.h" #include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #include "dport_access.h" #include "esp_rom_sys.h" #include "esp32/rom/ets_sys.h" +#include "esp_modem_wrapper.h" #define TAG "esp_adapter" @@ -196,48 +196,11 @@ static void set_isr_wrapper(int32_t n, void *f, void *arg) xt_set_interrupt_handler(n, (xt_handler)f, arg); } -static void * spin_lock_create_wrapper(void) -{ - portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED; - void *mux = heap_caps_malloc(sizeof(portMUX_TYPE), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - - if (mux) { - memcpy(mux,&tmp,sizeof(portMUX_TYPE)); - return mux; - } - return NULL; -} - -static uint32_t IRAM_ATTR wifi_int_disable_wrapper(void *wifi_int_mux) -{ - if (xPortInIsrContext()) { - portENTER_CRITICAL_ISR(wifi_int_mux); - } else { - portENTER_CRITICAL(wifi_int_mux); - } - - return 0; -} - -static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) -{ - if (xPortInIsrContext()) { - portEXIT_CRITICAL_ISR(wifi_int_mux); - } else { - portEXIT_CRITICAL(wifi_int_mux); - } -} - static bool IRAM_ATTR is_from_isr_wrapper(void) { return !xPortCanYield(); } -static void IRAM_ATTR task_yield_from_isr_wrapper(void) -{ - portYIELD_FROM_ISR(); -} - static void * semphr_create_wrapper(uint32_t max, uint32_t init) { return (void *)xSemaphoreCreateCounting(max, init); @@ -297,82 +260,6 @@ static int32_t semphr_give_wrapper(void *semphr) return (int32_t)xSemaphoreGive(semphr); } - -static void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) -{ - wifi_static_queue_t *semphr = heap_caps_calloc(1, sizeof(wifi_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr) { - return NULL; - } - -#ifdef CONFIG_SPIRAM_USE_MALLOC - semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr->storage) { - goto _error; - } - - semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); - if (!semphr->handle) { - goto _error; - } - return (void *)semphr; - -_error: - if (semphr) { - if (semphr->storage) { - free(semphr->storage); - } - - free(semphr); - } - return NULL; -#else - semphr->handle = xSemaphoreCreateCounting(max, init); - return (void *)semphr; -#endif -} - -void internal_semphr_delete_wrapper(void *semphr) -{ - wifi_static_queue_t *semphr_item = (wifi_static_queue_t *)semphr; - if (semphr_item) { - if (semphr_item->handle) { - vSemaphoreDelete(semphr_item->handle); - } -#ifdef CONFIG_SPIRAM_USE_MALLOC - if (semphr_item->storage) { - free(semphr_item->storage); - } -#endif - free(semphr_item); - } -} - -static int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreTakeFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreGiveFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) -{ - if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, portMAX_DELAY); - } else { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, block_time_tick); - } -} - -static int32_t internal_semphr_give_wrapper(void *semphr) -{ - return (int32_t)xSemaphoreGive(((wifi_static_queue_t *)semphr)->handle); -} - - static void * recursive_mutex_create_wrapper(void) { return (void *)xSemaphoreCreateRecursiveMutex(); @@ -493,26 +380,6 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat ets_timer_arm(timer, tmout, repeat); } -static void IRAM_ATTR timer_disarm_wrapper(void *timer) -{ - ets_timer_disarm(timer); -} - -static void timer_done_wrapper(void *ptimer) -{ - ets_timer_done(ptimer); -} - -static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) -{ - ets_timer_setfn(ptimer, pfunction, parg); -} - -static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) -{ - ets_timer_arm_us(ptimer, us, repeat); -} - static void wifi_reset_mac_wrapper(void) { periph_module_reset(PERIPH_WIFI_MODULE); @@ -533,11 +400,6 @@ static int get_time_wrapper(void *t) return os_get_time(t); } -static void * IRAM_ATTR malloc_internal_wrapper(size_t size) -{ - return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); -} - static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); @@ -725,11 +587,6 @@ static void IRAM_ATTR esp_empty_wrapper(void) } -int 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, @@ -850,27 +707,3 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_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 = internal_semphr_create_wrapper, - ._semphr_delete = internal_semphr_delete_wrapper, - ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, - ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, - ._semphr_take = internal_semphr_take_wrapper, - ._semphr_give = internal_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, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/esp32c2/esp_adapter.c b/components/esp_wifi/esp32c2/esp_adapter.c index 7d57949e30..3906026e56 100644 --- a/components/esp_wifi/esp32c2/esp_adapter.c +++ b/components/esp_wifi/esp32c2/esp_adapter.c @@ -41,8 +41,8 @@ #include "os.h" #include "esp_smartconfig.h" #include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #include "esp32c2/rom/ets_sys.h" +#include "esp_modem_wrapper.h" #define TAG "esp_adapter" @@ -103,15 +103,6 @@ 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_route(intr_source, intr_num); @@ -176,21 +167,6 @@ static bool IRAM_ATTR is_from_isr_wrapper(void) return !xPortCanYield(); } -static void IRAM_ATTR task_yield_from_isr_wrapper(void) -{ - portYIELD_FROM_ISR(); -} - -static void * semphr_create_wrapper(uint32_t max, uint32_t init) -{ - return (void *)xSemaphoreCreateCounting(max, init); -} - -static void semphr_delete_wrapper(void *semphr) -{ - vSemaphoreDelete(semphr); -} - static void wifi_thread_semphr_free(void* data) { SemaphoreHandle_t *sem = (SemaphoreHandle_t*)(data); @@ -226,30 +202,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) { - return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); - } else { - return (int32_t)xSemaphoreTake(semphr, block_time_tick); - } -} - -static int32_t semphr_give_wrapper(void *semphr) -{ - return (int32_t)xSemaphoreGive(semphr); -} - static void * recursive_mutex_create_wrapper(void) { return (void *)xSemaphoreCreateRecursiveMutex(); @@ -370,26 +322,6 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat ets_timer_arm(timer, tmout, repeat); } -static void IRAM_ATTR timer_disarm_wrapper(void *timer) -{ - ets_timer_disarm(timer); -} - -static void timer_done_wrapper(void *ptimer) -{ - ets_timer_done(ptimer); -} - -static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) -{ - ets_timer_setfn(ptimer, pfunction, parg); -} - -static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) -{ - ets_timer_arm_us(ptimer, us, repeat); -} - static void wifi_reset_mac_wrapper(void) { periph_module_reset(PERIPH_WIFI_MODULE); @@ -424,19 +356,6 @@ static int get_time_wrapper(void *t) return os_get_time(t); } -static uint32_t esp_clk_slowclk_cal_get_wrapper(void) -{ - /* The bit width of WiFi light sleep clock calibration is 12 while the one of - * system is 19. It should shift 19 - 12 = 7. - */ - return (esp_clk_slowclk_cal_get() >> (RTC_CLK_CAL_FRACT - SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH)); -} - -static void * IRAM_ATTR malloc_internal_wrapper(size_t size) -{ - return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); -} - static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); @@ -770,25 +689,3 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_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 = xPortInIsrContext, - ._malloc_internal = malloc_internal_wrapper, - ._free = free, - ._esp_timer_get_time = esp_timer_get_time, - ._env_is_chip = env_is_chip_wrapper, - ._slowclk_cal_get = esp_clk_slowclk_cal_get_wrapper, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/esp32c3/esp_adapter.c b/components/esp_wifi/esp32c3/esp_adapter.c index d6b87809aa..04e8b57359 100644 --- a/components/esp_wifi/esp32c3/esp_adapter.c +++ b/components/esp_wifi/esp32c3/esp_adapter.c @@ -42,8 +42,8 @@ #include "os.h" #include "esp_smartconfig.h" #include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #include "esp32c3/rom/ets_sys.h" +#include "esp_modem_wrapper.h" #define TAG "esp_adapter" @@ -179,21 +179,6 @@ static bool IRAM_ATTR is_from_isr_wrapper(void) return !xPortCanYield(); } -static void IRAM_ATTR task_yield_from_isr_wrapper(void) -{ - portYIELD_FROM_ISR(); -} - -static void * semphr_create_wrapper(uint32_t max, uint32_t init) -{ - return (void *)xSemaphoreCreateCounting(max, init); -} - -static void semphr_delete_wrapper(void *semphr) -{ - vSemaphoreDelete(semphr); -} - static void wifi_thread_semphr_free(void* data) { SemaphoreHandle_t *sem = (SemaphoreHandle_t*)(data); @@ -229,30 +214,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) { - return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); - } else { - return (int32_t)xSemaphoreTake(semphr, block_time_tick); - } -} - -static int32_t semphr_give_wrapper(void *semphr) -{ - return (int32_t)xSemaphoreGive(semphr); -} - static void * recursive_mutex_create_wrapper(void) { return (void *)xSemaphoreCreateRecursiveMutex(); @@ -373,26 +334,6 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat ets_timer_arm(timer, tmout, repeat); } -static void IRAM_ATTR timer_disarm_wrapper(void *timer) -{ - ets_timer_disarm(timer); -} - -static void timer_done_wrapper(void *ptimer) -{ - ets_timer_done(ptimer); -} - -static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) -{ - ets_timer_setfn(ptimer, pfunction, parg); -} - -static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) -{ - ets_timer_arm_us(ptimer, us, repeat); -} - static void wifi_reset_mac_wrapper(void) { periph_module_reset(PERIPH_WIFI_MODULE); @@ -440,11 +381,6 @@ static uint32_t esp_clk_slowclk_cal_get_wrapper(void) } } -static void * IRAM_ATTR malloc_internal_wrapper(size_t size) -{ - return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); -} - static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); @@ -778,23 +714,3 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_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 = xPortInIsrContext, - ._malloc_internal = malloc_internal_wrapper, - ._free = free, - ._esp_timer_get_time = esp_timer_get_time, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 31654e1220..71bc971240 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -42,9 +42,9 @@ #include "os.h" #include "esp_smartconfig.h" #include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #include "esp_rom_sys.h" #include "esp32s2/rom/ets_sys.h" +#include "esp_modem_wrapper.h" #define TAG "esp_adapter" @@ -224,11 +224,6 @@ static bool IRAM_ATTR is_from_isr_wrapper(void) return !xPortCanYield(); } -static void IRAM_ATTR task_yield_from_isr_wrapper(void) -{ - portYIELD_FROM_ISR(); -} - static void * semphr_create_wrapper(uint32_t max, uint32_t init) { return (void *)xSemaphoreCreateCounting(max, init); @@ -288,80 +283,6 @@ static int32_t semphr_give_wrapper(void *semphr) return (int32_t)xSemaphoreGive(semphr); } -static void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) -{ - wifi_static_queue_t *semphr = heap_caps_calloc(1, sizeof(wifi_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr) { - return NULL; - } - -#ifdef CONFIG_SPIRAM_USE_MALLOC - semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr->storage) { - goto _error; - } - - semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); - if (!semphr->handle) { - goto _error; - } - return (void *)semphr; - -_error: - if (semphr) { - if (semphr->storage) { - free(semphr->storage); - } - - free(semphr); - } - return NULL; -#else - semphr->handle = xSemaphoreCreateCounting(max, init); - return (void *)semphr; -#endif -} - -void internal_semphr_delete_wrapper(void *semphr) -{ - wifi_static_queue_t *semphr_item = (wifi_static_queue_t *)semphr; - if (semphr_item) { - if (semphr_item->handle) { - vSemaphoreDelete(semphr_item->handle); - } -#ifdef CONFIG_SPIRAM_USE_MALLOC - if (semphr_item->storage) { - free(semphr_item->storage); - } -#endif - free(semphr_item); - } -} - -static int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreTakeFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreGiveFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) -{ - if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, portMAX_DELAY); - } else { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, block_time_tick); - } -} - -static int32_t internal_semphr_give_wrapper(void *semphr) -{ - return (int32_t)xSemaphoreGive(((wifi_static_queue_t *)semphr)->handle); -} - static void * recursive_mutex_create_wrapper(void) { return (void *)xSemaphoreCreateRecursiveMutex(); @@ -482,26 +403,6 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat ets_timer_arm(timer, tmout, repeat); } -static void IRAM_ATTR timer_disarm_wrapper(void *timer) -{ - ets_timer_disarm(timer); -} - -static void timer_done_wrapper(void *ptimer) -{ - ets_timer_done(ptimer); -} - -static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) -{ - ets_timer_setfn(ptimer, pfunction, parg); -} - -static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) -{ - ets_timer_arm_us(ptimer, us, repeat); -} - static void wifi_reset_mac_wrapper(void) { periph_module_reset(PERIPH_WIFI_MODULE); @@ -530,11 +431,6 @@ static uint32_t esp_clk_slowclk_cal_get_wrapper(void) return (esp_clk_slowclk_cal_get() >> (RTC_CLK_CAL_FRACT - SOC_WIFI_LIGHT_SLEEP_CLK_WIDTH)); } -static void * IRAM_ATTR malloc_internal_wrapper(size_t size) -{ - return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); -} - static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); @@ -726,11 +622,6 @@ static void IRAM_ATTR esp_empty_wrapper(void) } -int 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, @@ -853,23 +744,3 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._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 = internal_semphr_create_wrapper, - ._semphr_delete = internal_semphr_delete_wrapper, - ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, - ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, - ._semphr_take = internal_semphr_take_wrapper, - ._semphr_give = internal_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, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/esp32s3/esp_adapter.c b/components/esp_wifi/esp32s3/esp_adapter.c index 0ecda19857..0c7162a12d 100644 --- a/components/esp_wifi/esp32s3/esp_adapter.c +++ b/components/esp_wifi/esp32s3/esp_adapter.c @@ -43,9 +43,9 @@ #include "os.h" #include "esp_smartconfig.h" #include "esp_coexist_internal.h" -#include "esp_coexist_adapter.h" #include "esp_rom_sys.h" #include "esp32s3/rom/ets_sys.h" +#include "esp_modem_wrapper.h" #define TAG "esp_adapter" @@ -227,11 +227,6 @@ static bool IRAM_ATTR is_from_isr_wrapper(void) return !xPortCanYield(); } -static void IRAM_ATTR task_yield_from_isr_wrapper(void) -{ - portYIELD_FROM_ISR(); -} - static void * semphr_create_wrapper(uint32_t max, uint32_t init) { return (void *)xSemaphoreCreateCounting(max, init); @@ -291,80 +286,6 @@ static int32_t semphr_give_wrapper(void *semphr) return (int32_t)xSemaphoreGive(semphr); } -static void *internal_semphr_create_wrapper(uint32_t max, uint32_t init) -{ - wifi_static_queue_t *semphr = heap_caps_calloc(1, sizeof(wifi_static_queue_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr) { - return NULL; - } - -#ifdef CONFIG_SPIRAM_USE_MALLOC - semphr->storage = heap_caps_calloc(1, sizeof(StaticSemaphore_t), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); - if (!semphr->storage) { - goto _error; - } - - semphr->handle = xSemaphoreCreateCountingStatic(max, init, semphr->storage); - if (!semphr->handle) { - goto _error; - } - return (void *)semphr; - -_error: - if (semphr) { - if (semphr->storage) { - free(semphr->storage); - } - - free(semphr); - } - return NULL; -#else - semphr->handle = xSemaphoreCreateCounting(max, init); - return (void *)semphr; -#endif -} - -void internal_semphr_delete_wrapper(void *semphr) -{ - wifi_static_queue_t *semphr_item = (wifi_static_queue_t *)semphr; - if (semphr_item) { - if (semphr_item->handle) { - vSemaphoreDelete(semphr_item->handle); - } -#ifdef CONFIG_SPIRAM_USE_MALLOC - if (semphr_item->storage) { - free(semphr_item->storage); - } -#endif - free(semphr_item); - } -} - -static int32_t IRAM_ATTR internal_semphr_take_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreTakeFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t IRAM_ATTR internal_semphr_give_from_isr_wrapper(void *semphr, void *hptw) -{ - return (int32_t)xSemaphoreGiveFromISR(((wifi_static_queue_t *)semphr)->handle, hptw); -} - -static int32_t internal_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) -{ - if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, portMAX_DELAY); - } else { - return (int32_t)xSemaphoreTake(((wifi_static_queue_t *)semphr)->handle, block_time_tick); - } -} - -static int32_t internal_semphr_give_wrapper(void *semphr) -{ - return (int32_t)xSemaphoreGive(((wifi_static_queue_t *)semphr)->handle); -} - static void * recursive_mutex_create_wrapper(void) { return (void *)xSemaphoreCreateRecursiveMutex(); @@ -485,26 +406,6 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat ets_timer_arm(timer, tmout, repeat); } -static void IRAM_ATTR timer_disarm_wrapper(void *timer) -{ - ets_timer_disarm(timer); -} - -static void timer_done_wrapper(void *ptimer) -{ - ets_timer_done(ptimer); -} - -static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) -{ - ets_timer_setfn(ptimer, pfunction, parg); -} - -static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) -{ - ets_timer_arm_us(ptimer, us, repeat); -} - static void wifi_reset_mac_wrapper(void) { periph_module_reset(PERIPH_WIFI_MODULE); @@ -552,11 +453,6 @@ static uint32_t esp_clk_slowclk_cal_get_wrapper(void) } } -static void * IRAM_ATTR malloc_internal_wrapper(size_t size) -{ - return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); -} - static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); @@ -748,11 +644,6 @@ static void IRAM_ATTR esp_empty_wrapper(void) } -int 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, @@ -872,23 +763,3 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_register_cb = coex_schm_register_cb_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 = internal_semphr_create_wrapper, - ._semphr_delete = internal_semphr_delete_wrapper, - ._semphr_take_from_isr = internal_semphr_take_from_isr_wrapper, - ._semphr_give_from_isr = internal_semphr_give_from_isr_wrapper, - ._semphr_take = internal_semphr_take_wrapper, - ._semphr_give = internal_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, - ._timer_disarm = timer_disarm_wrapper, - ._timer_done = timer_done_wrapper, - ._timer_setfn = timer_setfn_wrapper, - ._timer_arm_us = timer_arm_us_wrapper, - ._magic = COEX_ADAPTER_MAGIC, -}; diff --git a/components/esp_wifi/linker.lf b/components/esp_wifi/linker.lf index 4e5c3403d5..99c7a0482e 100644 --- a/components/esp_wifi/linker.lf +++ b/components/esp_wifi/linker.lf @@ -135,12 +135,6 @@ entries: if ESP_WIFI_RX_IRAM_OPT || ESP_WIFI_SLP_IRAM_OPT: * (wifi_slp_rx_iram) -[mapping:coexist] -archive: libcoexist.a -entries: - if ESP_WIFI_SLP_IRAM_OPT = y: - * (wifi_slp_iram) - [mapping:esp_wifi] archive: libesp_wifi.a entries: diff --git a/components/esp_wifi/test_md5/test_md5.sh b/components/esp_wifi/test_md5/test_md5.sh index aff6cbcf6f..28e85b3a8f 100755 --- a/components/esp_wifi/test_md5/test_md5.sh +++ b/components/esp_wifi/test_md5/test_md5.sh @@ -44,7 +44,6 @@ ${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${ELF_FILE} \ -u g_wifi_type_md5 \ -u g_wifi_he_type_md5 \ -u g_wifi_osi_funcs_md5 \ - -u g_coex_adapter_funcs_md5 \ -u g_wifi_supplicant_funcs_md5 \ ${IDF_PATH}/components/esp_wifi/lib/${LIB_DIR}/*.a @@ -75,7 +74,6 @@ check_md5 ${IDF_PATH}/components/esp_wifi/include/esp_private/wifi_os_adapter.h check_md5 ${IDF_PATH}/components/esp_wifi/include/esp_wifi_crypto_types.h g_wifi_crypto_funcs_md5 check_md5 ${IDF_PATH}/components/esp_wifi/include/esp_wifi_types.h g_wifi_type_md5 check_md5 ${IDF_PATH}/components/esp_wifi/include/esp_wifi_he_types.h g_wifi_he_type_md5 -check_md5 ${IDF_PATH}/components/esp_wifi/include/esp_coexist_adapter.h g_coex_adapter_funcs_md5 check_md5 ${IDF_PATH}/components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h g_wifi_supplicant_funcs_md5 if [ $FAILURES -gt 0 ]; then diff --git a/tools/ci/check_public_headers_exceptions.txt b/tools/ci/check_public_headers_exceptions.txt index 024e6b9eb6..3b68da343c 100644 --- a/tools/ci/check_public_headers_exceptions.txt +++ b/tools/ci/check_public_headers_exceptions.txt @@ -118,11 +118,11 @@ components/esp_rom/include/esp32s2/rom/opi_flash.h components/esp_rom/include/esp32s2/rom/efuse.h components/esp_ringbuf/include/freertos/ringbuf.h components/esp_wifi/include/esp_wifi_crypto_types.h -components/esp_wifi/include/esp_coexist_internal.h +components/esp_coex/include/esp_coexist_internal.h components/esp_wifi/include/esp_wifi_netif.h components/esp_wifi/include/smartconfig_ack.h components/esp_wifi/include/esp_wifi_default.h -components/esp_wifi/include/esp_coexist_adapter.h +components/esp_coex/include/esp_coexist_adapter.h components/esp_event/include/esp_event_base.h components/esp_netif/include/esp_netif_sta_list.h components/esp_netif/include/esp_netif_defaults.h diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index 495a212209..051f3b2138 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -1,6 +1,7 @@ components/app_update/otatool.py components/efuse/efuse_table_gen.py components/efuse/test_efuse_host/efuse_tests.py +components/esp_coex/test_md5/test_md5.sh components/esp_wifi/test_md5/test_md5.sh components/espcoredump/espcoredump.py components/espcoredump/test/test_espcoredump.py