From bcce4e305229dea8dc04a9c33b069fa0e0814e0e Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Mon, 2 Dec 2019 14:56:18 +0800 Subject: [PATCH] fix bug that phy_enter_critical cannot effect on dual-core Sometimes, libphy.a call phy_enter_critical() to protect accessing critical sections, such like operating on I2C, but it may not effect when both the CPU core call it. It may cause accessing I2C blocking and cannot recover by esp_restart(), until do HW reboot. --- components/esp_wifi/src/phy_init.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/esp_wifi/src/phy_init.c b/components/esp_wifi/src/phy_init.c index 76d7a0eb8..07ec78a2c 100644 --- a/components/esp_wifi/src/phy_init.c +++ b/components/esp_wifi/src/phy_init.c @@ -75,14 +75,28 @@ static _lock_t s_modem_sleep_lock; static int64_t s_phy_rf_en_ts = 0; #endif +static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED; + uint32_t IRAM_ATTR phy_enter_critical(void) { - return portENTER_CRITICAL_NESTED(); + if (xPortInIsrContext()) { + portENTER_CRITICAL_ISR(&s_phy_int_mux); + + } else { + portENTER_CRITICAL(&s_phy_int_mux); + } + // Interrupt level will be stored in current tcb, so always return zero. + return 0; } void IRAM_ATTR phy_exit_critical(uint32_t level) { - portEXIT_CRITICAL_NESTED(level); + // Param level don't need any more, ignore it. + if (xPortInIsrContext()) { + portEXIT_CRITICAL_ISR(&s_phy_int_mux); + } else { + portEXIT_CRITICAL(&s_phy_int_mux); + } } #if CONFIG_IDF_TARGET_ESP32