ald_pmu.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file ald_pmu.h
  5. * @brief Header file of PMU module driver.
  6. *
  7. * @version V1.0
  8. * @date 04 Dec 2017
  9. * @author AE Team
  10. * @note
  11. *
  12. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  13. *
  14. ********************************************************************************
  15. */
  16. #ifndef __ALD_PMU_H__
  17. #define __ALD_PMU_H__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include "utils.h"
  22. #include "ald_syscfg.h"
  23. /** @addtogroup ES32FXXX_ALD
  24. * @{
  25. */
  26. /** @addtogroup PMU
  27. * @{
  28. */
  29. /** @defgroup PMU_Public_Macros PMU Public Macros
  30. * @{
  31. */
  32. #define PMU_SRAM0_ENABLE() \
  33. do { \
  34. SYSCFG_UNLOCK(); \
  35. SET_BIT(PMU->PWRCR, BIT(PMU_PWRCR_SRAM_POSS)); \
  36. SYSCFG_LOCK(); \
  37. } while (0)
  38. #define PMU_SRAM0_DISABLE() \
  39. do { \
  40. SYSCFG_UNLOCK(); \
  41. CLEAR_BIT(PMU->PWRCR, BIT(PMU_PWRCR_SRAM_POSS));\
  42. SYSCFG_LOCK(); \
  43. } while (0)
  44. #define PMU_SRAM1_ENABLE() \
  45. do { \
  46. SYSCFG_UNLOCK(); \
  47. SET_BIT(PMU->PWRCR, BIT(PMU_PWRCR_SRAM_POSE)); \
  48. SYSCFG_LOCK(); \
  49. } while (0)
  50. #define PMU_SRAM1_DISABLE() \
  51. do { \
  52. SYSCFG_UNLOCK(); \
  53. CLEAR_BIT(PMU->PWRCR, BIT(PMU_PWRCR_SRAM_POSE));\
  54. SYSCFG_LOCK(); \
  55. } while (0)
  56. #define PMU_BXCAN_ENABLE() \
  57. do { \
  58. SYSCFG_UNLOCK(); \
  59. SET_BIT(PMU->PWRCR, PMU_PWRCR_BXCAN_MSK); \
  60. SYSCFG_LOCK(); \
  61. } while (0)
  62. #define PMU_BXCAN_DISABLE() \
  63. do { \
  64. SYSCFG_UNLOCK(); \
  65. CLEAR_BIT(PMU->PWRCR, PMU_PWRCR_BXCAN_MSK); \
  66. SYSCFG_LOCK(); \
  67. } while (0)
  68. #define PMU_LPSTOP_ENABLE() \
  69. do { \
  70. SYSCFG_UNLOCK(); \
  71. SET_BIT(PMU->CR, PMU_CR_LPSTOP_MSK); \
  72. SYSCFG_LOCK(); \
  73. } while (0)
  74. #define PMU_LPSTOP_DISABLE() \
  75. do { \
  76. SYSCFG_UNLOCK(); \
  77. CLEAR_BIT(PMU->CR, PMU_CR_LPSTOP_MSK); \
  78. SYSCFG_LOCK(); \
  79. } while (0)
  80. #define PMU_MTSTOP_ENABLE() \
  81. do { \
  82. SYSCFG_UNLOCK(); \
  83. SET_BIT(PMU->CR, PMU_CR_MTSTOP_MSK); \
  84. SYSCFG_LOCK(); \
  85. } while (0)
  86. #define PMU_MTSTOP_DISABLE() \
  87. do { \
  88. SYSCFG_UNLOCK(); \
  89. CLEAR_BIT(PMU->CR, PMU_CR_MTSTOP_MSK); \
  90. SYSCFG_LOCK(); \
  91. } while (0)
  92. #define PMU_GET_LVD_STATUS() (READ_BITS(PMU->LVDCR, PMU_LVDCR_LVDO_MSK, PMU_LVDCR_LVDO_POS))
  93. /**
  94. * @}
  95. */
  96. /** @defgroup PMU_Public_Types PMU Public Types
  97. * @{
  98. */
  99. /**
  100. * @brief Standby wakeup port select
  101. */
  102. typedef enum {
  103. PMU_STANDBY_PORT_SEL_PA0 = 0x0, /**< PA0 */
  104. PMU_STANDBY_PORT_SEL_PA1 = 0x1, /**< PA1 */
  105. PMU_STANDBY_PORT_SEL_PA2 = 0x2, /**< PA2 */
  106. PMU_STANDBY_PORT_SEL_PA3 = 0x3, /**< PA3 */
  107. PMU_STANDBY_PORT_SEL_PA4 = 0x4, /**< PA4 */
  108. PMU_STANDBY_PORT_SEL_PA5 = 0x5, /**< PA5 */
  109. PMU_STANDBY_PORT_SEL_PA6 = 0x6, /**< PA6 */
  110. PMU_STANDBY_PORT_SEL_PA7 = 0x7, /**< PA7 */
  111. PMU_STANDBY_PORT_NONE = 0xF, /**< NONE */
  112. } pmu_standby_wakeup_sel_t;
  113. /**
  114. * @brief Low power mode
  115. */
  116. typedef enum {
  117. PMU_LP_STOP1 = 0x0, /**< Stop1 */
  118. PMU_LP_STOP2 = 0x1, /**< Stop2 */
  119. PMU_LP_STANDBY = 0x2, /**< Standby */
  120. } pmu_lp_mode_t;
  121. typedef enum {
  122. PMU_SR_WUF = (1U << 0),
  123. PMU_SR_STANDBYF = (1U << 1),
  124. } pmu_status_t;
  125. /**
  126. * @brief LVD voltage select
  127. */
  128. typedef enum {
  129. PMU_LVD_VOL_SEL_2_0 = 0x0, /**< 2.0V ~ 2.05V */
  130. PMU_LVD_VOL_SEL_2_1 = 0x1, /**< 2.1V ~ 2.15V */
  131. PMU_LVD_VOL_SEL_2_2 = 0x2, /**< 2.2V ~ 2.25V */
  132. PMU_LVD_VOL_SEL_2_4 = 0x3, /**< 2.4V ~ 2.45V */
  133. PMU_LVD_VOL_SEL_2_6 = 0x4, /**< 2.6V ~ 2.65V */
  134. PMU_LVD_VOL_SEL_2_8 = 0x5, /**< 2.8V ~ 2.85V */
  135. PMU_LVD_VOL_SEL_3_0 = 0x6, /**< 3.0V ~ 3.05V */
  136. PMU_LVD_VOL_SEL_3_6 = 0x7, /**< 3.6V ~ 3.65V */
  137. PMU_LVD_VOL_SEL_4_0 = 0x8, /**< 4.0V ~ 4.05V */
  138. PMU_LVD_VOL_SEL_4_6 = 0x9, /**< 4.6V ~ 4.65V */
  139. PMU_LVD_VOL_SEL_2_3 = 0xA, /**< 2.3V ~ 2.35V */
  140. PMU_LVD_VOL_SEL_EXT = 0xF, /**< Select external input. It must be 1.2V */
  141. } pmu_lvd_voltage_sel_t;
  142. /**
  143. * @brief LVD trigger mode
  144. */
  145. typedef enum {
  146. PMU_LVD_TRIGGER_RISING_EDGE = 0x0, /**< Rising edge */
  147. PMU_LVD_TRIGGER_FALLING_EDGE = 0x1, /**< Falling edge */
  148. PMU_LVD_TRIGGER_HIGH_LEVEL = 0x2, /**< High level */
  149. PMU_LVD_TRIGGER_LOW_LEVEL = 0x3, /**< Low level */
  150. PMU_LVD_TRIGGER_RISING_FALLING = 0x4, /**< Rising and falling edge */
  151. } pmu_lvd_trigger_mode_t;
  152. /**
  153. * @brief LDO output voltage selest in low power mode
  154. */
  155. typedef enum {
  156. PMU_LDO_LPMODE_OUTPUT_1_5 = 0x0, /**< 1.5V */
  157. PMU_LDO_LPMODE_OUTPUT_1_4 = 0x1, /**< 1.4V */
  158. PMU_LDO_LPMODE_OUTPUT_1_3 = 0x2, /**< 1.3V */
  159. PMU_LDO_LPMODE_OUTPUT_1_2 = 0x4, /**< 1.2V */
  160. } pmu_ldo_lpmode_output_t;
  161. /**
  162. * @}
  163. */
  164. /**
  165. * @defgroup PMU_Private_Macros PMU Private Macros
  166. * @{
  167. */
  168. #define IS_PMU_STANDBY_PORT_SEL(x) (((x) == PMU_STANDBY_PORT_SEL_PA0) || \
  169. ((x) == PMU_STANDBY_PORT_SEL_PA1) || \
  170. ((x) == PMU_STANDBY_PORT_SEL_PA2) || \
  171. ((x) == PMU_STANDBY_PORT_SEL_PA3) || \
  172. ((x) == PMU_STANDBY_PORT_SEL_PA4) || \
  173. ((x) == PMU_STANDBY_PORT_SEL_PA5) || \
  174. ((x) == PMU_STANDBY_PORT_SEL_PA6) || \
  175. ((x) == PMU_STANDBY_PORT_SEL_PA7) || \
  176. ((x) == PMU_STANDBY_PORT_NONE))
  177. #define IS_PMU_LP_MODE(x) (((x) == PMU_LP_STOP1) || \
  178. ((x) == PMU_LP_STOP2) || \
  179. ((x) == PMU_LP_STANDBY))
  180. #define IS_PMU_STATUS(x) (((x) == PMU_SR_WUF) || \
  181. ((x) == PMU_SR_STANDBYF))
  182. #define IS_PMU_LVD_VOL_SEL(x) (((x) == PMU_LVD_VOL_SEL_2_0) || \
  183. ((x) == PMU_LVD_VOL_SEL_2_1) || \
  184. ((x) == PMU_LVD_VOL_SEL_2_2) || \
  185. ((x) == PMU_LVD_VOL_SEL_2_4) || \
  186. ((x) == PMU_LVD_VOL_SEL_2_6) || \
  187. ((x) == PMU_LVD_VOL_SEL_2_8) || \
  188. ((x) == PMU_LVD_VOL_SEL_3_0) || \
  189. ((x) == PMU_LVD_VOL_SEL_3_6) || \
  190. ((x) == PMU_LVD_VOL_SEL_4_0) || \
  191. ((x) == PMU_LVD_VOL_SEL_4_6) || \
  192. ((x) == PMU_LVD_VOL_SEL_2_3) || \
  193. ((x) == PMU_LVD_VOL_SEL_EXT))
  194. #define IS_PMU_LVD_TRIGGER_MODE(x) (((x) == PMU_LVD_TRIGGER_RISING_EDGE) || \
  195. ((x) == PMU_LVD_TRIGGER_FALLING_EDGE) || \
  196. ((x) == PMU_LVD_TRIGGER_HIGH_LEVEL) || \
  197. ((x) == PMU_LVD_TRIGGER_LOW_LEVEL) || \
  198. ((x) == PMU_LVD_TRIGGER_RISING_FALLING))
  199. #define IS_PMU_LDO_LPMODE_OUTPUT(x) (((x) == PMU_LDO_LPMODE_OUTPUT_1_5) || \
  200. ((x) == PMU_LDO_LPMODE_OUTPUT_1_4) || \
  201. ((x) == PMU_LDO_LPMODE_OUTPUT_1_3) || \
  202. ((x) == PMU_LDO_LPMODE_OUTPUT_1_2))
  203. /**
  204. * @}
  205. */
  206. /** @addtogroup PMU_Public_Functions
  207. * @{
  208. */
  209. /** @addtogroup PMU_Public_Functions_Group1
  210. * @{
  211. */
  212. /* Low power mode select */
  213. __STATIC_INLINE__ void __sleep()
  214. {
  215. __WFI();
  216. }
  217. __STATIC_INLINE__ void __sleep_deep()
  218. {
  219. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  220. __WFI();
  221. }
  222. void pmu_stop1_enter(void);
  223. void pmu_stop2_enter(void);
  224. void pmu_standby_enter(pmu_standby_wakeup_sel_t port);
  225. void pmu_lprun_config(pmu_ldo_lpmode_output_t vol, type_func_t state);
  226. flag_status_t pmu_get_status(pmu_status_t sr);
  227. void pmu_clear_status(pmu_status_t sr);
  228. /**
  229. * @}
  230. */
  231. /** @addtogroup PMU_Public_Functions_Group2
  232. * @{
  233. */
  234. /* LVD configure */
  235. void pmu_lvd_config(pmu_lvd_voltage_sel_t sel, pmu_lvd_trigger_mode_t mode, type_func_t state);
  236. void lvd_irq_cbk(void);
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @}
  245. */
  246. /**
  247. * @}
  248. */
  249. #ifdef __cplusplus
  250. }
  251. #endif
  252. #endif /* __ALD_PMU_H__ */