4141#endif
4242
4343
44- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
44+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
4545#include <stdatomic.h>
4646#include "soc/hp_system_reg.h"
4747typedef enum {
@@ -81,7 +81,7 @@ typedef struct {
8181 } retent ;
8282} sleep_cpu_retention_t ;
8383
84- static DRAM_ATTR __attribute__((unused )) sleep_cpu_retention_t s_cpu_retention ;
84+ static TCM_DRAM_ATTR __attribute__((unused )) sleep_cpu_retention_t s_cpu_retention ;
8585
8686extern RvCoreCriticalSleepFrame * rv_core_critical_regs_frame [portNUM_PROCESSORS ];
8787
@@ -162,7 +162,7 @@ static esp_err_t esp_sleep_cpu_retention_init_impl(void)
162162 s_cpu_retention .retent .clic_frame [core_id ] = (cpu_domain_dev_sleep_frame_t * )frame ;
163163 }
164164 }
165- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
165+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
166166 for (uint8_t core_id = 0 ; core_id < portNUM_PROCESSORS ; ++ core_id ) {
167167 atomic_init (& s_smp_retention_state [core_id ], SMP_IDLE );
168168 }
@@ -209,7 +209,7 @@ FORCE_INLINE_ATTR void restore_mstatus(uint32_t mstatus_val)
209209 RV_WRITE_CSR (mstatus , mstatus_val );
210210}
211211
212- static IRAM_ATTR RvCoreNonCriticalSleepFrame * rv_core_noncritical_regs_save (void )
212+ static TCM_IRAM_ATTR RvCoreNonCriticalSleepFrame * rv_core_noncritical_regs_save (void )
213213{
214214 RvCoreNonCriticalSleepFrame * frame = s_cpu_retention .retent .non_critical_frame [esp_cpu_get_core_id ()];
215215
@@ -277,7 +277,7 @@ static IRAM_ATTR RvCoreNonCriticalSleepFrame * rv_core_noncritical_regs_save(voi
277277 return frame ;
278278}
279279
280- static IRAM_ATTR void rv_core_noncritical_regs_restore (void )
280+ static TCM_IRAM_ATTR void rv_core_noncritical_regs_restore (void )
281281{
282282 RvCoreNonCriticalSleepFrame * frame = s_cpu_retention .retent .non_critical_frame [esp_cpu_get_core_id ()];
283283
@@ -343,7 +343,7 @@ static IRAM_ATTR void rv_core_noncritical_regs_restore(void)
343343 RV_WRITE_CSR (mcycle , frame -> mcycle );
344344}
345345
346- static IRAM_ATTR void cpu_domain_dev_regs_save (cpu_domain_dev_sleep_frame_t * frame )
346+ static TCM_IRAM_ATTR void cpu_domain_dev_regs_save (cpu_domain_dev_sleep_frame_t * frame )
347347{
348348 assert (frame );
349349 cpu_domain_dev_regs_region_t * region = frame -> region ;
@@ -357,7 +357,7 @@ static IRAM_ATTR void cpu_domain_dev_regs_save(cpu_domain_dev_sleep_frame_t *fra
357357 }
358358}
359359
360- static IRAM_ATTR void cpu_domain_dev_regs_restore (cpu_domain_dev_sleep_frame_t * frame )
360+ static TCM_IRAM_ATTR void cpu_domain_dev_regs_restore (cpu_domain_dev_sleep_frame_t * frame )
361361{
362362 assert (frame );
363363 cpu_domain_dev_regs_region_t * region = frame -> region ;
@@ -372,12 +372,12 @@ static IRAM_ATTR void cpu_domain_dev_regs_restore(cpu_domain_dev_sleep_frame_t *
372372}
373373
374374#if CONFIG_PM_CHECK_SLEEP_RETENTION_FRAME
375- static IRAM_ATTR void update_retention_frame_crc (uint32_t * frame_ptr , uint32_t frame_check_size , uint32_t * frame_crc_ptr )
375+ static TCM_IRAM_ATTR void update_retention_frame_crc (uint32_t * frame_ptr , uint32_t frame_check_size , uint32_t * frame_crc_ptr )
376376{
377377 * (frame_crc_ptr ) = esp_crc32_le (0 , (void * )frame_ptr , frame_check_size );
378378}
379379
380- static IRAM_ATTR void validate_retention_frame_crc (uint32_t * frame_ptr , uint32_t frame_check_size , uint32_t * frame_crc_ptr )
380+ static TCM_IRAM_ATTR void validate_retention_frame_crc (uint32_t * frame_ptr , uint32_t frame_check_size , uint32_t * frame_crc_ptr )
381381{
382382 if (* (frame_crc_ptr ) != esp_crc32_le (0 , (void * )(frame_ptr ), frame_check_size )){
383383 // resume uarts
@@ -399,7 +399,7 @@ extern RvCoreCriticalSleepFrame * rv_core_critical_regs_save(void);
399399extern RvCoreCriticalSleepFrame * rv_core_critical_regs_restore (void );
400400typedef uint32_t (* sleep_cpu_entry_cb_t )(uint32_t , uint32_t , uint32_t , bool );
401401
402- static IRAM_ATTR esp_err_t do_cpu_retention (sleep_cpu_entry_cb_t goto_sleep ,
402+ static TCM_IRAM_ATTR esp_err_t do_cpu_retention (sleep_cpu_entry_cb_t goto_sleep ,
403403 uint32_t wakeup_opt , uint32_t reject_opt , uint32_t lslp_mem_inf_fpu , bool dslp )
404404{
405405 uint8_t core_id = esp_cpu_get_core_id ();
@@ -410,11 +410,11 @@ static IRAM_ATTR esp_err_t do_cpu_retention(sleep_cpu_entry_cb_t goto_sleep,
410410 esp_sleep_execute_event_callbacks (SLEEP_EVENT_SW_CPU_TO_MEM_END , (void * )0 );
411411#if CONFIG_PM_CHECK_SLEEP_RETENTION_FRAME
412412 /* Minus 2 * sizeof(long) is for bypass `pmufunc` and `frame_crc` field */
413- update_retention_frame_crc ((uint32_t * )frame , RV_SLEEP_CTX_FRMSZ - 2 * sizeof (long ), (uint32_t * )(& frame -> frame_crc ));
413+ update_retention_frame_crc ((uint32_t * )frame , RV_SLEEP_CTX_SZ1 - 2 * sizeof (long ), (uint32_t * )(& frame -> frame_crc ));
414414#endif
415415 REG_WRITE (RTC_SLEEP_WAKE_STUB_ADDR_REG , (uint32_t )rv_core_critical_regs_restore );
416416
417- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
417+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
418418 atomic_store (& s_smp_retention_state [core_id ], SMP_BACKUP_DONE );
419419 while (atomic_load (& s_smp_retention_state [!core_id ]) != SMP_BACKUP_DONE ) {
420420 ;
@@ -425,20 +425,20 @@ static IRAM_ATTR esp_err_t do_cpu_retention(sleep_cpu_entry_cb_t goto_sleep,
425425 }
426426#if CONFIG_PM_CHECK_SLEEP_RETENTION_FRAME
427427 else {
428- validate_retention_frame_crc ((uint32_t * )frame , RV_SLEEP_CTX_FRMSZ - 2 * sizeof (long ), (uint32_t * )(& frame -> frame_crc ));
428+ validate_retention_frame_crc ((uint32_t * )frame , RV_SLEEP_CTX_SZ1 - 2 * sizeof (long ), (uint32_t * )(& frame -> frame_crc ));
429429 }
430430#endif
431431
432432 return pmu_sleep_finish ();
433433}
434434
435- esp_err_t IRAM_ATTR esp_sleep_cpu_retention (uint32_t (* goto_sleep )(uint32_t , uint32_t , uint32_t , bool ),
435+ esp_err_t TCM_IRAM_ATTR esp_sleep_cpu_retention (uint32_t (* goto_sleep )(uint32_t , uint32_t , uint32_t , bool ),
436436 uint32_t wakeup_opt , uint32_t reject_opt , uint32_t lslp_mem_inf_fpu , bool dslp )
437437{
438438 esp_sleep_execute_event_callbacks (SLEEP_EVENT_SW_CPU_TO_MEM_START , (void * )0 );
439439 uint32_t mstatus = save_mstatus_and_disable_global_int ();
440440 uint8_t core_id = esp_cpu_get_core_id ();
441- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
441+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
442442 atomic_store (& s_smp_retention_state [core_id ], SMP_BACKUP_START );
443443#endif
444444 cpu_domain_dev_regs_save (s_cpu_retention .retent .clic_frame [core_id ]);
@@ -457,7 +457,7 @@ esp_err_t IRAM_ATTR esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t, uin
457457 validate_retention_frame_crc ((uint32_t * )frame , sizeof (RvCoreNonCriticalSleepFrame ) - sizeof (long ), (uint32_t * )(& frame -> frame_crc ));
458458#endif
459459
460- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
460+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
461461 // Start core1
462462 if (core_id == 0 ) {
463463 REG_SET_BIT (HP_SYS_CLKRST_SOC_CLK_CTRL0_REG , HP_SYS_CLKRST_REG_CORE1_CPU_CLK_EN );
@@ -472,7 +472,7 @@ esp_err_t IRAM_ATTR esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t, uin
472472 cpu_domain_dev_regs_restore (s_cpu_retention .retent .clic_frame [core_id ]);
473473 restore_mstatus (mstatus );
474474
475- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP && !CONFIG_FREERTOS_UNICORE
475+ #if ESP_SLEEP_POWER_DOWN_CPU && !CONFIG_FREERTOS_UNICORE
476476 atomic_store (& s_smp_retention_state [core_id ], SMP_RESTORE_DONE );
477477#endif
478478 return err ;
@@ -504,7 +504,7 @@ bool cpu_domain_pd_allowed(void)
504504
505505esp_err_t sleep_cpu_configure (bool light_sleep_enable )
506506{
507- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP
507+ #if ESP_SLEEP_POWER_DOWN_CPU
508508 if (light_sleep_enable ) {
509509 ESP_RETURN_ON_ERROR (esp_sleep_cpu_retention_init (), TAG , "Failed to enable CPU power down during light sleep." );
510510 } else {
@@ -515,7 +515,7 @@ esp_err_t sleep_cpu_configure(bool light_sleep_enable)
515515}
516516
517517#if !CONFIG_FREERTOS_UNICORE
518- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP
518+ #if ESP_SLEEP_POWER_DOWN_CPU
519519static TCM_IRAM_ATTR void smp_core_do_retention (void )
520520{
521521 uint8_t core_id = esp_cpu_get_core_id ();
@@ -572,14 +572,14 @@ static TCM_IRAM_ATTR void smp_core_do_retention(void)
572572}
573573
574574
575- IRAM_ATTR void esp_sleep_cpu_skip_retention (void ) {
575+ TCM_IRAM_ATTR void esp_sleep_cpu_skip_retention (void ) {
576576 atomic_store (& s_smp_retention_state [esp_cpu_get_core_id ()], SMP_SKIP_RETENTION );
577577}
578578#endif
579579
580580void sleep_smp_cpu_sleep_prepare (void )
581581{
582- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP
582+ #if ESP_SLEEP_POWER_DOWN_CPU
583583 while (atomic_load (& s_smp_retention_state [!esp_cpu_get_core_id ()]) != SMP_IDLE ) {
584584 ;
585585 }
@@ -591,7 +591,7 @@ void sleep_smp_cpu_sleep_prepare(void)
591591
592592void sleep_smp_cpu_wakeup_prepare (void )
593593{
594- #if CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP
594+ #if ESP_SLEEP_POWER_DOWN_CPU
595595 uint8_t core_id = esp_cpu_get_core_id ();
596596 if (atomic_load (& s_smp_retention_state [core_id ]) == SMP_RESTORE_DONE ) {
597597 while (atomic_load (& s_smp_retention_state [!core_id ]) != SMP_RESTORE_DONE ) {
0 commit comments