efm32_emu.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Energy management unit (EMU) peripheral API for EFM32.
  4. * @author Energy Micro AS
  5. * @version 2.3.2
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_EMU_H
  29. #define __EFM32_EMU_H
  30. #include <stdbool.h>
  31. #include "efm32.h"
  32. #include "efm32_bitband.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /***************************************************************************//**
  37. * @addtogroup EFM32_Library
  38. * @{
  39. ******************************************************************************/
  40. /***************************************************************************//**
  41. * @addtogroup EMU
  42. * @{
  43. ******************************************************************************/
  44. /*******************************************************************************
  45. ******************************** ENUMS ************************************
  46. ******************************************************************************/
  47. #if defined(_EFM32_GIANT_FAMILY)
  48. /** EM4 duty oscillator */
  49. typedef enum
  50. {
  51. /** Select ULFRCO as duty oscillator in EM4 */
  52. emuEM4Osc_ULFRCO = EMU_EM4CONF_OSC_ULFRCO,
  53. /** Select LFXO as duty oscillator in EM4 */
  54. emuEM4Osc_LFXO = EMU_EM4CONF_OSC_LFXO,
  55. /** Select LFRCO as duty oscillator in EM4 */
  56. emuEM4Osc_LFRCO = EMU_EM4CONF_OSC_LFRCO
  57. } EMU_EM4Osc_TypeDef;
  58. /** Backup Power Voltage Probe types */
  59. typedef enum
  60. {
  61. /** Disable voltage probe */
  62. emuProbe_Disable = EMU_BUCTRL_PROBE_DISABLE,
  63. /** Connect probe to VDD_DREG */
  64. emuProbe_VDDDReg = EMU_BUCTRL_PROBE_VDDDREG,
  65. /** Connect probe to BU_IN */
  66. emuProbe_BUIN = EMU_BUCTRL_PROBE_BUIN,
  67. /** Connect probe to BU_OUT */
  68. emuProbe_BUOUT = EMU_BUCTRL_PROBE_BUOUT
  69. } EMU_Probe_TypeDef;
  70. /** Backup Power Domain resistor selection */
  71. typedef enum
  72. {
  73. /** Main power and backup power connected with RES0 series resistance */
  74. emuRes_Res0 = EMU_PWRCONF_PWRRES_RES0,
  75. /** Main power and backup power connected with RES1 series resistance */
  76. emuRes_Res1 = EMU_PWRCONF_PWRRES_RES1,
  77. /** Main power and backup power connected with RES2 series resistance */
  78. emuRes_Res2 = EMU_PWRCONF_PWRRES_RES2,
  79. /** Main power and backup power connected with RES3 series resistance */
  80. emuRes_Res3 = EMU_PWRCONF_PWRRES_RES3,
  81. } EMU_Resistor_TypeDef;
  82. /** Backup Power Domain power connection */
  83. typedef enum
  84. {
  85. /** No connection between main and backup power */
  86. emuPower_None = EMU_BUINACT_PWRCON_NONE,
  87. /** Main power and backup power connected through diode,
  88. allowing current from backup to main only */
  89. emuPower_BUMain = EMU_BUINACT_PWRCON_BUMAIN,
  90. /** Main power and backup power connected through diode,
  91. allowing current from main to backup only */
  92. emuPower_MainBU = EMU_BUINACT_PWRCON_MAINBU,
  93. /** Main power and backup power connected without diode */
  94. emuPower_NoDiode = EMU_BUINACT_PWRCON_NODIODE,
  95. } EMU_Power_TypeDef;
  96. #endif
  97. /*******************************************************************************
  98. ******************************* STRUCTS ***********************************
  99. ******************************************************************************/
  100. #if defined(_EFM32_GIANT_FAMILY)
  101. /** Energy Mode 4 initialization structure */
  102. typedef struct
  103. {
  104. /** Lock configuration of regulator, BOD and oscillator */
  105. bool lockConfig;
  106. /** EM4 duty oscillator */
  107. EMU_EM4Osc_TypeDef osc;
  108. /** Wake up on EM4 BURTC interrupt */
  109. bool buRtcWakeup;
  110. /** Enable EM4 voltage regulator */
  111. bool vreg;
  112. } EMU_EM4Init_TypeDef;
  113. /** Default initialization of EM4 configuration */
  114. #define EMU_EM4INIT_DEFAULT \
  115. { false, /* Dont't lock configuration after it's been set */ \
  116. emuEM4Osc_ULFRCO, /* Use default ULFRCO oscillator */ \
  117. true, /* Wake up on EM4 BURTC interrupt */ \
  118. true, /* Enable VREG */ \
  119. }
  120. /** Backup Power Domain Initialization structure */
  121. typedef struct
  122. {
  123. /* Backup Power Domain power configuration */
  124. /** Voltage probe select, selects ADC voltage */
  125. EMU_Probe_TypeDef probe;
  126. /** Enable BOD calibration mode */
  127. bool bodCal;
  128. /** Enable BU_STAT status pin for active BU mode */
  129. bool statusPinEnable;
  130. /* Backup Power Domain connection configuration */
  131. /** Power domain resistor */
  132. EMU_Resistor_TypeDef resistor;
  133. /** BU_VOUT strong enable */
  134. bool voutStrong;
  135. /** BU_VOUT medium enable */
  136. bool voutMed;
  137. /** BU_VOUT weak enable */
  138. bool voutWeak;
  139. /* Backup Power Domain inactive configuration */
  140. /** Power connection, when not in Backup Mode */
  141. EMU_Power_TypeDef inactivePower;
  142. /** Threshold range for backup BOD sensing on VDD_DREG, when not in Backup Mode */
  143. uint32_t inactiveThresRange;
  144. /** Threshold for backup BOD sesning on VDD_DREG, when not in Backup Mode */
  145. uint32_t inactiveThreshold;
  146. /* Backup Power Domain active configuration */
  147. /** Power connection, when in Backup Mode */
  148. EMU_Power_TypeDef activePower;
  149. /** Threshold range for backup BOD sensing when in Backup Mode */
  150. uint32_t activeThresRange;
  151. /** Threshold for backup BOD sesning on VDD_DREG, when in Backup Mode */
  152. uint32_t activeThreshold;
  153. /** Enable backup power domain, and release reset, enable BU_VIN pin */
  154. bool enable;
  155. } EMU_BUPDInit_TypeDef;
  156. /** Default */
  157. #define EMU_BUPDINIT_DEFAULT \
  158. { emuProbe_Disable, /* Do not enable voltage probe */ \
  159. false, /* Disable BOD calibration mode */ \
  160. false, /* Disable BU_STAT pin for backup mode indication */ \
  161. \
  162. emuRes_Res0, /* RES0 series resistance between main and backup power */ \
  163. false, /* Don't enable strong switch */ \
  164. false, /* Don't enable medium switch */ \
  165. false, /* Don't enable weak switch */ \
  166. \
  167. emuPower_None, /* No connection between main and backup power (inactive mode) */ \
  168. 0, /* Default threshold range for backup BOD sense (inactive mode) */ \
  169. 0, /* Default threshold for backup BOD snese (inactive mode) */ \
  170. \
  171. emuPower_None, /* No connection between main and backup power (active mode) */ \
  172. 0, /* Default threshold range for backup BOD sense (active mode) */ \
  173. 0, /* Default threshold for backup BOD snese (active mode) */ \
  174. \
  175. true /* Enable BUPD enter on BOD, enable BU_VIN pin, release BU reset */ \
  176. }
  177. #endif
  178. /*******************************************************************************
  179. ***************************** PROTOTYPES **********************************
  180. ******************************************************************************/
  181. /***************************************************************************//**
  182. * @brief
  183. * Enter energy mode 1 (EM1).
  184. ******************************************************************************/
  185. static __INLINE void EMU_EnterEM1(void)
  186. {
  187. /* Just enter Cortex-M3 sleep mode */
  188. SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
  189. __WFI();
  190. }
  191. void EMU_EnterEM2(bool restore);
  192. void EMU_EnterEM3(bool restore);
  193. void EMU_EnterEM4(void);
  194. void EMU_MemPwrDown(uint32_t blocks);
  195. void EMU_UpdateOscConfig(void);
  196. #if defined(_EFM32_GIANT_FAMILY)
  197. void EMU_EM4Init(EMU_EM4Init_TypeDef *em4init);
  198. void EMU_BUPDInit(EMU_BUPDInit_TypeDef *budpdInit);
  199. /***************************************************************************//**
  200. * @brief
  201. * Disable BU_VIN support
  202. * @param[in] enable
  203. * If true, enables BU_VIN input pin support, if false disables it
  204. ******************************************************************************/
  205. static __INLINE void EMU_BUPinEnable(bool enable)
  206. {
  207. BITBAND_Peripheral(&(EMU->ROUTE), _EMU_ROUTE_BUVINPEN_SHIFT, enable);
  208. }
  209. #endif
  210. /***************************************************************************//**
  211. * @brief
  212. * Lock the EMU in order to protect all its registers against unintended
  213. * modification.
  214. *
  215. * @note
  216. * If locking the EMU registers, they must be unlocked prior to using any
  217. * EMU API functions modifying EMU registers. An exception to this is the
  218. * energy mode entering API (EMU_EnterEMn()), which can be used when the
  219. * EMU registers are locked.
  220. ******************************************************************************/
  221. static __INLINE void EMU_Lock(void)
  222. {
  223. EMU->LOCK = EMU_LOCK_LOCKKEY_LOCK;
  224. }
  225. /***************************************************************************//**
  226. * @brief
  227. * Unlock the EMU so that writing to locked registers again is possible.
  228. ******************************************************************************/
  229. static __INLINE void EMU_Unlock(void)
  230. {
  231. EMU->LOCK = EMU_LOCK_LOCKKEY_UNLOCK;
  232. }
  233. /***************************************************************************//**
  234. * @brief
  235. * Block entering EM2 or higher number energy modes.
  236. ******************************************************************************/
  237. static __INLINE void EMU_EM2Block(void)
  238. {
  239. BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 1U);
  240. }
  241. /***************************************************************************//**
  242. * @brief
  243. * Unblock entering EM2 or higher number energy modes.
  244. ******************************************************************************/
  245. static __INLINE void EMU_EM2UnBlock(void)
  246. {
  247. BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 0U);
  248. }
  249. /** @} (end addtogroup EMU) */
  250. /** @} (end addtogroup EFM32_Library) */
  251. #ifdef __cplusplus
  252. }
  253. #endif
  254. #endif /* __EFM32_EMU_H */