Skip to content

Commit ea05eba

Browse files
committed
feat(esp_hw_support): do mstatus restore on each core
1 parent 228e74e commit ea05eba

File tree

1 file changed

+6
-4
lines changed
  • components/esp_hw_support/lowpower/port/esp32p4

1 file changed

+6
-4
lines changed

components/esp_hw_support/lowpower/port/esp32p4/sleep_cpu.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ static TCM_IRAM_ATTR esp_err_t do_cpu_retention(sleep_cpu_entry_cb_t goto_sleep,
380380
uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
381381
{
382382
uint8_t core_id = esp_cpu_get_core_id();
383+
/* mstatus is core privated CSR, do it near the core critical regs restore */
384+
uint32_t mstatus = save_mstatus_and_disable_global_int();
383385
rv_core_critical_regs_save();
384386

385387
RvCoreCriticalSleepFrame * frame = s_cpu_retention.retent.critical_frame[core_id];
@@ -405,15 +407,14 @@ static TCM_IRAM_ATTR esp_err_t do_cpu_retention(sleep_cpu_entry_cb_t goto_sleep,
405407
validate_retention_frame_crc((uint32_t*)frame, RV_SLEEP_CTX_SZ1 - 2 * sizeof(long), (uint32_t *)(&frame->frame_crc));
406408
}
407409
#endif
408-
410+
restore_mstatus(mstatus);
409411
return pmu_sleep_finish(dslp);
410412
}
411413

412414
esp_err_t TCM_IRAM_ATTR esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t, uint32_t, uint32_t, bool),
413415
uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
414416
{
415417
esp_sleep_execute_event_callbacks(SLEEP_EVENT_SW_CPU_TO_MEM_START, (void *)0);
416-
uint32_t mstatus = save_mstatus_and_disable_global_int();
417418
uint8_t core_id = esp_cpu_get_core_id();
418419
#if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
419420
atomic_store(&s_smp_retention_state[core_id], SMP_BACKUP_START);
@@ -443,9 +444,8 @@ esp_err_t TCM_IRAM_ATTR esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t,
443444
atomic_store(&s_smp_retention_state[core_id], SMP_RESTORE_START);
444445
#endif
445446

446-
rv_core_noncritical_regs_restore();
447447
cpu_domain_dev_regs_restore(s_cpu_retention.retent.clic_frame[core_id]);
448-
restore_mstatus(mstatus);
448+
rv_core_noncritical_regs_restore();
449449

450450
#if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
451451
atomic_store(&s_smp_retention_state[core_id], SMP_RESTORE_DONE);
@@ -518,6 +518,7 @@ static TCM_IRAM_ATTR void smp_core_do_retention(void)
518518
atomic_store(&s_smp_retention_state[core_id], SMP_BACKUP_START);
519519
rv_core_noncritical_regs_save();
520520
cpu_domain_dev_regs_save(s_cpu_retention.retent.clic_frame[core_id]);
521+
uint32_t mstatus = save_mstatus_and_disable_global_int();
521522
rv_core_critical_regs_save();
522523
RvCoreCriticalSleepFrame *frame_critical = s_cpu_retention.retent.critical_frame[core_id];
523524
if ((frame_critical->pmufunc & 0x3) == 0x1) {
@@ -537,6 +538,7 @@ static TCM_IRAM_ATTR void smp_core_do_retention(void)
537538
REG_CLR_BIT(HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_CORE1_GLOBAL);
538539
}
539540
atomic_store(&s_smp_retention_state[core_id], SMP_RESTORE_START);
541+
restore_mstatus(mstatus);
540542
cpu_domain_dev_regs_restore(s_cpu_retention.retent.clic_frame[core_id]);
541543
rv_core_noncritical_regs_restore();
542544
atomic_store(&s_smp_retention_state[core_id], SMP_RESTORE_DONE);

0 commit comments

Comments
 (0)