mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-19 07:55:54 +00:00
fix(phy): fix pll track when enabling and disabling PHY frequently
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_phy_init.h"
|
||||
#include "esp_private/phy.h"
|
||||
@@ -20,6 +21,7 @@ static volatile int64_t s_wifi_prev_timestamp;
|
||||
static volatile int64_t s_bt_154_prev_timestamp;
|
||||
#endif
|
||||
#define PHY_TRACK_PLL_PERIOD_IN_US 1000000
|
||||
static void phy_track_pll_internal(void);
|
||||
|
||||
#if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED || CONFIG_ESP_WIFI_ENABLED
|
||||
bool phy_enabled_modem_contains(esp_phy_modem_t modem)
|
||||
@@ -28,7 +30,28 @@ bool phy_enabled_modem_contains(esp_phy_modem_t modem)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void phy_track_pll(void)
|
||||
void phy_track_pll(void)
|
||||
{
|
||||
// Light sleep scenario: enabling and disabling PHY frequently, the timer will not get triggered.
|
||||
// Using a variable to record the previously tracked time when PLL was last called.
|
||||
// If the duration is larger than PHY_TRACK_PLL_PERIOD_IN_US, then track PLL.
|
||||
bool need_track_pll = false;
|
||||
#if CONFIG_ESP_WIFI_ENABLED
|
||||
if (phy_enabled_modem_contains(PHY_MODEM_WIFI)) {
|
||||
need_track_pll = need_track_pll || ((esp_timer_get_time() - s_wifi_prev_timestamp) > PHY_TRACK_PLL_PERIOD_IN_US);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED
|
||||
if (phy_enabled_modem_contains(PHY_MODEM_BT | PHY_MODEM_IEEE802154)) {
|
||||
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_internal();
|
||||
}
|
||||
}
|
||||
|
||||
static void phy_track_pll_internal(void)
|
||||
{
|
||||
bool wifi_track_pll = false;
|
||||
bool ble_154_track_pll = false;
|
||||
@@ -46,6 +69,14 @@ static void phy_track_pll(void)
|
||||
}
|
||||
#endif
|
||||
if (wifi_track_pll || ble_154_track_pll) {
|
||||
#if CONFIG_ESP_PHY_PLL_TRACK_DEBUG
|
||||
#if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED
|
||||
ESP_LOGI("PLL_TRACK", "BT or IEEE802154 tracks PLL: %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");
|
||||
#endif
|
||||
#endif
|
||||
phy_param_track_tot(wifi_track_pll, ble_154_track_pll);
|
||||
}
|
||||
}
|
||||
@@ -54,26 +85,12 @@ static void phy_track_pll_timer_callback(void* arg)
|
||||
{
|
||||
_lock_t phy_lock = phy_get_lock();
|
||||
_lock_acquire(&phy_lock);
|
||||
phy_track_pll();
|
||||
phy_track_pll_internal();
|
||||
_lock_release(&phy_lock);
|
||||
}
|
||||
|
||||
void phy_track_pll_init(void)
|
||||
{
|
||||
// Light sleep scenario: enabling and disabling PHY frequently, the timer will not get triggered.
|
||||
// Using a variable to record the previously tracked time when PLL was last called.
|
||||
// If the duration is larger than PHY_TRACK_PLL_PERIOD_IN_US, then track PLL.
|
||||
bool need_track_pll = false;
|
||||
#if CONFIG_ESP_WIFI_ENABLED
|
||||
need_track_pll = need_track_pll || ((esp_timer_get_time() - s_wifi_prev_timestamp) > PHY_TRACK_PLL_PERIOD_IN_US);
|
||||
#endif
|
||||
#if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED
|
||||
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();
|
||||
}
|
||||
|
||||
const esp_timer_create_args_t phy_track_pll_timer_args = {
|
||||
.callback = &phy_track_pll_timer_callback,
|
||||
.name = "phy-track-pll-timer"
|
||||
|
Reference in New Issue
Block a user