]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_emu.h
Add Pearl Gecko demo.
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_emu.h
1 /***************************************************************************//**\r
2  * @file em_emu.h\r
3  * @brief Energy management unit (EMU) peripheral API\r
4  * @version 4.2.1\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\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
13  *\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
19  *\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
26  *\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
30  *\r
31  ******************************************************************************/\r
32 \r
33 #ifndef __SILICON_LABS_EM_EMU_H__\r
34 #define __SILICON_LABS_EM_EMU_H__\r
35 \r
36 #include "em_device.h"\r
37 #if defined( EMU_PRESENT )\r
38 \r
39 #include <stdbool.h>\r
40 #include "em_bus.h"\r
41 \r
42 #ifdef __cplusplus\r
43 extern "C" {\r
44 #endif\r
45 \r
46 /***************************************************************************//**\r
47  * @addtogroup EM_Library\r
48  * @{\r
49  ******************************************************************************/\r
50 \r
51 /***************************************************************************//**\r
52  * @addtogroup EMU\r
53  * @{\r
54  ******************************************************************************/\r
55 \r
56 /*******************************************************************************\r
57  ********************************   ENUMS   ************************************\r
58  ******************************************************************************/\r
59 \r
60 #if defined( _EMU_EM4CONF_OSC_MASK )\r
61 /** EM4 duty oscillator */\r
62 typedef enum\r
63 {\r
64   /** Select ULFRCO as duty oscillator in EM4 */\r
65   emuEM4Osc_ULFRCO = EMU_EM4CONF_OSC_ULFRCO,\r
66   /** Select LFXO as duty oscillator in EM4 */\r
67   emuEM4Osc_LFXO = EMU_EM4CONF_OSC_LFXO,\r
68   /** Select LFRCO as duty oscillator in EM4 */\r
69   emuEM4Osc_LFRCO = EMU_EM4CONF_OSC_LFRCO\r
70 } EMU_EM4Osc_TypeDef;\r
71 #endif\r
72 \r
73 #if defined( _EMU_BUCTRL_PROBE_MASK )\r
74 /** Backup Power Voltage Probe types */\r
75 typedef enum\r
76 {\r
77   /** Disable voltage probe */\r
78   emuProbe_Disable = EMU_BUCTRL_PROBE_DISABLE,\r
79   /** Connect probe to VDD_DREG */\r
80   emuProbe_VDDDReg = EMU_BUCTRL_PROBE_VDDDREG,\r
81   /** Connect probe to BU_IN */\r
82   emuProbe_BUIN    = EMU_BUCTRL_PROBE_BUIN,\r
83   /** Connect probe to BU_OUT */\r
84   emuProbe_BUOUT   = EMU_BUCTRL_PROBE_BUOUT\r
85 } EMU_Probe_TypeDef;\r
86 #endif\r
87 \r
88 #if defined( _EMU_PWRCONF_PWRRES_MASK )\r
89 /** Backup Power Domain resistor selection */\r
90 typedef enum\r
91 {\r
92   /** Main power and backup power connected with RES0 series resistance */\r
93   emuRes_Res0 = EMU_PWRCONF_PWRRES_RES0,\r
94   /** Main power and backup power connected with RES1 series resistance */\r
95   emuRes_Res1 = EMU_PWRCONF_PWRRES_RES1,\r
96   /** Main power and backup power connected with RES2 series resistance */\r
97   emuRes_Res2 = EMU_PWRCONF_PWRRES_RES2,\r
98   /** Main power and backup power connected with RES3 series resistance */\r
99   emuRes_Res3 = EMU_PWRCONF_PWRRES_RES3,\r
100 } EMU_Resistor_TypeDef;\r
101 #endif\r
102 \r
103 #if defined( BU_PRESENT )\r
104 /** Backup Power Domain power connection */\r
105 typedef enum\r
106 {\r
107   /** No connection between main and backup power */\r
108   emuPower_None = EMU_BUINACT_PWRCON_NONE,\r
109   /** Main power and backup power connected through diode,\r
110       allowing current from backup to main only */\r
111   emuPower_BUMain = EMU_BUINACT_PWRCON_BUMAIN,\r
112   /** Main power and backup power connected through diode,\r
113       allowing current from main to backup only */\r
114   emuPower_MainBU = EMU_BUINACT_PWRCON_MAINBU,\r
115   /** Main power and backup power connected without diode */\r
116   emuPower_NoDiode = EMU_BUINACT_PWRCON_NODIODE,\r
117 } EMU_Power_TypeDef;\r
118 #endif\r
119 \r
120 /** BOD threshold setting selector, active or inactive mode */\r
121 typedef enum\r
122 {\r
123   /** Configure BOD threshold for active mode */\r
124   emuBODMode_Active,\r
125   /** Configure BOD threshold for inactive mode */\r
126   emuBODMode_Inactive,\r
127 } EMU_BODMode_TypeDef;\r
128 \r
129 #if defined( _EMU_EM4CTRL_EM4STATE_MASK )\r
130 /** EM4 modes */\r
131 typedef enum\r
132 {\r
133   /** EM4 Hibernate */\r
134   emuEM4Hibernate = EMU_EM4CTRL_EM4STATE_EM4H,\r
135   /** EM4 Shutoff */\r
136   emuEM4Shutoff = EMU_EM4CTRL_EM4STATE_EM4S,\r
137 } EMU_EM4State_TypeDef;\r
138 #endif\r
139 \r
140 \r
141 #if defined( _EMU_EM4CTRL_EM4IORETMODE_MASK )\r
142 typedef enum\r
143 {\r
144   /** No Retention: Pads enter reset state when entering EM4 */\r
145   emuPinRetentionDisable = EMU_EM4CTRL_EM4IORETMODE_DISABLE,\r
146   /** Retention through EM4: Pads enter reset state when exiting EM4 */\r
147   emuPinRetentionEm4Exit = EMU_EM4CTRL_EM4IORETMODE_EM4EXIT,\r
148   /** Retention through EM4 and wakeup: call EMU_UnlatchPinRetention() to\r
149       release pins from retention after EM4 wakeup */\r
150   emuPinRetentionLatch   = EMU_EM4CTRL_EM4IORETMODE_SWUNLATCH,\r
151 } EMU_EM4PinRetention_TypeDef;\r
152 #endif\r
153 \r
154 \r
155 #if defined( _EMU_PWRCFG_MASK )\r
156 /** Power configurations */\r
157 typedef enum\r
158 {\r
159   /** DCDC is connected to DVDD */\r
160   emuPowerConfig_DcdcToDvdd = EMU_PWRCFG_PWRCFG_DCDCTODVDD,\r
161 } EMU_PowerConfig_TypeDef;\r
162 #endif\r
163 \r
164 #if defined( _EMU_DCDCCTRL_MASK )\r
165 /** DCDC operating modes */\r
166 typedef enum\r
167 {\r
168   /** DCDC regulator bypass */\r
169   emuDcdcMode_Bypass = EMU_DCDCCTRL_DCDCMODE_BYPASS,\r
170   /** DCDC low-noise mode */\r
171   emuDcdcMode_LowNoise = EMU_DCDCCTRL_DCDCMODE_LOWNOISE,\r
172 } EMU_DcdcMode_TypeDef;\r
173 #endif\r
174 \r
175 #if defined( _EMU_PWRCTRL_MASK )\r
176 /** DCDC to DVDD mode analog peripheral power supply select */\r
177 typedef enum\r
178 {\r
179   /** Select AVDD as analog power supply. Typically lower noise, but less energy efficient. */\r
180   emuDcdcAnaPeripheralPower_AVDD = EMU_PWRCTRL_ANASW_AVDD,\r
181   /** Select DCDC (DVDD) as analog power supply. Typically more energy efficient, but more noise. */\r
182   emuDcdcAnaPeripheralPower_DCDC = EMU_PWRCTRL_ANASW_DVDD\r
183 } EMU_DcdcAnaPeripheralPower_TypeDef;\r
184 #endif\r
185 \r
186 #if defined( _EMU_DCDCMISCCTRL_MASK )\r
187 /** DCDC Low-noise efficiency mode */\r
188 typedef enum\r
189 {\r
190 #if defined( _EFM_DEVICE )\r
191   /** High efficiency mode */\r
192   emuDcdcLnHighEfficiency = 0,\r
193 #endif\r
194   /** Fast transient response mode */\r
195   emuDcdcLnFastTransient = EMU_DCDCMISCCTRL_LNFORCECCM,\r
196 } EMU_DcdcLnTransientMode_TypeDef;\r
197 #endif\r
198 \r
199 #if defined( _EMU_DCDCCTRL_MASK )\r
200 /** DCDC Low-noise RCO band select */\r
201 typedef enum\r
202 {\r
203   /** Set RCO to 3MHz */\r
204   EMU_DcdcLnRcoBand_3MHz = 0,\r
205   /** Set RCO to 4MHz */\r
206   EMU_DcdcLnRcoBand_4MHz = 1,\r
207   /** Set RCO to 5MHz */\r
208   EMU_DcdcLnRcoBand_5MHz = 2,\r
209   /** Set RCO to 6MHz */\r
210   EMU_DcdcLnRcoBand_6MHz = 3,\r
211   /** Set RCO to 7MHz */\r
212   EMU_DcdcLnRcoBand_7MHz = 4,\r
213   /** Set RCO to 8MHz */\r
214   EMU_DcdcLnRcoBand_8MHz = 5,\r
215   /** Set RCO to 9MHz */\r
216   EMU_DcdcLnRcoBand_9MHz = 6,\r
217   /** Set RCO to 10MHz */\r
218   EMU_DcdcLnRcoBand_10MHz = 7,\r
219 } EMU_DcdcLnRcoBand_TypeDef;\r
220 \r
221 #endif\r
222 \r
223 #if defined( EMU_STATUS_VMONRDY )\r
224 /** VMON channels */\r
225 typedef enum\r
226 {\r
227   emuVmonChannel_AVDD,\r
228   emuVmonChannel_ALTAVDD,\r
229   emuVmonChannel_DVDD,\r
230   emuVmonChannel_IOVDD0\r
231 } EMU_VmonChannel_TypeDef;\r
232 #endif /* EMU_STATUS_VMONRDY */\r
233 \r
234 /*******************************************************************************\r
235  *******************************   STRUCTS   ***********************************\r
236  ******************************************************************************/\r
237 \r
238 /** Energy Mode 2 and 3 initialization structure  */\r
239 typedef struct\r
240 {\r
241   bool em23VregFullEn;                  /**< Enable full VREG drive strength in EM2/3 */\r
242 } EMU_EM23Init_TypeDef;\r
243 \r
244 /** Default initialization of EM2 and 3 configuration */\r
245 #define EMU_EM23INIT_DEFAULT    \\r
246 { false }                               /* Reduced voltage regulator drive strength in EM2 and EM3 */\r
247 \r
248 \r
249 #if defined( _EMU_EM4CONF_MASK ) || defined( _EMU_EM4CTRL_MASK )\r
250 /** Energy Mode 4 initialization structure  */\r
251 typedef struct\r
252 {\r
253 #if defined( _EMU_EM4CONF_MASK )\r
254   /* Init parameters for platforms with EMU->EM4CONF register */\r
255   bool                  lockConfig;     /**< Lock configuration of regulator, BOD and oscillator */\r
256   bool                  buBodRstDis;    /**< When set, no reset will be asserted due to Brownout when in EM4 */\r
257   EMU_EM4Osc_TypeDef    osc;            /**< EM4 duty oscillator */\r
258   bool                  buRtcWakeup;    /**< Wake up on EM4 BURTC interrupt */\r
259   bool                  vreg;           /**< Enable EM4 voltage regulator */\r
260 \r
261 #elif defined( _EMU_EM4CTRL_MASK )\r
262   /* Init parameters for platforms with EMU->EM4CTRL register */\r
263   bool                        retainLfxo;       /**< Disable the LFXO upon EM4 entry */\r
264   bool                        retainLfrco;      /**< Disable the LFRCO upon EM4 entry */\r
265   bool                        retainUlfrco;     /**< Disable the ULFRCO upon EM4 entry */\r
266   EMU_EM4State_TypeDef        em4State;         /**< Hibernate or shutoff EM4 state */\r
267   EMU_EM4PinRetention_TypeDef pinRetentionMode; /**< EM4 pin retention mode */\r
268 #endif\r
269 } EMU_EM4Init_TypeDef;\r
270 #endif\r
271 \r
272 /** Default initialization of EM4 configuration */\r
273 #if defined( _EMU_EM4CONF_MASK )\r
274 #define EMU_EM4INIT_DEFAULT                                                                \\r
275 {                                                                                          \\r
276   false,                              /* Dont't lock configuration after it's been set */  \\r
277   false,                              /* No reset will be asserted due to Brownout when in EM4 */ \\r
278   emuEM4Osc_ULFRCO,                   /* Use default ULFRCO oscillator  */                 \\r
279   true,                               /* Wake up on EM4 BURTC interrupt */                 \\r
280   true,                               /* Enable VREG */                                    \\r
281 }\r
282 #endif\r
283 #if defined( _EMU_EM4CTRL_MASK )\r
284 #define EMU_EM4INIT_DEFAULT                                                                \\r
285 {                                                                                          \\r
286   false,                             /* Retain LFXO configuration upon EM4 entry */        \\r
287   false,                             /* Retain LFRCO configuration upon EM4 entry */       \\r
288   false,                             /* Retain ULFRCO configuration upon EM4 entry */      \\r
289   emuEM4Shutoff,                     /* Use EM4 shutoff state */                           \\r
290   emuPinRetentionDisable,            /* Do not retain pins in EM4 */                       \\r
291 }\r
292 #endif\r
293 \r
294 #if defined( BU_PRESENT )\r
295 /** Backup Power Domain Initialization structure */\r
296 typedef struct\r
297 {\r
298   /* Backup Power Domain power configuration */\r
299 \r
300   /** Voltage probe select, selects ADC voltage */\r
301   EMU_Probe_TypeDef     probe;\r
302   /** Enable BOD calibration mode */\r
303   bool                  bodCal;\r
304   /** Enable BU_STAT status pin for active BU mode */\r
305   bool                  statusPinEnable;\r
306 \r
307   /* Backup Power Domain connection configuration */\r
308   /** Power domain resistor */\r
309   EMU_Resistor_TypeDef  resistor;\r
310   /** BU_VOUT strong enable */\r
311   bool                  voutStrong;\r
312   /** BU_VOUT medium enable */\r
313   bool                  voutMed;\r
314   /** BU_VOUT weak enable */\r
315   bool                  voutWeak;\r
316   /** Power connection, when not in Backup Mode */\r
317   EMU_Power_TypeDef  inactivePower;\r
318   /** Power connection, when in Backup Mode */\r
319   EMU_Power_TypeDef     activePower;\r
320   /** Enable backup power domain, and release reset, enable BU_VIN pin  */\r
321   bool                  enable;\r
322 } EMU_BUPDInit_TypeDef;\r
323 \r
324 /** Default Backup Power Domain configuration */\r
325 #define EMU_BUPDINIT_DEFAULT                                              \\r
326 {                                                                         \\r
327   emuProbe_Disable, /* Do not enable voltage probe */                     \\r
328   false,            /* Disable BOD calibration mode */                    \\r
329   false,            /* Disable BU_STAT pin for backup mode indication */  \\r
330                                                                           \\r
331   emuRes_Res0,      /* RES0 series resistance between main and backup power */ \\r
332   false,            /* Don't enable strong switch */                           \\r
333   false,            /* Don't enable medium switch */                           \\r
334   false,            /* Don't enable weak switch */                             \\r
335                                                                                \\r
336   emuPower_None,    /* No connection between main and backup power (inactive mode) */     \\r
337   emuPower_None,    /* No connection between main and backup power (active mode) */       \\r
338   true              /* Enable BUPD enter on BOD, enable BU_VIN pin, release BU reset  */  \\r
339 }\r
340 #endif\r
341 \r
342 #if defined( _EMU_DCDCCTRL_MASK )\r
343 /** DCDC initialization structure */\r
344 typedef struct\r
345 {\r
346   EMU_PowerConfig_TypeDef powerConfig;                  /**< Device external power configuration */\r
347   EMU_DcdcMode_TypeDef dcdcMode;                        /**< DCDC regulator operating mode in EM0 */\r
348   uint16_t mVout;                                       /**< Target output voltage (mV) */\r
349   uint16_t em01LoadCurrent_mA;                          /**< Estimated average load current in EM0 (mA).\r
350                                                              This estimate is also used for EM1 optimization,\r
351                                                              so if EM1 current is expected to be higher than EM0,\r
352                                                              then this parameter should hold the higher EM1 current. */\r
353   uint16_t em234LoadCurrent_uA;                         /**< Estimated average load current in EM2 (uA).\r
354                                                              This estimate is also used for EM3 and 4 optimization,\r
355                                                              so if EM3 or 4 current is expected to be higher than EM2,\r
356                                                              then this parameter should hold the higher EM3 or 4 current. */\r
357   uint16_t maxCurrent_mA;                               /**< Maximum peak DCDC output current (mA).\r
358                                                              This can be set to the maximum for the power source,\r
359                                                              for example the maximum for a battery. */\r
360   EMU_DcdcAnaPeripheralPower_TypeDef anaPeripheralPower;/**< Select analog peripheral power in DCDC-to-DVDD mode */\r
361   EMU_DcdcLnTransientMode_TypeDef lnTransientMode;      /**< Low-noise transient mode */\r
362 \r
363 } EMU_DCDCInit_TypeDef;\r
364 \r
365 /** Default DCDC initialization */\r
366 #if defined( _EFM_DEVICE )\r
367 #define EMU_DCDCINIT_DEFAULT                                                                                    \\r
368 {                                                                                                               \\r
369   emuPowerConfig_DcdcToDvdd,     /* DCDC to DVDD */                                                             \\r
370   emuDcdcMode_LowNoise,          /* Low-niose mode in EM0 (can be set to LowPower on EFM32PG revB0) */          \\r
371   1800,                          /* Nominal output voltage for DVDD mode, 1.8V  */                              \\r
372   5,                             /* Nominal EM0 load current of less than 5mA */                                \\r
373   10,                            /* Nominal EM2/3 load current less than 10uA  */                               \\r
374   160,                           /* Maximum peak current of 160mA */                                            \\r
375   emuDcdcAnaPeripheralPower_DCDC,/* Select DCDC as analog power supply (lower power) */                         \\r
376   emuDcdcLnHighEfficiency,       /* Use low-noise high-efficiency mode (ignored if emuDcdcMode_LowPower) */     \\r
377 }\r
378 #else /* EFR32 device */\r
379 #define EMU_DCDCINIT_DEFAULT                                                                                    \\r
380 {                                                                                                               \\r
381   emuPowerConfig_DcdcToDvdd,     /* DCDC to DVDD */                                                             \\r
382   emuDcdcMode_LowNoise,          /* Low-niose mode in EM0 */                                                    \\r
383   1800,                          /* Nominal output voltage for DVDD mode, 1.8V  */                              \\r
384   15,                             /* Nominal EM0 load current of less than 5mA */                               \\r
385   10,                            /* Nominal EM2/3 load current less than 10uA  */                               \\r
386   160,                           /* Maximum peak current of 160mA */                                            \\r
387   emuDcdcAnaPeripheralPower_AVDD,/* Select AVDD as analog power supply (less noise) */                          \\r
388   emuDcdcLnFastTransient,        /* Use low-noise fast-transient mode */                                        \\r
389 }\r
390 #endif\r
391 \r
392 #endif\r
393 \r
394 #if defined( EMU_STATUS_VMONRDY )\r
395 /** VMON initialization structure */\r
396 typedef struct\r
397 {\r
398   EMU_VmonChannel_TypeDef channel;                 /**< VMON channel to configure */\r
399   int threshold;                                   /**< Trigger threshold (mV) */\r
400   bool riseWakeup;                                 /**< Wake up from EM4H on rising edge */\r
401   bool fallWakeup;                                 /**< Wake up from EM4H on falling edge */\r
402   bool enable;                                     /**< Enable VMON channel */\r
403   bool retDisable;                                 /**< Disable IO0 retention when voltage drops below threshold (IOVDD only) */\r
404 } EMU_VmonInit_TypeDef;\r
405 \r
406 /** Default VMON initialization structure */\r
407 #define EMU_VMONINIT_DEFAULT                                               \\r
408 {                                                                          \\r
409   emuVmonChannel_AVDD,          /* AVDD VMON channel */                    \\r
410   3200,                         /* 3.2 V threshold */                      \\r
411   false,                        /* Don't wake from EM4H on rising edge */  \\r
412   false,                        /* Don't wake from EM4H on falling edge */ \\r
413   true,                         /* Enable VMON channel */                  \\r
414   false                         /* Don't disable IO0 retention */          \\r
415 }\r
416 \r
417 /** VMON Hysteresis initialization structure */\r
418 typedef struct\r
419 {\r
420   EMU_VmonChannel_TypeDef channel;                     /**< VMON channel to configure */\r
421   int riseThreshold;                                   /**< Rising threshold (mV) */\r
422   int fallThreshold;                                   /**< Falling threshold (mV) */\r
423   bool riseWakeup;                                     /**< Wake up from EM4H on rising edge */\r
424   bool fallWakeup;                                     /**< Wake up from EM4H on falling edge */\r
425   bool enable;                                         /**< Enable VMON channel */\r
426 } EMU_VmonHystInit_TypeDef;\r
427 \r
428 /** Default VMON Hysteresis initialization structure */\r
429 #define EMU_VMONHYSTINIT_DEFAULT                                           \\r
430 {                                                                          \\r
431   emuVmonChannel_AVDD,          /* AVDD VMON channel */                    \\r
432   3200,                         /* 3.2 V rise threshold */                 \\r
433   3200,                         /* 3.2 V fall threshold */                 \\r
434   false,                        /* Don't wake from EM4H on rising edge */  \\r
435   false,                        /* Don't wake from EM4H on falling edge */ \\r
436   true                          /* Enable VMON channel */                  \\r
437 }\r
438 #endif /* EMU_STATUS_VMONRDY */\r
439 \r
440 /*******************************************************************************\r
441  *****************************   PROTOTYPES   **********************************\r
442  ******************************************************************************/\r
443 \r
444 /***************************************************************************//**\r
445  * @brief\r
446  *   Enter energy mode 1 (EM1).\r
447  ******************************************************************************/\r
448 __STATIC_INLINE void EMU_EnterEM1(void)\r
449 {\r
450   /* Enter sleep mode */\r
451   SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;\r
452   __WFI();\r
453 }\r
454 \r
455 void EMU_EM23Init(EMU_EM23Init_TypeDef *em23Init);\r
456 #if defined( _EMU_EM4CONF_MASK ) || defined( _EMU_EM4CTRL_MASK )\r
457 void EMU_EM4Init(EMU_EM4Init_TypeDef *em4Init);\r
458 #endif\r
459 void EMU_EnterEM2(bool restore);\r
460 void EMU_EnterEM3(bool restore);\r
461 void EMU_EnterEM4(void);\r
462 void EMU_MemPwrDown(uint32_t blocks);\r
463 void EMU_UpdateOscConfig(void);\r
464 #if defined( BU_PRESENT )\r
465 void EMU_BUPDInit(EMU_BUPDInit_TypeDef *bupdInit);\r
466 void EMU_BUThresholdSet(EMU_BODMode_TypeDef mode, uint32_t value);\r
467 void EMU_BUThresRangeSet(EMU_BODMode_TypeDef mode, uint32_t value);\r
468 #endif\r
469 #if defined( _EMU_DCDCCTRL_MASK )\r
470 bool EMU_DCDCInit(EMU_DCDCInit_TypeDef *dcdcInit);\r
471 void EMU_DCDCModeSet(EMU_DcdcMode_TypeDef dcdcMode);\r
472 bool EMU_DCDCOutputVoltageSet(uint32_t mV, bool setLpVoltage, bool setLnVoltage);\r
473 void EMU_DCDCOptimizeSlice(uint32_t mALoadCurrent);\r
474 void EMU_DCDCLnRcoBandSet(EMU_DcdcLnRcoBand_TypeDef band);\r
475 bool EMU_DCDCPowerOff(void);\r
476 #endif\r
477 #if defined( EMU_STATUS_VMONRDY )\r
478 void EMU_VmonInit(EMU_VmonInit_TypeDef *vmonInit);\r
479 void EMU_VmonHystInit(EMU_VmonHystInit_TypeDef *vmonInit);\r
480 void EMU_VmonEnable(EMU_VmonChannel_TypeDef channel, bool enable);\r
481 bool EMU_VmonChannelStatusGet(EMU_VmonChannel_TypeDef channel);\r
482 \r
483 /***************************************************************************//**\r
484  * @brief\r
485  *   Get the status of the voltage monitor (VMON).\r
486  *\r
487  * @return\r
488  *   Status of the VMON. True if all the enabled channels are ready, false if\r
489  *   one or more of the enabled channels are not ready.\r
490  ******************************************************************************/\r
491 __STATIC_INLINE bool EMU_VmonStatusGet(void)\r
492 {\r
493   return BUS_RegBitRead(&EMU->STATUS, _EMU_STATUS_VMONRDY_SHIFT);\r
494 }\r
495 #endif /* EMU_STATUS_VMONRDY */\r
496 \r
497 #if defined( _EMU_IF_MASK )\r
498 /***************************************************************************//**\r
499  * @brief\r
500  *   Clear one or more pending EMU interrupts.\r
501  *\r
502  * @param[in] flags\r
503  *   Pending EMU interrupt sources to clear. Use one or more valid\r
504  *   interrupt flags for the EMU module (EMU_IFC_nnn).\r
505  ******************************************************************************/\r
506 __STATIC_INLINE void EMU_IntClear(uint32_t flags)\r
507 {\r
508   EMU->IFC = flags;\r
509 }\r
510 \r
511 \r
512 /***************************************************************************//**\r
513  * @brief\r
514  *   Disable one or more EMU interrupts.\r
515  *\r
516  * @param[in] flags\r
517  *   EMU interrupt sources to disable. Use one or more valid\r
518  *   interrupt flags for the EMU module (EMU_IEN_nnn).\r
519  ******************************************************************************/\r
520 __STATIC_INLINE void EMU_IntDisable(uint32_t flags)\r
521 {\r
522   EMU->IEN &= ~flags;\r
523 }\r
524 \r
525 \r
526 /***************************************************************************//**\r
527  * @brief\r
528  *   Enable one or more EMU interrupts.\r
529  *\r
530  * @note\r
531  *   Depending on the use, a pending interrupt may already be set prior to\r
532  *   enabling the interrupt. Consider using EMU_IntClear() prior to enabling\r
533  *   if such a pending interrupt should be ignored.\r
534  *\r
535  * @param[in] flags\r
536  *   EMU interrupt sources to enable. Use one or more valid\r
537  *   interrupt flags for the EMU module (EMU_IEN_nnn).\r
538  ******************************************************************************/\r
539 __STATIC_INLINE void EMU_IntEnable(uint32_t flags)\r
540 {\r
541   EMU->IEN |= flags;\r
542 }\r
543 \r
544 \r
545 /***************************************************************************//**\r
546  * @brief\r
547  *   Get pending EMU interrupt flags.\r
548  *\r
549  * @note\r
550  *   The event bits are not cleared by the use of this function.\r
551  *\r
552  * @return\r
553  *   EMU interrupt sources pending. Returns one or more valid\r
554  *   interrupt flags for the EMU module (EMU_IF_nnn).\r
555  ******************************************************************************/\r
556 __STATIC_INLINE uint32_t EMU_IntGet(void)\r
557 {\r
558   return EMU->IF;\r
559 }\r
560 \r
561 \r
562 /***************************************************************************//**\r
563  * @brief\r
564  *   Get enabled and pending EMU interrupt flags.\r
565  *   Useful for handling more interrupt sources in the same interrupt handler.\r
566  *\r
567  * @note\r
568  *   Interrupt flags are not cleared by the use of this function.\r
569  *\r
570  * @return\r
571  *   Pending and enabled EMU interrupt sources\r
572  *   The return value is the bitwise AND of\r
573  *   - the enabled interrupt sources in EMU_IEN and\r
574  *   - the pending interrupt flags EMU_IF\r
575  ******************************************************************************/\r
576 __STATIC_INLINE uint32_t EMU_IntGetEnabled(void)\r
577 {\r
578   uint32_t ien;\r
579 \r
580   ien = EMU->IEN;\r
581   return EMU->IF & ien;\r
582 }\r
583 \r
584 \r
585 /***************************************************************************//**\r
586  * @brief\r
587  *   Set one or more pending EMU interrupts\r
588  *\r
589  * @param[in] flags\r
590  *   EMU interrupt sources to set to pending. Use one or more valid\r
591  *   interrupt flags for the EMU module (EMU_IFS_nnn).\r
592  ******************************************************************************/\r
593 __STATIC_INLINE void EMU_IntSet(uint32_t flags)\r
594 {\r
595   EMU->IFS = flags;\r
596 }\r
597 #endif /* _EMU_IF_MASK */\r
598 \r
599 \r
600 #if defined( _EMU_EM4CONF_LOCKCONF_MASK )\r
601 /***************************************************************************//**\r
602  * @brief\r
603  *   Enable or disable EM4 lock configuration\r
604  * @param[in] enable\r
605  *   If true, locks down EM4 configuration\r
606  ******************************************************************************/\r
607 __STATIC_INLINE void EMU_EM4Lock(bool enable)\r
608 {\r
609   BUS_RegBitWrite(&(EMU->EM4CONF), _EMU_EM4CONF_LOCKCONF_SHIFT, enable);\r
610 }\r
611 #endif\r
612 \r
613 #if defined( _EMU_STATUS_BURDY_MASK )\r
614 /***************************************************************************//**\r
615  * @brief\r
616  *   Halts until backup power functionality is ready\r
617  ******************************************************************************/\r
618 __STATIC_INLINE void EMU_BUReady(void)\r
619 {\r
620   while(!(EMU->STATUS & EMU_STATUS_BURDY))\r
621     ;\r
622 }\r
623 #endif\r
624 \r
625 #if defined( _EMU_ROUTE_BUVINPEN_MASK )\r
626 /***************************************************************************//**\r
627  * @brief\r
628  *   Disable BU_VIN support\r
629  * @param[in] enable\r
630  *   If true, enables BU_VIN input pin support, if false disables it\r
631  ******************************************************************************/\r
632 __STATIC_INLINE void EMU_BUPinEnable(bool enable)\r
633 {\r
634   BUS_RegBitWrite(&(EMU->ROUTE), _EMU_ROUTE_BUVINPEN_SHIFT, enable);\r
635 }\r
636 #endif\r
637 \r
638 /***************************************************************************//**\r
639  * @brief\r
640  *   Lock the EMU in order to protect its registers against unintended\r
641  *   modification.\r
642  *\r
643  * @note\r
644  *   If locking the EMU registers, they must be unlocked prior to using any\r
645  *   EMU API functions modifying EMU registers, excluding interrupt control\r
646  *   and regulator control if the architecture has a EMU_PWRCTRL register.\r
647  *   An exception to this is the energy mode entering API (EMU_EnterEMn()),\r
648  *   which can be used when the EMU registers are locked.\r
649  ******************************************************************************/\r
650 __STATIC_INLINE void EMU_Lock(void)\r
651 {\r
652   EMU->LOCK = EMU_LOCK_LOCKKEY_LOCK;\r
653 }\r
654 \r
655 \r
656 /***************************************************************************//**\r
657  * @brief\r
658  *   Unlock the EMU so that writing to locked registers again is possible.\r
659  ******************************************************************************/\r
660 __STATIC_INLINE void EMU_Unlock(void)\r
661 {\r
662   EMU->LOCK = EMU_LOCK_LOCKKEY_UNLOCK;\r
663 }\r
664 \r
665 \r
666 #if defined( _EMU_PWRLOCK_MASK )\r
667 /***************************************************************************//**\r
668  * @brief\r
669  *   Lock the EMU regulator control registers in order to protect against\r
670  *   unintended modification.\r
671  ******************************************************************************/\r
672 __STATIC_INLINE void EMU_PowerLock(void)\r
673 {\r
674   EMU->PWRLOCK = EMU_PWRLOCK_LOCKKEY_LOCK;\r
675 }\r
676 \r
677 \r
678 /***************************************************************************//**\r
679  * @brief\r
680  *   Unlock the EMU power control registers so that writing to\r
681  *   locked registers again is possible.\r
682  ******************************************************************************/\r
683 __STATIC_INLINE void EMU_PowerUnlock(void)\r
684 {\r
685   EMU->PWRLOCK = EMU_PWRLOCK_LOCKKEY_UNLOCK;\r
686 }\r
687 #endif\r
688 \r
689 \r
690 /***************************************************************************//**\r
691  * @brief\r
692  *   Block entering EM2 or higher number energy modes.\r
693  ******************************************************************************/\r
694 __STATIC_INLINE void EMU_EM2Block(void)\r
695 {\r
696   BUS_RegBitWrite(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 1U);\r
697 }\r
698 \r
699 /***************************************************************************//**\r
700  * @brief\r
701  *   Unblock entering EM2 or higher number energy modes.\r
702  ******************************************************************************/\r
703 __STATIC_INLINE void EMU_EM2UnBlock(void)\r
704 {\r
705   BUS_RegBitWrite(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 0U);\r
706 }\r
707 \r
708 #if defined( _EMU_EM4CTRL_EM4IORETMODE_MASK )\r
709 /***************************************************************************//**\r
710  * @brief\r
711  *   When EM4 pin retention is set to emuPinRetentionLatch, then pins are retained\r
712  *   through EM4 entry and wakeup. The pin state is released by calling this function.\r
713  *   The feature allows peripherals or GPIO to be re-initialized after EM4 exit (reset),\r
714  *   and when the initialization is done, this function can release pins and return control\r
715  *   to the peripherals or GPIO.\r
716  ******************************************************************************/\r
717 __STATIC_INLINE void EMU_UnlatchPinRetention(void)\r
718 {\r
719   EMU->CMD = EMU_CMD_EM4UNLATCH;\r
720 }\r
721 #endif\r
722 \r
723 /** @} (end addtogroup EMU) */\r
724 /** @} (end addtogroup EM_Library) */\r
725 \r
726 #ifdef __cplusplus\r
727 }\r
728 #endif\r
729 \r
730 #endif /* defined( EMU_PRESENT ) */\r
731 #endif /* __SILICON_LABS_EM_EMU_H__ */\r