Skip to content

Commit 0f07209

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'enhancement/protect_from_odd_phy_disable_operations_by_single_modem_v5.5' into 'release/v5.5'
esp_phy: Add protection of consecutive disable operations by single modem source (v5.5) See merge request espressif/esp-idf!41291
2 parents 10d07d1 + 6891970 commit 0f07209

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

components/esp_phy/src/phy_common.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -126,13 +126,26 @@ void phy_track_pll_deinit(void)
126126
}
127127
#endif
128128

129+
static const char *phy_get_modem_str(esp_phy_modem_t modem)
130+
{
131+
switch (modem) {
132+
case PHY_MODEM_WIFI: return "Wi-Fi";
133+
case PHY_MODEM_BT: return "Bluetooth";
134+
case PHY_MODEM_IEEE802154: return "IEEE 802.15.4";
135+
default: return "";
136+
}
137+
}
138+
129139
void phy_set_modem_flag(esp_phy_modem_t modem)
130140
{
131141
s_phy_modem_flag |= modem;
132142
}
133143

134144
void phy_clr_modem_flag(esp_phy_modem_t modem)
135145
{
146+
if ((s_phy_modem_flag & modem) == 0) {
147+
ESP_LOGW(TAG, "Clear the flag of %s before it's set", phy_get_modem_str(modem));
148+
}
136149
s_phy_modem_flag &= ~modem;
137150
}
138151

components/esp_phy/src/phy_init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ void esp_phy_disable(esp_phy_modem_t modem)
357357
#if CONFIG_ESP_PHY_RECORD_USED_TIME
358358
phy_record_time(false, modem);
359359
#endif
360+
esp_phy_modem_t saved_modem = phy_get_modem_flag();
360361
phy_clr_modem_flag(modem);
361-
if (phy_get_modem_flag() == 0) {
362+
if (saved_modem == modem) {
362363
// ESP32 will track pll in the wifi/BT modem interrupt handler.
363364
#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_ESP_PHY_DISABLE_PLL_TRACK
364365
phy_track_pll_deinit();

components/esp_phy/src/phy_init_esp32hxx.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -134,8 +134,9 @@ void esp_phy_disable(esp_phy_modem_t modem)
134134
#if CONFIG_ESP_PHY_RECORD_USED_TIME
135135
phy_record_time(false, modem);
136136
#endif
137+
esp_phy_modem_t saved_modem = phy_get_modem_flag();
137138
phy_clr_modem_flag(modem);
138-
if (phy_get_modem_flag() == 0) {
139+
if (saved_modem == modem) {
139140

140141
#if !CONFIG_ESP_PHY_DISABLE_PLL_TRACK
141142
phy_track_pll_deinit();

0 commit comments

Comments
 (0)