rtc_cntl_hal.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "hal/rtc_hal.h"
  16. #include "soc/soc_caps.h"
  17. #include "esp32c3/rom/lldesc.h"
  18. #include "esp_attr.h"
  19. #define RTC_CNTL_HAL_LINK_BUF_SIZE_MIN (SOC_RTC_CNTL_CPU_PD_DMA_BLOCK_SIZE) /* The minimum size of dma link buffer */
  20. typedef struct rtc_cntl_link_buf_conf {
  21. uint32_t cfg[4]; /* 4 word for dma link buffer configuration */
  22. } rtc_cntl_link_buf_conf_t;
  23. void * rtc_cntl_hal_dma_link_init(void *elem, void *buff, int size, void *next)
  24. {
  25. assert(elem != NULL);
  26. assert(buff != NULL);
  27. assert(size >= RTC_CNTL_HAL_LINK_BUF_SIZE_MIN);
  28. lldesc_t *plink = (lldesc_t *)elem;
  29. plink->eof = next ? 0 : 1;
  30. plink->owner = 1;
  31. plink->size = size >> 4; /* in unit of 16 bytes */
  32. plink->length = size >> 4;
  33. plink->buf = buff;
  34. plink->offset = 0;
  35. plink->sosf = 0;
  36. STAILQ_NEXT(plink, qe) = next;
  37. return (void *)plink;
  38. }
  39. void rtc_cntl_hal_enable_cpu_retention(void *addr)
  40. {
  41. if (addr) {
  42. lldesc_t *plink = (lldesc_t *)addr;
  43. /* dma link buffer configure */
  44. rtc_cntl_link_buf_conf_t *pbuf = (rtc_cntl_link_buf_conf_t *)plink->buf;
  45. pbuf->cfg[0] = 0;
  46. pbuf->cfg[1] = 0;
  47. pbuf->cfg[2] = 0;
  48. pbuf->cfg[3] = (uint32_t)-1;
  49. rtc_cntl_ll_enable_cpu_retention((uint32_t)addr);
  50. }
  51. }