mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'fix/use_unilock_for_sleep_process_v5.2' into 'release/v5.2'
fix(esp_hw_support): use same lock for lightsleep/deepsleep process (v5.2) See merge request espressif/esp-idf!49844
This commit is contained in:
@@ -249,10 +249,6 @@ static sleep_config_t s_config = {
|
|||||||
expected when determining wakeup cause. */
|
expected when determining wakeup cause. */
|
||||||
static bool s_light_sleep_wakeup = false;
|
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";
|
static const char *TAG = "sleep";
|
||||||
/* APP core of esp32 can't access to RTC FAST MEMORY, do not define it with RTC_FAST_ATTR */
|
/* 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;
|
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])
|
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++) {
|
for (int n = 0; n < MAX_DSLP_HOOKS; n++) {
|
||||||
if (s_cb_array[n]==NULL || s_cb_array[n]==new_cb) {
|
if (s_cb_array[n]==NULL || s_cb_array[n]==new_cb) {
|
||||||
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;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
|
portEXIT_CRITICAL(&s_config.lock);
|
||||||
ESP_LOGE(TAG, "Registered deepsleep callbacks exceeds MAX_DSLP_HOOKS");
|
ESP_LOGE(TAG, "Registered deepsleep callbacks exceeds MAX_DSLP_HOOKS");
|
||||||
return ESP_ERR_NO_MEM;
|
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])
|
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++) {
|
for (int n = 0; n < MAX_DSLP_HOOKS; n++) {
|
||||||
if(s_cb_array[n] == old_cb) {
|
if(s_cb_array[n] == old_cb) {
|
||||||
s_cb_array[n] = NULL;
|
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)
|
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
|
/* Disable interrupts and stall another core in case another task writes
|
||||||
* to RTC memory while we calculate RTC memory CRC.
|
* 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();
|
esp_ipc_isr_stall_other_cpu();
|
||||||
|
|
||||||
// record current RTC time
|
// 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.
|
// Never returns here, except that the sleep is rejected.
|
||||||
esp_ipc_isr_release_other_cpu();
|
esp_ipc_isr_release_other_cpu();
|
||||||
portEXIT_CRITICAL(&spinlock_rtc_deep_sleep);
|
portEXIT_CRITICAL(&s_config.lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user