rtc_cntl_hal.c 1.8 KB

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