rtc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Copyright 2020 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. #ifndef _ROM_RTC_H_
  15. #define _ROM_RTC_H_
  16. #include "ets_sys.h"
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #include "soc/soc.h"
  20. #include "soc/rtc_cntl_reg.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /** \defgroup rtc_apis, rtc registers and memory related apis
  25. * @brief rtc apis
  26. */
  27. /** @addtogroup rtc_apis
  28. * @{
  29. */
  30. /**************************************************************************************
  31. * Note: *
  32. * Some Rtc memory and registers are used, in ROM or in internal library. *
  33. * Please do not use reserved or used rtc memory or registers. *
  34. * *
  35. *************************************************************************************
  36. * RTC Memory & Store Register usage
  37. *************************************************************************************
  38. * rtc memory addr type size usage
  39. * 0x3f421000(0x50000000) Slow SIZE_CP Co-Processor code/Reset Entry
  40. * 0x3f421000+SIZE_CP Slow 8192-SIZE_CP
  41. *
  42. * 0x3ff80000(0x40070000) Fast 8192 deep sleep entry code
  43. *
  44. *************************************************************************************
  45. * RTC store registers usage
  46. * RTC_CNTL_STORE0_REG Reserved
  47. * RTC_CNTL_STORE1_REG RTC_SLOW_CLK calibration value
  48. * RTC_CNTL_STORE2_REG Boot time, low word
  49. * RTC_CNTL_STORE3_REG Boot time, high word
  50. * RTC_CNTL_STORE4_REG External XTAL frequency
  51. * RTC_CNTL_STORE5_REG APB bus frequency
  52. * RTC_CNTL_STORE6_REG FAST_RTC_MEMORY_ENTRY
  53. * RTC_CNTL_STORE7_REG FAST_RTC_MEMORY_CRC
  54. *************************************************************************************
  55. */
  56. #define RTC_SLOW_CLK_CAL_REG RTC_CNTL_STORE1_REG
  57. #define RTC_BOOT_TIME_LOW_REG RTC_CNTL_STORE2_REG
  58. #define RTC_BOOT_TIME_HIGH_REG RTC_CNTL_STORE3_REG
  59. #define RTC_XTAL_FREQ_REG RTC_CNTL_STORE4_REG
  60. #define RTC_APB_FREQ_REG RTC_CNTL_STORE5_REG
  61. #define RTC_ENTRY_ADDR_REG RTC_CNTL_STORE6_REG
  62. #define RTC_RESET_CAUSE_REG RTC_CNTL_STORE6_REG
  63. #define RTC_MEMORY_CRC_REG RTC_CNTL_STORE7_REG
  64. typedef enum {
  65. AWAKE = 0, //<CPU ON
  66. LIGHT_SLEEP = BIT0, //CPU waiti, PLL ON. We don't need explicitly set this mode.
  67. DEEP_SLEEP = BIT1 //CPU OFF, PLL OFF, only specific timer could wake up
  68. } SLEEP_MODE;
  69. typedef enum {
  70. NO_MEAN = 0,
  71. POWERON_RESET = 1, /**<1, Vbat power on reset*/
  72. RTC_SW_SYS_RESET = 3, /**<3, Software reset digital core*/
  73. DEEPSLEEP_RESET = 5, /**<3, Deep Sleep reset digital core*/
  74. SDIO_RESET = 6, /**<6, Reset by SLC module, reset digital core*/
  75. TG0WDT_SYS_RESET = 7, /**<7, Timer Group0 Watch dog reset digital core*/
  76. TG1WDT_SYS_RESET = 8, /**<8, Timer Group1 Watch dog reset digital core*/
  77. RTCWDT_SYS_RESET = 9, /**<9, RTC Watch dog Reset digital core*/
  78. INTRUSION_RESET = 10, /**<10, Instrusion tested to reset CPU*/
  79. TG0WDT_CPU_RESET = 11, /**<11, Time Group0 reset CPU*/
  80. RTC_SW_CPU_RESET = 12, /**<12, Software reset CPU*/
  81. RTCWDT_CPU_RESET = 13, /**<13, RTC Watch dog Reset CPU*/
  82. RTCWDT_BROWN_OUT_RESET = 15, /**<15, Reset when the vdd voltage is not stable*/
  83. RTCWDT_RTC_RESET = 16, /**<16, RTC Watch dog reset digital core and rtc module*/
  84. TG1WDT_CPU_RESET = 17, /**<11, Time Group1 reset CPU*/
  85. SUPER_WDT_RESET = 18, /**<11, super watchdog reset digital core and rtc module*/
  86. } RESET_REASON;
  87. typedef enum {
  88. NO_SLEEP = 0,
  89. EXT_EVENT0_TRIG = BIT0,
  90. EXT_EVENT1_TRIG = BIT1,
  91. GPIO_TRIG = BIT2,
  92. TIMER_EXPIRE = BIT3,
  93. SDIO_TRIG = BIT4,
  94. MAC_TRIG = BIT5,
  95. UART0_TRIG = BIT6,
  96. UART1_TRIG = BIT7,
  97. TOUCH_TRIG = BIT8,
  98. SAR_TRIG = BIT9,
  99. BT_TRIG = BIT10,
  100. RISCV_TRIG = BIT11,
  101. XTAL_DEAD_TRIG = BIT12,
  102. RISCV_TRAP_TRIG = BIT13,
  103. USB_TRIG = BIT14
  104. } WAKEUP_REASON;
  105. typedef enum {
  106. DISEN_WAKEUP = NO_SLEEP,
  107. EXT_EVENT0_TRIG_EN = EXT_EVENT0_TRIG,
  108. EXT_EVENT1_TRIG_EN = EXT_EVENT1_TRIG,
  109. GPIO_TRIG_EN = GPIO_TRIG,
  110. TIMER_EXPIRE_EN = TIMER_EXPIRE,
  111. SDIO_TRIG_EN = SDIO_TRIG,
  112. MAC_TRIG_EN = MAC_TRIG,
  113. UART0_TRIG_EN = UART0_TRIG,
  114. UART1_TRIG_EN = UART1_TRIG,
  115. TOUCH_TRIG_EN = TOUCH_TRIG,
  116. SAR_TRIG_EN = SAR_TRIG,
  117. BT_TRIG_EN = BT_TRIG,
  118. RISCV_TRIG_EN = RISCV_TRIG,
  119. XTAL_DEAD_TRIG_EN = XTAL_DEAD_TRIG,
  120. RISCV_TRAP_TRIG_EN = RISCV_TRAP_TRIG,
  121. USB_TRIG_EN = USB_TRIG
  122. } WAKEUP_ENABLE;
  123. /**
  124. * @brief Get the reset reason for CPU.
  125. *
  126. * @param int cpu_no : CPU no.
  127. *
  128. * @return RESET_REASON
  129. */
  130. RESET_REASON rtc_get_reset_reason(int cpu_no);
  131. /**
  132. * @brief Get the wakeup cause for CPU.
  133. *
  134. * @param int cpu_no : CPU no.
  135. *
  136. * @return WAKEUP_REASON
  137. */
  138. WAKEUP_REASON rtc_get_wakeup_cause(void);
  139. /**
  140. * @brief Get CRC for Fast RTC Memory.
  141. *
  142. * @param uint32_t start_addr : 0 - 0x7ff for Fast RTC Memory.
  143. *
  144. * @param uint32_t crc_len : 0 - 0x7ff, 0 for 4 byte, 0x7ff for 0x2000 byte.
  145. *
  146. * @return uint32_t : CRC32 result
  147. */
  148. uint32_t calc_rtc_memory_crc(uint32_t start_addr, uint32_t crc_len);
  149. /**
  150. * @brief Set CRC of Fast RTC memory 0-0x7ff into RTC STORE7.
  151. *
  152. * @param None
  153. *
  154. * @return None
  155. */
  156. void set_rtc_memory_crc(void);
  157. /**
  158. * @brief Fetch entry from RTC memory and RTC STORE reg
  159. *
  160. * @param uint32_t * entry_addr : the address to save entry
  161. *
  162. * @param RESET_REASON reset_reason : reset reason this time
  163. *
  164. * @return None
  165. */
  166. void rtc_boot_control(uint32_t *entry_addr, RESET_REASON reset_reason);
  167. /**
  168. * @brief Software Reset digital core.
  169. *
  170. * It is not recommended to use this function in esp-idf, use
  171. * esp_restart() instead.
  172. *
  173. * @param None
  174. *
  175. * @return None
  176. */
  177. void software_reset(void);
  178. /**
  179. * @brief Software Reset digital core.
  180. *
  181. * It is not recommended to use this function in esp-idf, use
  182. * esp_restart() instead.
  183. *
  184. * @param int cpu_no : The CPU to reset, 0 for PRO CPU, 1 for APP CPU.
  185. *
  186. * @return None
  187. */
  188. void software_reset_cpu(int cpu_no);
  189. /**
  190. * @}
  191. */
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* _ROM_RTC_H_ */