rtc_cntl_hal.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 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 "soc/soc_caps.h"
  8. #include "soc/lldesc.h"
  9. #include "hal/dma_types.h"
  10. #include "hal/rtc_hal.h"
  11. #include "hal/assert.h"
  12. #include "esp_attr.h"
  13. #define RTC_CNTL_HAL_LINK_BUF_SIZE_MIN (SOC_RTC_CNTL_CPU_PD_DMA_BLOCK_SIZE) /* The minimum size of dma link buffer */
  14. typedef struct rtc_cntl_link_buf_conf {
  15. uint32_t cfg[4]; /* 4 word for dma link buffer configuration */
  16. } rtc_cntl_link_buf_conf_t;
  17. void * rtc_cntl_hal_dma_link_init(void *elem, void *buff, int size, void *next)
  18. {
  19. HAL_ASSERT(elem != NULL);
  20. HAL_ASSERT(buff != NULL);
  21. HAL_ASSERT(size >= RTC_CNTL_HAL_LINK_BUF_SIZE_MIN);
  22. lldesc_t *plink = (lldesc_t *)elem;
  23. plink->eof = next ? 0 : 1;
  24. plink->owner = DMA_DESCRIPTOR_BUFFER_OWNER_DMA;
  25. plink->size = size >> 4; /* in unit of 16 bytes */
  26. plink->length = size >> 4;
  27. plink->buf = buff;
  28. plink->offset = 0;
  29. plink->sosf = 0;
  30. STAILQ_NEXT(plink, qe) = next;
  31. return (void *)plink;
  32. }
  33. #if SOC_PM_SUPPORT_CPU_PD
  34. void rtc_cntl_hal_enable_cpu_retention(void *addr)
  35. {
  36. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  37. if (addr) {
  38. if (retent->cpu_pd_mem) {
  39. lldesc_t *plink = (lldesc_t *)retent->cpu_pd_mem;
  40. /* dma link buffer configure */
  41. rtc_cntl_link_buf_conf_t *pbuf = (rtc_cntl_link_buf_conf_t *)plink->buf;
  42. pbuf->cfg[0] = 0;
  43. pbuf->cfg[1] = 0;
  44. pbuf->cfg[2] = 0;
  45. pbuf->cfg[3] = (uint32_t)-1;
  46. rtc_cntl_ll_set_cpu_retention_link_addr((uint32_t)plink);
  47. rtc_cntl_ll_enable_cpu_retention_clock();
  48. rtc_cntl_ll_enable_cpu_retention();
  49. }
  50. }
  51. }
  52. void IRAM_ATTR rtc_cntl_hal_disable_cpu_retention(void *addr)
  53. {
  54. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  55. if (addr) {
  56. if (retent->cpu_pd_mem) {
  57. rtc_cntl_ll_disable_cpu_retention();
  58. }
  59. }
  60. }
  61. #endif // SOC_PM_SUPPORT_CPU_PD