rtc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // Copyright 2010-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ROM_RTC_H_
  14. #define _ROM_RTC_H_
  15. #include "ets_sys.h"
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include "soc/soc.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** \defgroup rtc_apis, rtc registers and memory related apis
  23. * @brief rtc apis
  24. */
  25. /** @addtogroup rtc_apis
  26. * @{
  27. */
  28. /**************************************************************************************
  29. * Note: *
  30. * Some Rtc memory and registers are used, in ROM or in internal library. *
  31. * Please do not use reserved or used rtc memory or registers. *
  32. * *
  33. *************************************************************************************
  34. * RTC Memory & Store Register usage
  35. *************************************************************************************
  36. * rtc memory addr type size usage
  37. * 0x3ff61000(0x50000000) Slow SIZE_CP Co-Processor code/Reset Entry
  38. * 0x3ff61000+SIZE_CP Slow 4096-SIZE_CP
  39. * 0x3ff62800 Slow 4096 Reserved
  40. *
  41. * 0x3ff80000(0x400c0000) Fast 8192 deep sleep entry code
  42. *
  43. *************************************************************************************
  44. * RTC store registers usage
  45. * RTC_CNTL_STORE0_REG Reserved
  46. * RTC_CNTL_STORE1_REG RTC_SLOW_CLK calibration value
  47. * RTC_CNTL_STORE2_REG Boot time, low word
  48. * RTC_CNTL_STORE3_REG Boot time, high word
  49. * RTC_CNTL_STORE4_REG External XTAL frequency
  50. * RTC_CNTL_STORE5_REG APB bus frequency
  51. * RTC_CNTL_STORE6_REG FAST_RTC_MEMORY_ENTRY
  52. * RTC_CNTL_STORE7_REG FAST_RTC_MEMORY_CRC
  53. *************************************************************************************
  54. */
  55. #define RTC_SLOW_CLK_CAL_REG RTC_CNTL_STORE1_REG
  56. #define RTC_BOOT_TIME_LOW_REG RTC_CNTL_STORE2_REG
  57. #define RTC_BOOT_TIME_HIGH_REG RTC_CNTL_STORE3_REG
  58. #define RTC_XTAL_FREQ_REG RTC_CNTL_STORE4_REG
  59. #define RTC_APB_FREQ_REG RTC_CNTL_STORE5_REG
  60. #define RTC_ENTRY_ADDR_REG RTC_CNTL_STORE6_REG
  61. #define RTC_MEMORY_CRC_REG RTC_CNTL_STORE7_REG
  62. typedef enum {
  63. AWAKE = 0, //<CPU ON
  64. LIGHT_SLEEP = BIT0, //CPU waiti, PLL ON. We don't need explicitly set this mode.
  65. DEEP_SLEEP = BIT1 //CPU OFF, PLL OFF, only specific timer could wake up
  66. } SLEEP_MODE;
  67. typedef enum {
  68. NO_MEAN = 0,
  69. POWERON_RESET = 1, /**<1, Vbat power on reset*/
  70. SW_RESET = 3, /**<3, Software reset digital core*/
  71. OWDT_RESET = 4, /**<4, Legacy watch dog reset digital core*/
  72. DEEPSLEEP_RESET = 5, /**<3, Deep Sleep reset digital core*/
  73. SDIO_RESET = 6, /**<6, Reset by SLC module, reset digital core*/
  74. TG0WDT_SYS_RESET = 7, /**<7, Timer Group0 Watch dog reset digital core*/
  75. TG1WDT_SYS_RESET = 8, /**<8, Timer Group1 Watch dog reset digital core*/
  76. RTCWDT_SYS_RESET = 9, /**<9, RTC Watch dog Reset digital core*/
  77. INTRUSION_RESET = 10, /**<10, Instrusion tested to reset CPU*/
  78. TGWDT_CPU_RESET = 11, /**<11, Time Group reset CPU*/
  79. SW_CPU_RESET = 12, /**<12, Software reset CPU*/
  80. RTCWDT_CPU_RESET = 13, /**<13, RTC Watch dog Reset CPU*/
  81. EXT_CPU_RESET = 14, /**<14, for APP CPU, reseted by PRO 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. } RESET_REASON;
  85. typedef enum {
  86. NO_SLEEP = 0,
  87. EXT_EVENT0_TRIG = BIT0,
  88. EXT_EVENT1_TRIG = BIT1,
  89. GPIO_TRIG = BIT2,
  90. TIMER_EXPIRE = BIT3,
  91. SDIO_TRIG = BIT4,
  92. MAC_TRIG = BIT5,
  93. UART0_TRIG = BIT6,
  94. UART1_TRIG = BIT7,
  95. TOUCH_TRIG = BIT8,
  96. SAR_TRIG = BIT9,
  97. BT_TRIG = BIT10
  98. } WAKEUP_REASON;
  99. typedef enum {
  100. DISEN_WAKEUP = NO_SLEEP,
  101. EXT_EVENT0_TRIG_EN = EXT_EVENT0_TRIG,
  102. EXT_EVENT1_TRIG_EN = EXT_EVENT1_TRIG,
  103. GPIO_TRIG_EN = GPIO_TRIG,
  104. TIMER_EXPIRE_EN = TIMER_EXPIRE,
  105. SDIO_TRIG_EN = SDIO_TRIG,
  106. MAC_TRIG_EN = MAC_TRIG,
  107. UART0_TRIG_EN = UART0_TRIG,
  108. UART1_TRIG_EN = UART1_TRIG,
  109. TOUCH_TRIG_EN = TOUCH_TRIG,
  110. SAR_TRIG_EN = SAR_TRIG,
  111. BT_TRIG_EN = BT_TRIG
  112. } WAKEUP_ENABLE;
  113. typedef enum {
  114. NO_INT = 0,
  115. WAKEUP_INT = BIT0,
  116. REJECT_INT = BIT1,
  117. SDIO_IDLE_INT = BIT2,
  118. RTC_WDT_INT = BIT3,
  119. RTC_TIME_VALID_INT = BIT4
  120. } RTC_INT_REASON;
  121. typedef enum {
  122. DISEN_INT = 0,
  123. WAKEUP_INT_EN = WAKEUP_INT,
  124. REJECT_INT_EN = REJECT_INT,
  125. SDIO_IDLE_INT_EN = SDIO_IDLE_INT,
  126. RTC_WDT_INT_EN = RTC_WDT_INT,
  127. RTC_TIME_VALID_INT_EN = RTC_TIME_VALID_INT
  128. } RTC_INT_EN;
  129. /**
  130. * @brief Get the reset reason for CPU.
  131. *
  132. * @param int cpu_no : CPU no.
  133. *
  134. * @return RESET_REASON
  135. */
  136. RESET_REASON rtc_get_reset_reason(int cpu_no);
  137. /**
  138. * @brief Get the wakeup cause for CPU.
  139. *
  140. * @param int cpu_no : CPU no.
  141. *
  142. * @return WAKEUP_REASON
  143. */
  144. WAKEUP_REASON rtc_get_wakeup_cause(void);
  145. /**
  146. * @brief Get CRC for Fast RTC Memory.
  147. *
  148. * @param uint32_t start_addr : 0 - 0x7ff for Fast RTC Memory.
  149. *
  150. * @param uint32_t crc_len : 0 - 0x7ff, 0 for 4 byte, 0x7ff for 0x2000 byte.
  151. *
  152. * @return uint32_t : CRC32 result
  153. */
  154. uint32_t calc_rtc_memory_crc(uint32_t start_addr, uint32_t crc_len);
  155. /**
  156. * @brief Set CRC of Fast RTC memory 0-0x7ff into RTC STORE7.
  157. *
  158. * @param None
  159. *
  160. * @return None
  161. */
  162. void set_rtc_memory_crc(void);
  163. /**
  164. * @brief Software Reset digital core.
  165. *
  166. * It is not recommended to use this function in esp-idf, use
  167. * esp_restart() instead.
  168. *
  169. * @param None
  170. *
  171. * @return None
  172. */
  173. void software_reset(void);
  174. /**
  175. * @brief Software Reset digital core.
  176. *
  177. * It is not recommended to use this function in esp-idf, use
  178. * esp_restart() instead.
  179. *
  180. * @param int cpu_no : The CPU to reset, 0 for PRO CPU, 1 for APP CPU.
  181. *
  182. * @return None
  183. */
  184. void software_reset_cpu(int cpu_no);
  185. /**
  186. * @}
  187. */
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* _ROM_RTC_H_ */