diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index c8c0f740f90..7909380bec1 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -249,10 +249,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; @@ -418,28 +414,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) @@ -1036,7 +1032,7 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection) /* Disable interrupts and stall another core in case another task writes * to RTC memory while we calculate RTC memory CRC. */ - portENTER_CRITICAL(&spinlock_rtc_deep_sleep); + portENTER_CRITICAL(&s_config.lock); esp_ipc_isr_stall_other_cpu(); // record current RTC time @@ -1102,7 +1098,7 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection) } // Never returns here, except that the sleep is rejected. esp_ipc_isr_release_other_cpu(); - portEXIT_CRITICAL(&spinlock_rtc_deep_sleep); + portEXIT_CRITICAL(&s_config.lock); return err; }