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