From 99d68570a6841e7130e07bfd87e2ccd9d20536de Mon Sep 17 00:00:00 2001 From: zwx Date: Wed, 18 Oct 2023 16:36:47 +0800 Subject: [PATCH] fix(esp_phy): fix pll track corner case --- components/esp_phy/include/esp_private/phy.h | 6 ++++++ components/esp_phy/src/phy_common.c | 17 ++++++++++++++--- components/esp_phy/src/phy_init.c | 5 +++++ components/esp_phy/src/phy_init_esp32hxx.c | 5 +++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/components/esp_phy/include/esp_private/phy.h b/components/esp_phy/include/esp_private/phy.h index 8abb2961bc..19fbf7a6d8 100644 --- a/components/esp_phy/include/esp_private/phy.h +++ b/components/esp_phy/include/esp_private/phy.h @@ -168,6 +168,12 @@ void phy_clr_modem_flag(esp_phy_modem_t modem); * */ esp_phy_modem_t phy_get_modem_flag(void); + +/** + * @brief Get the PHY lock, only used in esp_phy, the user should not use this function. + * + */ +_lock_t phy_get_lock(void); #ifdef __cplusplus } #endif diff --git a/components/esp_phy/src/phy_common.c b/components/esp_phy/src/phy_common.c index 825c9585d2..d28745b8e8 100644 --- a/components/esp_phy/src/phy_common.c +++ b/components/esp_phy/src/phy_common.c @@ -6,6 +6,7 @@ #include "esp_timer.h" #include "esp_phy_init.h" +#include "esp_private/phy.h" #include static volatile uint16_t s_phy_modem_flag = 0; @@ -27,7 +28,7 @@ bool phy_enabled_modem_contains(esp_phy_modem_t modem) } #endif -static void phy_track_pll_timer_callback(void* arg) +static void phy_track_pll(void) { bool wifi_track_pll = false; bool ble_154_track_pll = false; @@ -44,7 +45,17 @@ static void phy_track_pll_timer_callback(void* arg) s_bt_154_prev_timestamp = esp_timer_get_time(); } #endif - phy_param_track_tot(wifi_track_pll, ble_154_track_pll); + if (wifi_track_pll || ble_154_track_pll) { + phy_param_track_tot(wifi_track_pll, ble_154_track_pll); + } +} + +static void phy_track_pll_timer_callback(void* arg) +{ + _lock_t phy_lock = phy_get_lock(); + _lock_acquire(&phy_lock); + phy_track_pll(); + _lock_release(&phy_lock); } void phy_track_pll_init(void) @@ -60,7 +71,7 @@ void phy_track_pll_init(void) need_track_pll = need_track_pll || ((esp_timer_get_time() - s_bt_154_prev_timestamp) > PHY_TRACK_PLL_PERIOD_IN_US); #endif if (need_track_pll) { - phy_track_pll_timer_callback((void* )0); + phy_track_pll(); } const esp_timer_create_args_t phy_track_pll_timer_args = { diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 8aad481c96..3c0d2b0ee2 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -1113,3 +1113,8 @@ esp_err_t esp_phy_update_country_info(const char *country) void esp_wifi_power_domain_on(void) __attribute__((alias("esp_wifi_bt_power_domain_on"))); void esp_wifi_power_domain_off(void) __attribute__((alias("esp_wifi_bt_power_domain_off"))); + +_lock_t phy_get_lock(void) +{ + return s_phy_access_lock; +} diff --git a/components/esp_phy/src/phy_init_esp32hxx.c b/components/esp_phy/src/phy_init_esp32hxx.c index 9387af78af..9639ffccd3 100644 --- a/components/esp_phy/src/phy_init_esp32hxx.c +++ b/components/esp_phy/src/phy_init_esp32hxx.c @@ -89,3 +89,8 @@ void esp_phy_disable(esp_phy_modem_t modem) phy_clr_modem_flag(modem); _lock_release(&s_phy_access_lock); } + +_lock_t phy_get_lock(void) +{ + return s_phy_access_lock; +}