1 /***************************************************************************//**
\r
3 * @brief Energy management unit (EMU) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
34 #ifndef __SILICON_LABS_EM_EMU_H__
\r
35 #define __SILICON_LABS_EM_EMU_H__
\r
37 #include "em_device.h"
\r
38 #if defined( EMU_PRESENT )
\r
40 #include <stdbool.h>
\r
41 #include "em_bitband.h"
\r
47 /***************************************************************************//**
\r
48 * @addtogroup EM_Library
\r
50 ******************************************************************************/
\r
52 /***************************************************************************//**
\r
55 ******************************************************************************/
\r
57 /*******************************************************************************
\r
58 ******************************** ENUMS ************************************
\r
59 ******************************************************************************/
\r
63 /** Enable EM2 and 3 voltage regulator reduced drive strength (reduced leakage current) */
\r
64 #if defined( _EMU_CTRL_EM23VREG_MASK )
\r
65 emuEM23Vreg_REDUCED = EMU_CTRL_EM23VREG_REDUCED,
\r
66 #elif defined( _EMU_CTRL_EMVREG_MASK )
\r
67 emuEM23Vreg_REDUCED = EMU_CTRL_EMVREG_REDUCED,
\r
69 /** Enable EM2 and 3 voltage regulator full drive strength (faster startup) */
\r
70 #if defined( _EMU_CTRL_EM23VREG_MASK )
\r
71 emuEM23Vreg_FULL = EMU_CTRL_EM23VREG_FULL,
\r
72 #elif defined( _EMU_CTRL_EMVREG_MASK )
\r
73 emuEM23Vreg_FULL = EMU_CTRL_EMVREG_FULL,
\r
77 #if defined( _EMU_EM4CONF_OSC_MASK )
\r
78 /** EM4 duty oscillator */
\r
81 /** Select ULFRCO as duty oscillator in EM4 */
\r
82 emuEM4Osc_ULFRCO = EMU_EM4CONF_OSC_ULFRCO,
\r
83 /** Select LFXO as duty oscillator in EM4 */
\r
84 emuEM4Osc_LFXO = EMU_EM4CONF_OSC_LFXO,
\r
85 /** Select LFRCO as duty oscillator in EM4 */
\r
86 emuEM4Osc_LFRCO = EMU_EM4CONF_OSC_LFRCO
\r
87 } EMU_EM4Osc_TypeDef;
\r
90 #if defined( _EMU_BUCTRL_PROBE_MASK )
\r
91 /** Backup Power Voltage Probe types */
\r
94 /** Disable voltage probe */
\r
95 emuProbe_Disable = EMU_BUCTRL_PROBE_DISABLE,
\r
96 /** Connect probe to VDD_DREG */
\r
97 emuProbe_VDDDReg = EMU_BUCTRL_PROBE_VDDDREG,
\r
98 /** Connect probe to BU_IN */
\r
99 emuProbe_BUIN = EMU_BUCTRL_PROBE_BUIN,
\r
100 /** Connect probe to BU_OUT */
\r
101 emuProbe_BUOUT = EMU_BUCTRL_PROBE_BUOUT
\r
102 } EMU_Probe_TypeDef;
\r
105 #if defined( _EMU_PWRCONF_PWRRES_MASK )
\r
106 /** Backup Power Domain resistor selection */
\r
109 /** Main power and backup power connected with RES0 series resistance */
\r
110 emuRes_Res0 = EMU_PWRCONF_PWRRES_RES0,
\r
111 /** Main power and backup power connected with RES1 series resistance */
\r
112 emuRes_Res1 = EMU_PWRCONF_PWRRES_RES1,
\r
113 /** Main power and backup power connected with RES2 series resistance */
\r
114 emuRes_Res2 = EMU_PWRCONF_PWRRES_RES2,
\r
115 /** Main power and backup power connected with RES3 series resistance */
\r
116 emuRes_Res3 = EMU_PWRCONF_PWRRES_RES3,
\r
117 } EMU_Resistor_TypeDef;
\r
120 #if defined( BU_PRESENT )
\r
121 /** Backup Power Domain power connection */
\r
124 /** No connection between main and backup power */
\r
125 emuPower_None = EMU_BUINACT_PWRCON_NONE,
\r
126 /** Main power and backup power connected through diode,
\r
127 allowing current from backup to main only */
\r
128 emuPower_BUMain = EMU_BUINACT_PWRCON_BUMAIN,
\r
129 /** Main power and backup power connected through diode,
\r
130 allowing current from main to backup only */
\r
131 emuPower_MainBU = EMU_BUINACT_PWRCON_MAINBU,
\r
132 /** Main power and backup power connected without diode */
\r
133 emuPower_NoDiode = EMU_BUINACT_PWRCON_NODIODE,
\r
134 } EMU_Power_TypeDef;
\r
137 /** BOD threshold setting selector, active or inactive mode */
\r
140 /** Configure BOD threshold for active mode */
\r
142 /** Configure BOD threshold for inactive mode */
\r
143 emuBODMode_Inactive,
\r
144 } EMU_BODMode_TypeDef;
\r
148 /*******************************************************************************
\r
149 ******************************* STRUCTS ***********************************
\r
150 ******************************************************************************/
\r
152 /** Energy Mode 2 and 3 initialization structure */
\r
156 } EMU_EM23Init_TypeDef;
\r
158 /** Default initialization of EM2 and 3 configuration */
\r
159 #define EMU_EM23INIT_DEFAULT \
\r
160 { false } /* Reduced voltage regulator drive strength in EM2 and EM3 */
\r
163 /** Energy Mode 4 initialization structure */
\r
166 /* Init parameters for platforms with EMU->EM4CONF register */
\r
167 #if defined( _EMU_EM4CONF_MASK )
\r
168 bool lockConfig; /** Lock configuration of regulator, BOD and oscillator */
\r
169 bool buBodRstDis; /** When set, no reset will be asserted due to Brownout when in EM4 */
\r
170 EMU_EM4Osc_TypeDef osc; /** EM4 duty oscillator */
\r
171 bool buRtcWakeup; /** Wake up on EM4 BURTC interrupt */
\r
172 bool vreg; /** Enable EM4 voltage regulator */
\r
174 bool reserved; /** Placeholder for empty structs */
\r
176 } EMU_EM4Init_TypeDef;
\r
178 /** Default initialization of EM4 configuration */
\r
179 #if defined( _EMU_EM4CONF_MASK )
\r
180 #define EMU_EM4INIT_DEFAULT \
\r
181 { false, /* Dont't lock configuration after it's been set */ \
\r
182 false, /* No reset will be asserted due to Brownout when in EM4 */ \
\r
183 emuEM4Osc_ULFRCO, /* Use default ULFRCO oscillator */ \
\r
184 true, /* Wake up on EM4 BURTC interrupt */ \
\r
185 true, /* Enable VREG */ \
\r
188 #define EMU_EM4INIT_DEFAULT \
\r
189 { false, /* Placeholder default value */ \
\r
194 #if defined( BU_PRESENT )
\r
195 /** Backup Power Domain Initialization structure */
\r
198 /* Backup Power Domain power configuration */
\r
200 /** Voltage probe select, selects ADC voltage */
\r
201 EMU_Probe_TypeDef probe;
\r
202 /** Enable BOD calibration mode */
\r
204 /** Enable BU_STAT status pin for active BU mode */
\r
205 bool statusPinEnable;
\r
207 /* Backup Power Domain connection configuration */
\r
208 /** Power domain resistor */
\r
209 EMU_Resistor_TypeDef resistor;
\r
210 /** BU_VOUT strong enable */
\r
212 /** BU_VOUT medium enable */
\r
214 /** BU_VOUT weak enable */
\r
216 /** Power connection, when not in Backup Mode */
\r
217 EMU_Power_TypeDef inactivePower;
\r
218 /** Power connection, when in Backup Mode */
\r
219 EMU_Power_TypeDef activePower;
\r
220 /** Enable backup power domain, and release reset, enable BU_VIN pin */
\r
222 } EMU_BUPDInit_TypeDef;
\r
225 #define EMU_BUPDINIT_DEFAULT \
\r
226 { emuProbe_Disable, /* Do not enable voltage probe */ \
\r
227 false, /* Disable BOD calibration mode */ \
\r
228 false, /* Disable BU_STAT pin for backup mode indication */ \
\r
230 emuRes_Res0, /* RES0 series resistance between main and backup power */ \
\r
231 false, /* Don't enable strong switch */ \
\r
232 false, /* Don't enable medium switch */ \
\r
233 false, /* Don't enable weak switch */ \
\r
235 emuPower_None, /* No connection between main and backup power (inactive mode) */ \
\r
236 emuPower_None, /* No connection between main and backup power (active mode) */ \
\r
237 true /* Enable BUPD enter on BOD, enable BU_VIN pin, release BU reset */ \
\r
242 /*******************************************************************************
\r
243 ***************************** PROTOTYPES **********************************
\r
244 ******************************************************************************/
\r
246 /***************************************************************************//**
\r
248 * Enter energy mode 1 (EM1).
\r
249 ******************************************************************************/
\r
250 __STATIC_INLINE void EMU_EnterEM1(void)
\r
252 /* Just enter Cortex-M3 sleep mode */
\r
253 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
\r
257 void EMU_EM23Init(EMU_EM23Init_TypeDef *em23Init);
\r
258 #if defined( _EMU_EM4CONF_MASK )
\r
259 void EMU_EM4Init(EMU_EM4Init_TypeDef *em4Init);
\r
261 void EMU_EnterEM2(bool restore);
\r
262 void EMU_EnterEM3(bool restore);
\r
263 void EMU_EnterEM4(void);
\r
264 void EMU_MemPwrDown(uint32_t blocks);
\r
265 void EMU_UpdateOscConfig(void);
\r
266 #if defined( BU_PRESENT )
\r
267 void EMU_BUPDInit(EMU_BUPDInit_TypeDef *bupdInit);
\r
268 void EMU_BUThresholdSet(EMU_BODMode_TypeDef mode, uint32_t value);
\r
269 void EMU_BUThresRangeSet(EMU_BODMode_TypeDef mode, uint32_t value);
\r
273 #if defined( _EMU_IF_MASK )
\r
274 /***************************************************************************//**
\r
276 * Clear one or more pending EMU interrupts.
\r
279 * Pending EMU interrupt sources to clear. Use one or more valid
\r
280 * interrupt flags for the EMU module (EMU_IFC_nnn).
\r
281 ******************************************************************************/
\r
282 __STATIC_INLINE void EMU_IntClear(uint32_t flags)
\r
288 /***************************************************************************//**
\r
290 * Disable one or more EMU interrupts.
\r
293 * EMU interrupt sources to disable. Use one or more valid
\r
294 * interrupt flags for the EMU module (EMU_IEN_nnn).
\r
295 ******************************************************************************/
\r
296 __STATIC_INLINE void EMU_IntDisable(uint32_t flags)
\r
298 EMU->IEN &= ~(flags);
\r
302 /***************************************************************************//**
\r
304 * Enable one or more EMU interrupts.
\r
307 * Depending on the use, a pending interrupt may already be set prior to
\r
308 * enabling the interrupt. Consider using EMU_IntClear() prior to enabling
\r
309 * if such a pending interrupt should be ignored.
\r
312 * EMU interrupt sources to enable. Use one or more valid
\r
313 * interrupt flags for the EMU module (EMU_IEN_nnn).
\r
314 ******************************************************************************/
\r
315 __STATIC_INLINE void EMU_IntEnable(uint32_t flags)
\r
321 /***************************************************************************//**
\r
323 * Get pending EMU interrupt flags.
\r
326 * The event bits are not cleared by the use of this function.
\r
329 * EMU interrupt sources pending. Returns one or more valid
\r
330 * interrupt flags for the EMU module (EMU_IF_nnn).
\r
331 ******************************************************************************/
\r
332 __STATIC_INLINE uint32_t EMU_IntGet(void)
\r
338 /***************************************************************************//**
\r
340 * Get enabled and pending EMU interrupt flags.
\r
341 * Useful for handling more interrupt sources in the same interrupt handler.
\r
344 * Interrupt flags are not cleared by the use of this function.
\r
347 * Pending and enabled EMU interrupt sources
\r
348 * The return value is the bitwise AND of
\r
349 * - the enabled interrupt sources in EMU_IEN and
\r
350 * - the pending interrupt flags EMU_IF
\r
351 ******************************************************************************/
\r
352 __STATIC_INLINE uint32_t EMU_IntGetEnabled(void)
\r
357 return EMU->IF & ien;
\r
361 /***************************************************************************//**
\r
363 * Set one or more pending EMU interrupts
\r
366 * EMU interrupt sources to set to pending. Use one or more valid
\r
367 * interrupt flags for the EMU module (EMU_IFS_nnn).
\r
368 ******************************************************************************/
\r
369 __STATIC_INLINE void EMU_IntSet(uint32_t flags)
\r
373 #endif /* _EMU_IF_MASK */
\r
376 #if defined( _EMU_EM4CONF_LOCKCONF_MASK )
\r
377 /***************************************************************************//**
\r
379 * Enable or disable EM4 lock configuration
\r
380 * @param[in] enable
\r
381 * If true, locks down EM4 configuration
\r
382 ******************************************************************************/
\r
383 __STATIC_INLINE void EMU_EM4Lock(bool enable)
\r
385 BITBAND_Peripheral(&(EMU->EM4CONF), _EMU_EM4CONF_LOCKCONF_SHIFT, enable);
\r
390 #if defined( _EMU_STATUS_BURDY_MASK )
\r
391 /***************************************************************************//**
\r
393 * Halts until backup power functionality is ready
\r
394 ******************************************************************************/
\r
395 __STATIC_INLINE void EMU_BUReady(void)
\r
397 while(!(EMU->STATUS & EMU_STATUS_BURDY));
\r
402 #if defined( _EMU_ROUTE_BUVINPEN_MASK )
\r
403 /***************************************************************************//**
\r
405 * Disable BU_VIN support
\r
406 * @param[in] enable
\r
407 * If true, enables BU_VIN input pin support, if false disables it
\r
408 ******************************************************************************/
\r
409 __STATIC_INLINE void EMU_BUPinEnable(bool enable)
\r
411 BITBAND_Peripheral(&(EMU->ROUTE), _EMU_ROUTE_BUVINPEN_SHIFT, enable);
\r
416 /***************************************************************************//**
\r
418 * Lock the EMU in order to protect all its registers against unintended
\r
422 * If locking the EMU registers, they must be unlocked prior to using any
\r
423 * EMU API functions modifying EMU registers. An exception to this is the
\r
424 * energy mode entering API (EMU_EnterEMn()), which can be used when the
\r
425 * EMU registers are locked.
\r
426 ******************************************************************************/
\r
427 __STATIC_INLINE void EMU_Lock(void)
\r
429 EMU->LOCK = EMU_LOCK_LOCKKEY_LOCK;
\r
433 /***************************************************************************//**
\r
435 * Unlock the EMU so that writing to locked registers again is possible.
\r
436 ******************************************************************************/
\r
437 __STATIC_INLINE void EMU_Unlock(void)
\r
439 EMU->LOCK = EMU_LOCK_LOCKKEY_UNLOCK;
\r
442 /***************************************************************************//**
\r
444 * Block entering EM2 or higher number energy modes.
\r
445 ******************************************************************************/
\r
446 __STATIC_INLINE void EMU_EM2Block(void)
\r
448 BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 1U);
\r
452 /***************************************************************************//**
\r
454 * Unblock entering EM2 or higher number energy modes.
\r
455 ******************************************************************************/
\r
456 __STATIC_INLINE void EMU_EM2UnBlock(void)
\r
458 BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 0U);
\r
462 /** @} (end addtogroup EMU) */
\r
463 /** @} (end addtogroup EM_Library) */
\r
469 #endif /* defined( EMU_PRESENT ) */
\r
470 #endif /* __EM_EMU_H */
\r