diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 2d6d1c5a746..fbf224e32b8 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -14,7 +14,7 @@ set(embed_files) if(CONFIG_ESP_PHY_ENABLED) - set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c") + set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c" "src/phy_debug.c") if(CONFIG_APP_NO_BLOBS) set(link_binary_libs 0) diff --git a/components/esp_phy/include/esp_private/phy_debug.h b/components/esp_phy/include/esp_private/phy_debug.h new file mode 100644 index 00000000000..68cfc2f3d25 --- /dev/null +++ b/components/esp_phy/include/esp_private/phy_debug.h @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "esp_phy_init.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if CONFIG_ESP_PHY_RECORD_USED_TIME +void phy_record_time(bool enabled, esp_phy_modem_t modem); +#endif + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_phy/lib b/components/esp_phy/lib index 5695f4f3810..b88e4b76e09 160000 --- a/components/esp_phy/lib +++ b/components/esp_phy/lib @@ -1 +1 @@ -Subproject commit 5695f4f38108658bc4a33e4712c1ebcb34911434 +Subproject commit b88e4b76e090ae59c51cb00b916d38def895b396 diff --git a/components/esp_phy/src/phy_common.c b/components/esp_phy/src/phy_common.c index 17b77825d2a..a1f6689626d 100644 --- a/components/esp_phy/src/phy_common.c +++ b/components/esp_phy/src/phy_common.c @@ -35,7 +35,25 @@ static const char* TAG = "phy_comm"; static volatile uint16_t s_phy_modem_flag = 0; #if !CONFIG_ESP_PHY_DISABLE_PLL_TRACK +#define RFPLL BIT(0) +#define WIFI_POWER BIT(1) +#define BT154_POWER BIT(2) +#define RXCAL BIT(3) +#define TXCAL BIT(4) + +typedef struct { + int16_t temp_curr; + int16_t temp_rfpll; + int16_t temp_wifi_power; + int16_t temp_bt_power; + int16_t temp_rxcal; + int16_t temp_txcal; + uint16_t flag; +} phy_param_track_result_t; + extern void phy_param_track_tot(bool en_wifi, bool en_ble_154); +extern const phy_param_track_result_t* phy_debug_get_track_result(); + static esp_timer_handle_t phy_track_pll_timer; #if CONFIG_ESP_WIFI_ENABLED static volatile int64_t s_wifi_prev_timestamp; @@ -97,15 +115,37 @@ static void phy_track_pll_internal(void) } #endif if (wifi_track_pll || ble_154_track_pll) { + phy_param_track_tot(wifi_track_pll, ble_154_track_pll); #if CONFIG_ESP_PHY_PLL_TRACK_DEBUG +// TODO:Support other targets +#if CONFIG_IDF_TARGET_ESP32S31 + const phy_param_track_result_t* result = phy_debug_get_track_result(); + if (result && result->flag != 0) { #if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED - ESP_LOGI("PLL_TRACK", "BT or IEEE802154 tracks PLL: %s", ble_154_track_pll ? "True" : "False"); + ESP_LOGI("TEMP_TRACK", "BT or IEEE802154 tracks: %s", ble_154_track_pll ? "True" : "False"); #endif #if CONFIG_ESP_WIFI_ENABLED - ESP_LOGI("PLL_TRACK", "Wi-Fi tracks PLL: %s", wifi_track_pll ? "True" : "False"); + ESP_LOGI("TEMP_TRACK", "Wi-Fi tracks: %s", wifi_track_pll ? "True" : "False"); +#endif + if (result->flag & RFPLL) { + ESP_LOGI("TEMP_TRACK", "RFPLL processed, temperature: %d", result->temp_rfpll); + } + if (result->flag & WIFI_POWER) { + ESP_LOGI("TEMP_TRACK", "WIFI_POWER processed, temperature: %d", result->temp_wifi_power); + } + if (result->flag & BT154_POWER) { + ESP_LOGI("TEMP_TRACK", "BT154_POWER processed, temperature: %d", result->temp_bt_power); + } + if (result->flag & RXCAL) { + ESP_LOGI("TEMP_TRACK", "RXCAL processed, temperature: %d", result->temp_rxcal); + } + if (result->flag & TXCAL) { + ESP_LOGI("TEMP_TRACK", "TXCAL processed, temperature: %d", result->temp_txcal); + } + ESP_LOGI("TEMP_TRACK", "Current temperature: %d", result->temp_curr); + } #endif #endif - phy_param_track_tot(wifi_track_pll, ble_154_track_pll); } } @@ -121,7 +161,7 @@ void phy_track_pll_init(void) { const esp_timer_create_args_t phy_track_pll_timer_args = { .callback = &phy_track_pll_timer_callback, - .name = "phy-track-pll-timer" + .name = "phy-track-timer" }; ESP_ERROR_CHECK(esp_timer_create(&phy_track_pll_timer_args, &phy_track_pll_timer)); ESP_ERROR_CHECK(esp_timer_start_periodic(phy_track_pll_timer, PHY_TRACK_PLL_PERIOD_IN_US)); diff --git a/components/esp_phy/src/phy_debug.c b/components/esp_phy/src/phy_debug.c new file mode 100644 index 00000000000..c57bb95e6f7 --- /dev/null +++ b/components/esp_phy/src/phy_debug.c @@ -0,0 +1,74 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_attr.h" +#include "esp_err.h" +#include "esp_phy_init.h" +#include "esp_timer.h" + +#include "esp_private/phy.h" +#include "esp_private/phy_debug.h" + +#if CONFIG_ESP_PHY_RECORD_USED_TIME + +#define ESP_PHY_MODEM_COUNT_MAX (__builtin_ffs(PHY_MODEM_MAX - 1)) +#define ESP_PHY_IS_VALID_MODEM(modem) (__builtin_popcount(modem) == 1 && __builtin_ctz(modem) < ESP_PHY_MODEM_COUNT_MAX) + +static DRAM_ATTR struct { + uint64_t used_time; + uint64_t enabled_time; + uint64_t disabled_time; +} s_phy_rf_used_info[ESP_PHY_MODEM_COUNT_MAX]; + +void IRAM_ATTR phy_record_time(bool enabled, esp_phy_modem_t modem) +{ + uint8_t index = __builtin_ctz(modem); + + if (enabled) { + s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); + } else { + s_phy_rf_used_info[index].disabled_time = esp_timer_get_time(); + s_phy_rf_used_info[index].used_time += s_phy_rf_used_info[index].disabled_time - s_phy_rf_used_info[index].enabled_time; + } +} + +esp_err_t phy_query_used_time(uint64_t *used_time, esp_phy_modem_t modem) +{ + if (!ESP_PHY_IS_VALID_MODEM(modem)) { + return ESP_ERR_INVALID_ARG; + } + + uint8_t index = __builtin_ctz(modem); + _lock_t phy_lock = phy_get_lock(); + _lock_acquire(&phy_lock); + *used_time = s_phy_rf_used_info[index].used_time; + if (s_phy_rf_used_info[index].disabled_time < s_phy_rf_used_info[index].enabled_time) { + *used_time += esp_timer_get_time() - s_phy_rf_used_info[index].enabled_time; + } + _lock_release(&phy_lock); + return ESP_OK; +} + +esp_err_t phy_clear_used_time(esp_phy_modem_t modem) +{ + if (!ESP_PHY_IS_VALID_MODEM(modem)) { + return ESP_ERR_INVALID_ARG; + } + + uint8_t index = __builtin_ctz(modem); + _lock_t phy_lock = phy_get_lock(); + _lock_acquire(&phy_lock); + if (s_phy_rf_used_info[index].enabled_time > s_phy_rf_used_info[index].disabled_time) { + s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); + } else { + s_phy_rf_used_info[index].enabled_time = s_phy_rf_used_info[index].disabled_time; + } + s_phy_rf_used_info[index].used_time = 0; + _lock_release(&phy_lock); + return ESP_OK; +} + +#endif diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 7f63b8efba0..b8311de41d1 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -58,6 +58,7 @@ #if SOC_PM_REGDMA_MODEM_LINK_PROTECT #include "esp_private/esp_pau.h" #endif // SOC_PM_REGDMA_MODEM_LINK_PROTECT +#include "esp_private/phy_debug.h" #ifndef PHY_INIT_MODEM_CLOCK_REQUIRED_BITS #warning "PHY_INIT_MODEM_CLOCK_REQUIRED_BITS not defined; using default value 0" @@ -190,59 +191,6 @@ static phy_country_to_bin_type_t s_country_code_map_type_table[] = { }; #endif -#if CONFIG_ESP_PHY_RECORD_USED_TIME -#define ESP_PHY_MODEM_COUNT_MAX (__builtin_ffs(PHY_MODEM_MAX - 1)) -#define ESP_PHY_IS_VALID_MODEM(modem) (__builtin_popcount(modem) == 1 && __builtin_ctz(modem) < ESP_PHY_MODEM_COUNT_MAX) - -static DRAM_ATTR struct { - uint64_t used_time; - uint64_t enabled_time; - uint64_t disabled_time; -} s_phy_rf_used_info[ESP_PHY_MODEM_COUNT_MAX]; - -static IRAM_ATTR void phy_record_time(bool enabled, esp_phy_modem_t modem) { - uint8_t index = __builtin_ctz(modem); - if (enabled) { - s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); - } else { - s_phy_rf_used_info[index].disabled_time = esp_timer_get_time(); - s_phy_rf_used_info[index].used_time += s_phy_rf_used_info[index].disabled_time - s_phy_rf_used_info[index].enabled_time; - } -} - -esp_err_t phy_query_used_time(uint64_t *used_time, esp_phy_modem_t modem) { - if (!ESP_PHY_IS_VALID_MODEM(modem)) { - return ESP_ERR_INVALID_ARG; - } - uint8_t index = __builtin_ctz(modem); - _lock_acquire(&s_phy_access_lock); - *used_time = s_phy_rf_used_info[index].used_time; - if (s_phy_rf_used_info[index].disabled_time < s_phy_rf_used_info[index].enabled_time) { - // phy is being used - *used_time += esp_timer_get_time() - s_phy_rf_used_info[index].enabled_time; - } - _lock_release(&s_phy_access_lock); - return ESP_OK; -} - -esp_err_t phy_clear_used_time(esp_phy_modem_t modem) { - if (!ESP_PHY_IS_VALID_MODEM(modem)) { - return ESP_ERR_INVALID_ARG; - } - uint8_t index = __builtin_ctz(modem); - _lock_acquire(&s_phy_access_lock); - if (s_phy_rf_used_info[index].enabled_time > s_phy_rf_used_info[index].disabled_time) { - // phy is being used - s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); - } else { - s_phy_rf_used_info[index].enabled_time = s_phy_rf_used_info[index].disabled_time; - } - s_phy_rf_used_info[index].used_time = 0; - _lock_release(&s_phy_access_lock); - return ESP_OK; -} -#endif - uint32_t IRAM_ATTR phy_enter_critical(void) { if (xPortInIsrContext()) { diff --git a/components/esp_phy/src/phy_init_esp32hxx.c b/components/esp_phy/src/phy_init_esp32hxx.c index e49b6ff8f5a..0f56118e3b3 100644 --- a/components/esp_phy/src/phy_init_esp32hxx.c +++ b/components/esp_phy/src/phy_init_esp32hxx.c @@ -15,6 +15,7 @@ #include "esp_private/esp_modem_clock.h" #endif #include "phy_init_deps.h" +#include "esp_private/phy_debug.h" #ifndef PHY_INIT_MODEM_CLOCK_REQUIRED_BITS #warning "PHY_INIT_MODEM_CLOCK_REQUIRED_BITS not defined; using default value 0" @@ -29,59 +30,6 @@ static _lock_t s_phy_access_lock; /* Reference count of enabling PHY */ static bool s_phy_is_enabled = false; -#if CONFIG_ESP_PHY_RECORD_USED_TIME -#define ESP_PHY_MODEM_COUNT_MAX (__builtin_ffs(PHY_MODEM_MAX - 1)) -#define ESP_PHY_IS_VALID_MODEM(modem) (__builtin_popcount(modem) == 1 && __builtin_ctz(modem) < ESP_PHY_MODEM_COUNT_MAX) - -static DRAM_ATTR struct { - uint64_t used_time; - uint64_t enabled_time; - uint64_t disabled_time; -} s_phy_rf_used_info[ESP_PHY_MODEM_COUNT_MAX]; - -static IRAM_ATTR void phy_record_time(bool enabled, esp_phy_modem_t modem) { - uint8_t index = __builtin_ctz(modem); - if (enabled) { - s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); - } else { - s_phy_rf_used_info[index].disabled_time = esp_timer_get_time(); - s_phy_rf_used_info[index].used_time += s_phy_rf_used_info[index].disabled_time - s_phy_rf_used_info[index].enabled_time; - } -} - -esp_err_t phy_query_used_time(uint64_t *used_time, esp_phy_modem_t modem) { - if (!ESP_PHY_IS_VALID_MODEM(modem)) { - return ESP_ERR_INVALID_ARG; - } - uint8_t index = __builtin_ctz(modem); - _lock_acquire(&s_phy_access_lock); - *used_time = s_phy_rf_used_info[index].used_time; - if (s_phy_rf_used_info[index].disabled_time < s_phy_rf_used_info[index].enabled_time) { - // phy is being used - *used_time += esp_timer_get_time() - s_phy_rf_used_info[index].enabled_time; - } - _lock_release(&s_phy_access_lock); - return ESP_OK; -} - -esp_err_t phy_clear_used_time(esp_phy_modem_t modem) { - if (!ESP_PHY_IS_VALID_MODEM(modem)) { - return ESP_ERR_INVALID_ARG; - } - uint8_t index = __builtin_ctz(modem); - _lock_acquire(&s_phy_access_lock); - if (s_phy_rf_used_info[index].enabled_time > s_phy_rf_used_info[index].disabled_time) { - // phy is being used - s_phy_rf_used_info[index].enabled_time = esp_timer_get_time(); - } else { - s_phy_rf_used_info[index].enabled_time = s_phy_rf_used_info[index].disabled_time; - } - s_phy_rf_used_info[index].used_time = 0; - _lock_release(&s_phy_access_lock); - return ESP_OK; -} -#endif - uint32_t IRAM_ATTR phy_enter_critical(void) { if (xPortInIsrContext()) {