rtc_cntl_hal.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // The HAL layer for RTC CNTL (common part)
  15. #include "soc/soc_caps.h"
  16. #include "soc/lldesc.h"
  17. #include "hal/dma_types.h"
  18. #include "hal/rtc_hal.h"
  19. #include "hal/assert.h"
  20. #include "esp_attr.h"
  21. #define RTC_CNTL_HAL_LINK_BUF_SIZE_MIN (SOC_RTC_CNTL_CPU_PD_DMA_BLOCK_SIZE) /* The minimum size of dma link buffer */
  22. typedef struct rtc_cntl_link_buf_conf {
  23. uint32_t cfg[4]; /* 4 word for dma link buffer configuration */
  24. } rtc_cntl_link_buf_conf_t;
  25. void * rtc_cntl_hal_dma_link_init(void *elem, void *buff, int size, void *next)
  26. {
  27. HAL_ASSERT(elem != NULL);
  28. HAL_ASSERT(buff != NULL);
  29. HAL_ASSERT(size >= RTC_CNTL_HAL_LINK_BUF_SIZE_MIN);
  30. lldesc_t *plink = (lldesc_t *)elem;
  31. plink->eof = next ? 0 : 1;
  32. plink->owner = DMA_DESCRIPTOR_BUFFER_OWNER_DMA;
  33. plink->size = size >> 4; /* in unit of 16 bytes */
  34. plink->length = size >> 4;
  35. plink->buf = buff;
  36. plink->offset = 0;
  37. plink->sosf = 0;
  38. STAILQ_NEXT(plink, qe) = next;
  39. return (void *)plink;
  40. }
  41. #if SOC_PM_SUPPORT_CPU_PD
  42. void rtc_cntl_hal_enable_cpu_retention(void *addr)
  43. {
  44. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  45. if (addr) {
  46. if (retent->cpu_pd_mem) {
  47. lldesc_t *plink = (lldesc_t *)retent->cpu_pd_mem;
  48. /* dma link buffer configure */
  49. rtc_cntl_link_buf_conf_t *pbuf = (rtc_cntl_link_buf_conf_t *)plink->buf;
  50. pbuf->cfg[0] = 0;
  51. pbuf->cfg[1] = 0;
  52. pbuf->cfg[2] = 0;
  53. pbuf->cfg[3] = (uint32_t)-1;
  54. rtc_cntl_ll_set_cpu_retention_link_addr((uint32_t)plink);
  55. rtc_cntl_ll_enable_cpu_retention_clock();
  56. rtc_cntl_ll_enable_cpu_retention();
  57. }
  58. }
  59. }
  60. void IRAM_ATTR rtc_cntl_hal_disable_cpu_retention(void *addr)
  61. {
  62. rtc_cntl_sleep_retent_t *retent = (rtc_cntl_sleep_retent_t *)addr;
  63. if (addr) {
  64. if (retent->cpu_pd_mem) {
  65. rtc_cntl_ll_disable_cpu_retention();
  66. }
  67. }
  68. }
  69. #endif // SOC_PM_SUPPORT_CPU_PD