fix(esp_phy): Add protection of consecutive disable operations by single modem source

This commit is contained in:
Wang Mengyang
2025-08-03 19:18:58 +08:00
parent d9521058ab
commit b1e0afd47a
3 changed files with 20 additions and 3 deletions

View File

@@ -15,6 +15,8 @@
#include "hal/temperature_sensor_ll.h"
#endif
static const char* TAG = "phy_comm";
static volatile uint16_t s_phy_modem_flag = 0;
#if !CONFIG_ESP_PHY_DISABLE_PLL_TRACK
@@ -114,6 +116,16 @@ void phy_track_pll_deinit(void)
}
#endif
static const char *phy_get_modem_str(esp_phy_modem_t modem)
{
switch (modem) {
case PHY_MODEM_WIFI: return "Wi-Fi";
case PHY_MODEM_BT: return "Bluetooth";
case PHY_MODEM_IEEE802154: return "IEEE 802.15.4";
default: return "";
}
}
void phy_set_modem_flag(esp_phy_modem_t modem)
{
s_phy_modem_flag |= modem;
@@ -121,6 +133,9 @@ void phy_set_modem_flag(esp_phy_modem_t modem)
void phy_clr_modem_flag(esp_phy_modem_t modem)
{
if ((s_phy_modem_flag & modem) == 0) {
ESP_LOGW(TAG, "Clear the flag of %s before it's set", phy_get_modem_str(modem));
}
s_phy_modem_flag &= ~modem;
}

View File

@@ -352,8 +352,9 @@ void esp_phy_disable(esp_phy_modem_t modem)
#if CONFIG_ESP_PHY_RECORD_USED_TIME
phy_record_time(false, modem);
#endif
esp_phy_modem_t saved_modem = phy_get_modem_flag();
phy_clr_modem_flag(modem);
if (phy_get_modem_flag() == 0) {
if (saved_modem == modem) {
// ESP32 will track pll in the wifi/BT modem interrupt handler.
#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_ESP_PHY_DISABLE_PLL_TRACK
phy_track_pll_deinit();

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -134,8 +134,9 @@ void esp_phy_disable(esp_phy_modem_t modem)
#if CONFIG_ESP_PHY_RECORD_USED_TIME
phy_record_time(false, modem);
#endif
esp_phy_modem_t saved_modem = phy_get_modem_flag();
phy_clr_modem_flag(modem);
if (phy_get_modem_flag() == 0) {
if (saved_modem == modem) {
#if !CONFIG_ESP_PHY_DISABLE_PLL_TRACK
phy_track_pll_deinit();