1 /*
2  * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include "soc/soc_caps.h"
11 #include "hal/gpio_types.h"
12 #include "hal/rtc_cntl_ll.h"
13 #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
14 #include "hal/rtc_io_ll.h"
15 #endif
16 
17 typedef struct rtc_cntl_sleep_retent {
18 #if SOC_PM_SUPPORT_CPU_PD
19     void     *cpu_pd_mem;   /* Internal ram address for cpu retention */
20 #endif // SOC_PM_SUPPORT_CPU_PD
21 #if SOC_PM_SUPPORT_TAGMEM_PD
22     struct {
23         void     *link_addr;  /* Internal ram address for tagmem retention */
24         struct {
25             uint32_t start_point: 8,    /* the row of start for i-cache tag memory */
26                      vld_size: 8,       /* valid size of i-cache tag memory, unit: 4 i-cache tagmem blocks */
27                      size: 8,           /* i-cache tag memory size, unit: 4 i-cache tagmem blocks */
28                      enable: 1;         /* enable or disable i-cache tagmem retention */
29         } icache;
30         struct {
31             uint32_t start_point: 9,    /* the row of start for d-cache tag memory */
32                      vld_size: 9,       /* valid size of d-cache tag memory, unit: 4 d-cache tagmem blocks */
33                      size: 9,           /* d-cache tag memory size, unit: 4 d-cache tagmem blocks */
34                      enable: 1;         /* enable or disable d-cache tagmem retention */
35         } dcache;
36     } tagmem;
37 #endif // SOC_PM_SUPPORT_TAGMEM_PD
38 } rtc_cntl_sleep_retent_t;
39 
40 #define RTC_HAL_DMA_LINK_NODE_SIZE      (16)
41 
42 #if SOC_PM_SUPPORT_EXT1_WAKEUP
43 
44 #define rtc_hal_ext1_get_wakeup_status()                  rtc_cntl_ll_ext1_get_wakeup_status()
45 
46 #define rtc_hal_ext1_clear_wakeup_status()                rtc_cntl_ll_ext1_clear_wakeup_status()
47 
48 #define rtc_hal_ext1_set_wakeup_pins(mask, mode)          rtc_cntl_ll_ext1_set_wakeup_pins(mask, mode)
49 
50 #define rtc_hal_ext1_clear_wakeup_pins()                  rtc_cntl_ll_ext1_clear_wakeup_pins()
51 
52 #define rtc_hal_ext1_get_wakeup_pins()                    rtc_cntl_ll_ext1_get_wakeup_pins()
53 
54 #endif // SOC_PM_SUPPORT_EXT1_WAKEUP
55 
56 #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && (SOC_RTCIO_PIN_COUNT == 0)
57 
58 #define rtc_hal_gpio_get_wakeup_status()                  rtc_cntl_ll_gpio_get_wakeup_status()
59 
60 #define rtc_hal_gpio_clear_wakeup_status()                rtc_cntl_ll_gpio_clear_wakeup_status()
61 
62 #endif
63 
64 #define rtc_hal_set_wakeup_timer(ticks)                   rtc_cntl_ll_set_wakeup_timer(ticks)
65 
66 void * rtc_cntl_hal_dma_link_init(void *elem, void *buff, int size, void *next);
67 
68 #if SOC_PM_SUPPORT_CPU_PD
69 
70 void rtc_cntl_hal_enable_cpu_retention(void *addr);
71 
72 void rtc_cntl_hal_disable_cpu_retention(void *addr);
73 
74 #endif
75 
76 #if SOC_PM_SUPPORT_TAGMEM_PD
77 
78 void rtc_cntl_hal_enable_tagmem_retention(void *addr);
79 
80 void rtc_cntl_hal_disable_tagmem_retention(void *addr);
81 
82 #endif
83 
84 /*
85  * Enable wakeup from ULP coprocessor.
86  */
87 #define rtc_hal_ulp_wakeup_enable()                       rtc_cntl_ll_ulp_wakeup_enable()
88 
89 #define rtc_hal_ulp_int_clear()                           rtc_cntl_ll_ulp_int_clear()
90