From 3b8bd7b60838f921c944f146b70a8827ea55ab41 Mon Sep 17 00:00:00 2001 From: liuning Date: Mon, 23 Sep 2024 20:18:43 +0800 Subject: [PATCH 1/4] fix(coex): fix some coexist debug issues --- .../include/private/esp_coexist_debug.h | 11 ++++- components/esp_coex/src/coexist_debug.c | 49 ++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/components/esp_coex/include/private/esp_coexist_debug.h b/components/esp_coex/include/private/esp_coexist_debug.h index 26147262c7..80bfbbd5aa 100644 --- a/components/esp_coex/include/private/esp_coexist_debug.h +++ b/components/esp_coex/include/private/esp_coexist_debug.h @@ -108,7 +108,7 @@ typedef enum { #endif /* wifi callback -> debug */ -void wifi_set_gpio_debug_cb(void (* cb)(int, int)); +void wifi_set_gpio_debug_cb(void (* cb)(int, coex_gpio_debug_sig_t)); int wifi_gpio_debug_max_event_get(void); /* functions to check if in ROM */ @@ -128,9 +128,10 @@ void pm_check_state(void); void pm_tx_null_data_done_process(void); void pm_start(void); void pm_stop(void); +void pm_disconnected_wake(void); /* coex callback -> debug */ -void coex_set_gpio_debug_cb(void (*cb)(int, int)); +void coex_set_gpio_debug_cb(void (*cb)(int, coex_gpio_debug_sig_t)); int coex_gpio_debug_max_event_get(void); esp_err_t coex_gpio_debug_matrix_init(void); @@ -142,4 +143,10 @@ void wifi_bind_io_to_evt(uint8_t io_idx, uint8_t evt); void coex_bind_io_to_evt(uint8_t io_idx, uint8_t evt); void diagram_bind_io_to_evt(void); +/* coex -> debug + * configure single gpio debug event */ +esp_err_t coex_gpio_debug_matrix_config(int event); +/* debug -> internal use */ +esp_err_t esp_coexist_gpio_debug_matrix_config(int event); + #endif diff --git a/components/esp_coex/src/coexist_debug.c b/components/esp_coex/src/coexist_debug.c index 317f7c4547..8ef1eb6de1 100644 --- a/components/esp_coex/src/coexist_debug.c +++ b/components/esp_coex/src/coexist_debug.c @@ -13,37 +13,20 @@ #include "esp_attr.h" #include "esp_log.h" -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/gpio.h" -#include "esp32/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32S2) -#include "esp32s2/rom/gpio.h" -#include "esp32s2/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#include "esp32c3/rom/gpio.h" -#include "esp32c3/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32C2) -#include "esp32c2/rom/gpio.h" -#include "esp32c2/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32C6) -#include "esp32c6/rom/gpio.h" -#include "esp32c6/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32C5) -#include "esp32c5/rom/gpio.h" -#include "esp32c5/rom/ets_sys.h" -#elif defined(CONFIG_IDF_TARGET_ESP32C61) -#include "esp32c61/rom/gpio.h" -#include "esp32c61/rom/ets_sys.h" -#endif +#include "rom/gpio.h" +#include "rom/ets_sys.h" #include "driver/gpio.h" #include "soc/gpio_sig_map.h" #include "esp_rom_gpio.h" #include "soc/soc.h" +#if SOC_MODEM_CLOCK_IS_INDEPENDENT +#include "esp_private/esp_modem_clock.h" +#endif #if CONFIG_ESP_COEX_GPIO_DEBUG static char* TAG = "coexist debug"; -__attribute__((weak)) void wifi_set_gpio_debug_cb(void (* cb)(int, int)) +__attribute__((weak)) void wifi_set_gpio_debug_cb(void (* cb)(int, coex_gpio_debug_sig_t)) { ESP_LOGW(TAG, "Not support: %s", __FUNCTION__); } @@ -53,7 +36,7 @@ __attribute__((weak)) int wifi_gpio_debug_max_event_get(void) return 0; } -__attribute__((weak)) void coex_set_gpio_debug_cb(void (*cb)(int, int)) +__attribute__((weak)) void coex_set_gpio_debug_cb(void (*cb)(int, coex_gpio_debug_sig_t)) { ESP_LOGW(TAG, "Not support: %s", __FUNCTION__); } @@ -207,6 +190,18 @@ esp_err_t esp_coexist_debug_matrix_init(int evt, int sig, bool rev) return ESP_OK; } +esp_err_t esp_coexist_gpio_debug_matrix_config(int event) +{ +#if SOC_MODEM_CLOCK_IS_INDEPENDENT + modem_clock_module_enable(PERIPH_COEX_MODULE); +#endif + esp_err_t ret = coex_gpio_debug_matrix_config(event); +#if SOC_MODEM_CLOCK_IS_INDEPENDENT + modem_clock_module_disable(PERIPH_COEX_MODULE); +#endif + return ret; +} + esp_err_t esp_coexist_debug_init(void) { if (check_funcs_in_rom()) { @@ -270,8 +265,14 @@ esp_err_t esp_coexist_debug_init(void) gpio_set_level(s_io_nums[i], false); } +#if SOC_MODEM_CLOCK_IS_INDEPENDENT + modem_clock_module_enable(PERIPH_COEX_MODULE); +#endif /* Init coexist hardware signal */ ESP_ERROR_CHECK(coex_gpio_debug_matrix_init()); +#if SOC_MODEM_CLOCK_IS_INDEPENDENT + modem_clock_module_disable(PERIPH_COEX_MODULE); +#endif return ESP_OK; } From 18f959623c558c799edb840b9c1a6d9dcd1a64e4 Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 11 Oct 2024 15:53:55 +0800 Subject: [PATCH 2/4] fix(coex): fix esp32c5 coexist hw timer issue --- components/esp_coex/esp32c2/esp_coex_adapter.c | 6 ++++++ components/esp_coex/esp32c5/esp_coex_adapter.c | 6 ++++++ components/esp_coex/esp32c6/esp_coex_adapter.c | 6 ++++++ components/esp_coex/esp32c61/esp_coex_adapter.c | 8 +++++++- components/esp_coex/esp32h2/esp_coex_adapter.c | 6 ++++++ components/esp_coex/include/private/esp_coexist_adapter.h | 1 + 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/components/esp_coex/esp32c2/esp_coex_adapter.c b/components/esp_coex/esp32c2/esp_coex_adapter.c index 4954fb9f85..b98c9c9474 100644 --- a/components/esp_coex/esp32c2/esp_coex_adapter.c +++ b/components/esp_coex/esp32c2/esp_coex_adapter.c @@ -152,6 +152,11 @@ static int esp_coexist_debug_matrix_init_wrapper(int evt, int sig, bool rev) #endif } +static IRAM_ATTR int esp_coex_common_xtal_freq_get_wrapper(void) +{ + return rtc_clk_xtal_freq_get(); +} + coex_adapter_funcs_t g_coex_adapter_funcs = { ._version = COEX_ADAPTER_VERSION, ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, @@ -172,5 +177,6 @@ coex_adapter_funcs_t g_coex_adapter_funcs = { ._timer_setfn = esp_coex_common_timer_setfn_wrapper, ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, ._debug_matrix_init = esp_coexist_debug_matrix_init_wrapper, + ._xtal_freq_get = esp_coex_common_xtal_freq_get_wrapper, ._magic = COEX_ADAPTER_MAGIC, }; diff --git a/components/esp_coex/esp32c5/esp_coex_adapter.c b/components/esp_coex/esp32c5/esp_coex_adapter.c index b5e761ffbd..8588b7348d 100644 --- a/components/esp_coex/esp32c5/esp_coex_adapter.c +++ b/components/esp_coex/esp32c5/esp_coex_adapter.c @@ -151,6 +151,11 @@ static int esp_coexist_debug_matrix_init_wrapper(int evt, int sig, bool rev) #endif } +static IRAM_ATTR int esp_coex_common_xtal_freq_get_wrapper(void) +{ + return rtc_clk_xtal_freq_get(); +} + coex_adapter_funcs_t g_coex_adapter_funcs = { ._version = COEX_ADAPTER_VERSION, ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, @@ -170,5 +175,6 @@ coex_adapter_funcs_t g_coex_adapter_funcs = { ._timer_setfn = esp_coex_common_timer_setfn_wrapper, ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, ._debug_matrix_init = esp_coexist_debug_matrix_init_wrapper, + ._xtal_freq_get = esp_coex_common_xtal_freq_get_wrapper, ._magic = COEX_ADAPTER_MAGIC, }; diff --git a/components/esp_coex/esp32c6/esp_coex_adapter.c b/components/esp_coex/esp32c6/esp_coex_adapter.c index 81b4eef2b1..4b920ce159 100644 --- a/components/esp_coex/esp32c6/esp_coex_adapter.c +++ b/components/esp_coex/esp32c6/esp_coex_adapter.c @@ -152,6 +152,11 @@ static int esp_coexist_debug_matrix_init_wrapper(int evt, int sig, bool rev) #endif } +static IRAM_ATTR int esp_coex_common_xtal_freq_get_wrapper(void) +{ + return rtc_clk_xtal_freq_get(); +} + coex_adapter_funcs_t g_coex_adapter_funcs = { ._version = COEX_ADAPTER_VERSION, ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, @@ -171,5 +176,6 @@ coex_adapter_funcs_t g_coex_adapter_funcs = { ._timer_setfn = esp_coex_common_timer_setfn_wrapper, ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, ._debug_matrix_init = esp_coexist_debug_matrix_init_wrapper, + ._xtal_freq_get = esp_coex_common_xtal_freq_get_wrapper, ._magic = COEX_ADAPTER_MAGIC, }; diff --git a/components/esp_coex/esp32c61/esp_coex_adapter.c b/components/esp_coex/esp32c61/esp_coex_adapter.c index 547e1dbd36..059160f7ba 100644 --- a/components/esp_coex/esp32c61/esp_coex_adapter.c +++ b/components/esp_coex/esp32c61/esp_coex_adapter.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -152,6 +152,11 @@ static int esp_coexist_debug_matrix_init_wrapper(int evt, int sig, bool rev) #endif } +static IRAM_ATTR int esp_coex_common_xtal_freq_get_wrapper(void) +{ + return rtc_clk_xtal_freq_get(); +} + coex_adapter_funcs_t g_coex_adapter_funcs = { ._version = COEX_ADAPTER_VERSION, ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, @@ -171,5 +176,6 @@ coex_adapter_funcs_t g_coex_adapter_funcs = { ._timer_setfn = esp_coex_common_timer_setfn_wrapper, ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, ._debug_matrix_init = esp_coexist_debug_matrix_init_wrapper, + ._xtal_freq_get = esp_coex_common_xtal_freq_get_wrapper, ._magic = COEX_ADAPTER_MAGIC, }; diff --git a/components/esp_coex/esp32h2/esp_coex_adapter.c b/components/esp_coex/esp32h2/esp_coex_adapter.c index f00cade6f6..1fa2243ae9 100644 --- a/components/esp_coex/esp32h2/esp_coex_adapter.c +++ b/components/esp_coex/esp32h2/esp_coex_adapter.c @@ -144,6 +144,11 @@ static int esp_coexist_debug_matrix_init_wrapper(int evt, int sig, bool rev) #endif } +static IRAM_ATTR int esp_coex_common_xtal_freq_get_wrapper(void) +{ + return rtc_clk_xtal_freq_get(); +} + coex_adapter_funcs_t g_coex_adapter_funcs = { ._version = COEX_ADAPTER_VERSION, ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, @@ -163,5 +168,6 @@ coex_adapter_funcs_t g_coex_adapter_funcs = { ._timer_setfn = esp_coex_common_timer_setfn_wrapper, ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, ._debug_matrix_init = esp_coexist_debug_matrix_init_wrapper, + ._xtal_freq_get = esp_coex_common_xtal_freq_get_wrapper, ._magic = COEX_ADAPTER_MAGIC, }; diff --git a/components/esp_coex/include/private/esp_coexist_adapter.h b/components/esp_coex/include/private/esp_coexist_adapter.h index aca50a6161..15e8ef7114 100644 --- a/components/esp_coex/include/private/esp_coexist_adapter.h +++ b/components/esp_coex/include/private/esp_coexist_adapter.h @@ -47,6 +47,7 @@ typedef struct { void (* _timer_setfn)(void *ptimer, void *pfunction, void *parg); void (* _timer_arm_us)(void *ptimer, uint32_t us, bool repeat); int (* _debug_matrix_init)(int event, int signal, bool rev); + int (* _xtal_freq_get)(void); int32_t _magic; } coex_adapter_funcs_t; From 05173abc43e844aad1169e7ea40fd582cb0b4d79 Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 11 Oct 2024 15:55:28 +0800 Subject: [PATCH 3/4] fix(coex): sync up coex head file --- components/esp_coex/test_md5/test_md5.sh | 68 ++++++++++++++++++------ 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/components/esp_coex/test_md5/test_md5.sh b/components/esp_coex/test_md5/test_md5.sh index 24f80b76e3..429796bdfa 100755 --- a/components/esp_coex/test_md5/test_md5.sh +++ b/components/esp_coex/test_md5/test_md5.sh @@ -32,40 +32,74 @@ case $IDF_TARGET in esac LIB_DIR=${IDF_TARGET} -ELF_FILE=test.elf +COEX_ELF_FILE=coex.elf +TEST_ELF_FILE=test.elf FAILURES=0 function check_md5() { - FILENAME=$1 - SYMBOL=$2 - - ${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${ELF_FILE} \ - -u ${SYMBOL} \ - ${IDF_PATH}/components/esp_coex/lib/${LIB_DIR}/*.a - 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 + if [ "$1" != "$2" ]; then echo " error: MD5 mismatch!" FAILURES=$(($FAILURES+1)) fi } +function check_md5_file_lib() +{ + FILENAME=$1 + SYMBOL=$2 + + ${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${COEX_ELF_FILE} \ + -u ${SYMBOL} \ + ${IDF_PATH}/components/esp_coex/lib/${LIB_DIR}/*.a + GDB_COMMAND="printf \"%s\\n\", (const char*) ${SYMBOL}" + MD5_FROM_LIB=$(${PREFIX}gdb -n -batch ${COEX_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" + check_md5 ${MD5_FROM_HEADER} ${MD5_FROM_LIB} +} + +function check_md5_libs() +{ + COEX_SYMBOL=$1 + TEST_SYMBOL=$2 + TEST_PATH=$3 + + ${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${COEX_ELF_FILE} \ + -u ${COEX_SYMBOL} \ + ${IDF_PATH}/components/esp_coex/lib/${LIB_DIR}/*.a + + ${PREFIX}ld --unresolved-symbols=ignore-all --entry 0 -o ${TEST_ELF_FILE} \ + -u ${TEST_SYMBOL} \ + ${TEST_PATH}/*.a + + COEX_GDB_COMMAND="printf \"%s\\n\", (const char*) ${COEX_SYMBOL}" + TEST_GDB_COMMAND="printf \"%s\\n\", (const char*) ${TEST_SYMBOL}" + COEX_MD5_FROM_LIB=$(${PREFIX}gdb -n -batch ${COEX_ELF_FILE} -ex "${COEX_GDB_COMMAND}") + TEST_MD5_FROM_LIB=$(${PREFIX}gdb -n -batch ${TEST_ELF_FILE} -ex "${TEST_GDB_COMMAND}") + + echo "Checking ${TEST_PATH}/${TEST_SYMBOL} " + echo " ${COEX_MD5_FROM_LIB} - from coexist library" + echo " ${TEST_MD5_FROM_LIB} - from test library" + check_md5 ${COEX_MD5_FROM_LIB} ${TEST_MD5_FROM_LIB} +} + echo "Checking libraries for target ${IDF_TARGET}..." -check_md5 ${IDF_PATH}/components/esp_coex/include/private/esp_coexist_adapter.h g_coex_adapter_funcs_md5 +check_md5_file_lib ${IDF_PATH}/components/esp_coex/include/private/esp_coexist_adapter.h g_coex_adapter_funcs_md5 case $IDF_TARGET in esp32c6|esp32h2|esp32c5) - check_md5 ${IDF_PATH}/components/esp_coex/include/esp_coex_i154.h g_coex_i154_funcs_md5 + check_md5_file_lib ${IDF_PATH}/components/esp_coex/include/esp_coex_i154.h g_coex_i154_funcs_md5 ;; esac +if [[ ! "$IDF_TARGET" =~ ^(esp32h2)$ ]]; then + check_md5_libs g_coex_basic_md5 g_wifi_coex_basic_md5 ${IDF_PATH}/components/esp_wifi/lib/${LIB_DIR} +fi + if [ $FAILURES -gt 0 ]; then exit 1 fi From 99dbcf536c0a6f5afedbe8353acb5ca53b45356e Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 11 Oct 2024 17:57:14 +0800 Subject: [PATCH 4/4] fix(coex): fix esp32c2/esp32c5/esp32c61 coexist memory leakage issue --- components/esp_coex/lib | 2 +- components/esp_rom/esp32c2/ld/esp32c2.rom.ld | 2 +- components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld | 2 +- components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld | 2 +- components/esp_wifi/lib | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/esp_coex/lib b/components/esp_coex/lib index e15e7a161f..9baa4202b6 160000 --- a/components/esp_coex/lib +++ b/components/esp_coex/lib @@ -1 +1 @@ -Subproject commit e15e7a161fc1a48e8fb4fd0b3da74623c30ba1cb +Subproject commit 9baa4202b6bddac85aa5f318c171a1b413e2caea diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index dd40a0253b..2abe48222a 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -1623,7 +1623,7 @@ dbg_lmac_rxtx_statis_dump = 0x40001e90; dbg_lmac_hw_statis_dump = 0x40001e94; dbg_lmac_diag_statis_dump = 0x40001e98; dbg_lmac_ps_statis_dump = 0x40001e9c; -pp_timer_do_process = 0x40001ea0; +/*pp_timer_do_process = 0x40001ea0;*/ rcUpdateAMPDUParam = 0x40001ea4; rcUpdatePhyMode = 0x40001ea8; rcGetHighestRateIdx = 0x40001eac; diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld index 7515b90cca..96c501f990 100644 --- a/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld +++ b/components/esp_rom/esp32c5/ld/esp32c5.rom.pp.ld @@ -222,7 +222,7 @@ pp_coex_tx_release = 0x40000f08; ppAdd2AMPDUTail = 0x40000f0c; ppDirectRecycleAmpdu = 0x40000f10; ppRegressAmpdu = 0x40000f14; -pp_timer_do_process = 0x40000f18; +/*pp_timer_do_process = 0x40000f18;*/ rcGetAmpduSched = 0x40000f1c; rcUpdateRxDone = 0x40000f20; rc_get_trc = 0x40000f24; diff --git a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld index cf1349b9ab..6931333f9d 100644 --- a/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld +++ b/components/esp_rom/esp32c61/ld/esp32c61.rom.pp.ld @@ -225,7 +225,7 @@ pp_coex_tx_release = 0x40000e7c; ppAdd2AMPDUTail = 0x40000e80; ppDirectRecycleAmpdu = 0x40000e84; ppRegressAmpdu = 0x40000e88; -pp_timer_do_process = 0x40000e8c; +/*pp_timer_do_process = 0x40000e8c;*/ rcGetAmpduSched = 0x40000e90; rcUpdateRxDone = 0x40000e94; rc_get_trc = 0x40000e98; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index a93530033a..0da5a8a5df 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit a93530033aece29f1622c9ca9161eb4770aea909 +Subproject commit 0da5a8a5dfd8914496c5975af7d8903a44f8bced