rtc_cntl_hal.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. // The HAL layer for RTC CNTL (common part)
  7. #include "hal/rtc_hal.h"
  8. #include "soc/soc_caps.h"
  9. #include "esp32s3/rom/lldesc.h"
  10. #include "esp32s3/rom/cache.h"
  11. #include "hal/dma_types.h"
  12. #include "hal/assert.h"
  13. #include "esp_attr.h"
  14. #define RTC_CNTL_HAL_LINK_BUF_SIZE_MIN (SOC_RTC_CNTL_CPU_PD_DMA_BLOCK_SIZE) /* The minimum size of dma link buffer */
  15. typedef struct rtc_cntl_link_buf_conf {
  16. uint32_t cfg[4]; /* 4 word for dma link buffer configuration */
  17. } rtc_cntl_link_buf_conf_t;
  18. void * rtc_cntl_hal_dma_link_init(void *elem, void *buff, int size, void *next)
  19. {
  20. HAL_ASSERT(elem != NULL);
  21. HAL_ASSERT(buff != NULL);
  22. HAL_ASSERT(size >= RTC_CNTL_HAL_LINK_BUF_SIZE_MIN);
  23. lldesc_t *plink = (lldesc_t *)elem;
  24. plink->eof = next ? 0 : 1;
  25. plink->owner = DMA_DESCRIPTOR_BUFFER_OWNER_DMA;
  26. plink->size = size >> 4; /* in unit of 16 bytes */
  27. plink->length = size >> 4;
  28. plink->buf = buff;
  29. plink->offset = 0;
  30. plink->sosf = 0;
  31. STAILQ_NEXT(plink, qe) = next;
  32. return (void *)plink;
  33. }
  34. #if SOC_PM_SUPPORT_CPU_PD
  35. #define DEFAULT_RETENTION_WAIT_CYCLES (0x7f)
  36. #define DEFAULT_RETENTION_CLKOFF_WAIT_CYCLES (0xf)
  37. #define DEFAULT_RETENTION_DONE_WAIT_CYCLES (0x7)
  38. void rtc_cntl_hal_enable_cpu_retention(void *addr)
  39. {
  40. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  41. if (addr) {
  42. if (retent->cpu_pd_mem) {
  43. lldesc_t *plink = (lldesc_t *)retent->cpu_pd_mem;
  44. /* dma link buffer configure */
  45. rtc_cntl_link_buf_conf_t *pbuf = (rtc_cntl_link_buf_conf_t *)plink->buf;
  46. pbuf->cfg[0] = 0;
  47. pbuf->cfg[1] = 0;
  48. pbuf->cfg[2] = 0;
  49. pbuf->cfg[3] = 0xfffe0000;
  50. rtc_cntl_ll_set_cpu_retention_link_addr((uint32_t)plink);
  51. rtc_cntl_ll_config_cpu_retention_timing(
  52. DEFAULT_RETENTION_WAIT_CYCLES,
  53. DEFAULT_RETENTION_CLKOFF_WAIT_CYCLES,
  54. DEFAULT_RETENTION_DONE_WAIT_CYCLES
  55. );
  56. rtc_cntl_ll_enable_cpu_retention_clock();
  57. rtc_cntl_ll_enable_cpu_retention();
  58. }
  59. }
  60. }
  61. void IRAM_ATTR rtc_cntl_hal_disable_cpu_retention(void *addr)
  62. {
  63. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  64. if (addr) {
  65. if (retent->cpu_pd_mem) {
  66. /* I/d-cache tagmem retention has not been included or not
  67. * been enabled, after the system wakes up, all the contents
  68. * of i/d-cache need to be invalidated. */
  69. #if SOC_PM_SUPPORT_TAGMEM_PD
  70. if (!retent->tagmem.icache.enable) {
  71. Cache_Invalidate_ICache_All();
  72. }
  73. if (!retent->tagmem.dcache.enable) {
  74. Cache_Invalidate_DCache_All();
  75. }
  76. #else
  77. Cache_Invalidate_ICache_All();
  78. Cache_Invalidate_DCache_All();
  79. #endif // SOC_PM_SUPPORT_TAGMEM_PD
  80. rtc_cntl_ll_disable_cpu_retention();
  81. }
  82. }
  83. }
  84. #endif // SOC_PM_SUPPORT_CPU_PD
  85. #if SOC_PM_SUPPORT_TAGMEM_PD
  86. void rtc_cntl_hal_enable_tagmem_retention(void *addr)
  87. {
  88. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  89. if (addr) {
  90. if (retent->tagmem.link_addr) {
  91. rtc_cntl_ll_set_tagmem_retention_link_addr((uint32_t)(retent->tagmem.link_addr));
  92. rtc_cntl_ll_enable_tagmem_retention();
  93. if (retent->tagmem.icache.enable) {
  94. rtc_cntl_ll_enable_icache_tagmem_retention(
  95. retent->tagmem.icache.start_point,
  96. retent->tagmem.icache.vld_size,
  97. retent->tagmem.icache.size
  98. );
  99. }
  100. if (retent->tagmem.dcache.enable) {
  101. rtc_cntl_ll_enable_dcache_tagmem_retention(
  102. retent->tagmem.dcache.start_point,
  103. retent->tagmem.dcache.vld_size,
  104. retent->tagmem.dcache.size
  105. );
  106. }
  107. }
  108. }
  109. }
  110. void IRAM_ATTR rtc_cntl_hal_disable_tagmem_retention(void *addr)
  111. {
  112. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  113. if (addr) {
  114. if (retent->tagmem.link_addr) {
  115. rtc_cntl_ll_disable_tagmem_retention();
  116. if (retent->tagmem.icache.enable) {
  117. rtc_cntl_ll_disable_icache_tagmem_retention();
  118. }
  119. if (retent->tagmem.dcache.enable) {
  120. rtc_cntl_ll_disable_dcache_tagmem_retention();
  121. }
  122. }
  123. }
  124. }
  125. #endif // SOC_PM_SUPPORT_TAGMEM_PD