Merge branch 'fix/use_unilock_for_sleep_process_v5.3' into 'release/v5.3'

fix(esp_hw_support): use same lock for lightsleep/deepsleep process (v5.3)

See merge request espressif/esp-idf!49845
This commit is contained in:
Jiang Jiang Jian
2026-06-23 11:00:20 +08:00
+7 -11
View File
@@ -270,10 +270,6 @@ static sleep_config_t s_config = {
expected when determining wakeup cause. */
static bool s_light_sleep_wakeup = false;
/* Updating RTC_MEMORY_CRC_REG register via set_rtc_memory_crc()
is not thread-safe, so we need to disable interrupts before going to deep sleep. */
static portMUX_TYPE spinlock_rtc_deep_sleep = portMUX_INITIALIZER_UNLOCKED;
static const char *TAG = "sleep";
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_FAST_ATTR */
static RTC_SLOW_ATTR bool s_adc_tsen_enabled = false;
@@ -439,28 +435,28 @@ esp_err_t esp_deep_sleep_try(uint64_t time_in_us)
static esp_err_t s_sleep_hook_register(esp_deep_sleep_cb_t new_cb, esp_deep_sleep_cb_t s_cb_array[MAX_DSLP_HOOKS])
{
portENTER_CRITICAL(&spinlock_rtc_deep_sleep);
portENTER_CRITICAL(&s_config.lock);
for (int n = 0; n < MAX_DSLP_HOOKS; n++) {
if (s_cb_array[n]==NULL || s_cb_array[n]==new_cb) {
s_cb_array[n]=new_cb;
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
portEXIT_CRITICAL(&s_config.lock);
return ESP_OK;
}
}
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
portEXIT_CRITICAL(&s_config.lock);
ESP_LOGE(TAG, "Registered deepsleep callbacks exceeds MAX_DSLP_HOOKS");
return ESP_ERR_NO_MEM;
}
static void s_sleep_hook_deregister(esp_deep_sleep_cb_t old_cb, esp_deep_sleep_cb_t s_cb_array[MAX_DSLP_HOOKS])
{
portENTER_CRITICAL(&spinlock_rtc_deep_sleep);
portENTER_CRITICAL(&s_config.lock);
for (int n = 0; n < MAX_DSLP_HOOKS; n++) {
if(s_cb_array[n] == old_cb) {
s_cb_array[n] = NULL;
}
}
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
portEXIT_CRITICAL(&s_config.lock);
}
esp_err_t esp_deep_sleep_register_hook(esp_deep_sleep_cb_t new_dslp_cb)
@@ -1120,7 +1116,7 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
// Must acquire all spinlocks which may be acquired during sleep process before stalling other core,
// otherwise deadlock may occur.
portENTER_CRITICAL(&spinlock_rtc_deep_sleep);
portENTER_CRITICAL(&s_config.lock);
#if !CONFIG_FREERTOS_UNICORE
extern portMUX_TYPE rtc_spinlock;
portENTER_CRITICAL_SAFE(&rtc_spinlock); // Maybe acquired from temp_sensor_get_raw_value by phy_close_rf callback
@@ -1204,7 +1200,7 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection)
esp_clk_private_unlock();
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
#endif
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
portEXIT_CRITICAL(&s_config.lock);
return err;
}