em_emu.h

Go to the documentation of this file.
00001 /***************************************************************************/
00034 #ifndef __SILICON_LABS_EM_EMU_H__
00035 #define __SILICON_LABS_EM_EMU_H__
00036 
00037 #include "em_device.h"
00038 #if defined( EMU_PRESENT )
00039 
00040 #include <stdbool.h>
00041 #include "em_bitband.h"
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 /***************************************************************************/
00052 /***************************************************************************/
00057 /*******************************************************************************
00058  ********************************   ENUMS   ************************************
00059  ******************************************************************************/
00060 
00061 typedef enum
00062 {
00064 #if defined( _EMU_CTRL_EM23VREG_MASK )
00065   emuEM23Vreg_REDUCED = EMU_CTRL_EM23VREG_REDUCED,
00066 #elif defined( _EMU_CTRL_EMVREG_MASK )
00067   emuEM23Vreg_REDUCED = EMU_CTRL_EMVREG_REDUCED,
00068 #endif
00069 
00070 #if defined( _EMU_CTRL_EM23VREG_MASK )
00071   emuEM23Vreg_FULL = EMU_CTRL_EM23VREG_FULL,
00072 #elif defined( _EMU_CTRL_EMVREG_MASK )
00073   emuEM23Vreg_FULL = EMU_CTRL_EMVREG_FULL,
00074 #endif
00075 } EMU_EM23VregMode;
00076 
00077 #if defined( _EMU_EM4CONF_OSC_MASK )
00078 
00079 typedef enum
00080 {
00082   emuEM4Osc_ULFRCO = EMU_EM4CONF_OSC_ULFRCO,
00084   emuEM4Osc_LFXO = EMU_EM4CONF_OSC_LFXO,
00086   emuEM4Osc_LFRCO = EMU_EM4CONF_OSC_LFRCO
00087 } EMU_EM4Osc_TypeDef;
00088 #endif
00089 
00090 #if defined( _EMU_BUCTRL_PROBE_MASK )
00091 
00092 typedef enum
00093 {
00095   emuProbe_Disable = EMU_BUCTRL_PROBE_DISABLE,
00097   emuProbe_VDDDReg = EMU_BUCTRL_PROBE_VDDDREG,
00099   emuProbe_BUIN    = EMU_BUCTRL_PROBE_BUIN,
00101   emuProbe_BUOUT   = EMU_BUCTRL_PROBE_BUOUT
00102 } EMU_Probe_TypeDef;
00103 #endif
00104 
00105 #if defined( _EMU_PWRCONF_PWRRES_MASK )
00106 
00107 typedef enum
00108 {
00110   emuRes_Res0 = EMU_PWRCONF_PWRRES_RES0,
00112   emuRes_Res1 = EMU_PWRCONF_PWRRES_RES1,
00114   emuRes_Res2 = EMU_PWRCONF_PWRRES_RES2,
00116   emuRes_Res3 = EMU_PWRCONF_PWRRES_RES3,
00117 } EMU_Resistor_TypeDef;
00118 #endif
00119 
00120 #if defined( BU_PRESENT )
00121 
00122 typedef enum
00123 {
00125   emuPower_None = EMU_BUINACT_PWRCON_NONE,
00128   emuPower_BUMain = EMU_BUINACT_PWRCON_BUMAIN,
00131   emuPower_MainBU = EMU_BUINACT_PWRCON_MAINBU,
00133   emuPower_NoDiode = EMU_BUINACT_PWRCON_NODIODE,
00134 } EMU_Power_TypeDef;
00135 #endif
00136 
00138 typedef enum
00139 {
00141   emuBODMode_Active,
00143   emuBODMode_Inactive,
00144 } EMU_BODMode_TypeDef;
00145 
00146 
00147 
00148 /*******************************************************************************
00149  *******************************   STRUCTS   ***********************************
00150  ******************************************************************************/
00151 
00153 typedef struct
00154 {
00155   bool em23Vreg;
00156 } EMU_EM23Init_TypeDef;
00157 
00159 #define EMU_EM23INIT_DEFAULT    \
00160   { false }     /* Reduced voltage regulator drive strength in EM2 and EM3 */
00161 
00162 
00164 typedef struct
00165 {
00166   /* Init parameters for platforms with EMU->EM4CONF register */
00167 #if defined( _EMU_EM4CONF_MASK )
00168   bool                  lockConfig;     
00169   bool                  buBodRstDis;    
00170   EMU_EM4Osc_TypeDef    osc;            
00171   bool                  buRtcWakeup;    
00172   bool                  vreg;           
00173 #else
00174   bool                  reserved;       
00175 #endif
00176 } EMU_EM4Init_TypeDef;
00177 
00179 #if defined( _EMU_EM4CONF_MASK )
00180 #define EMU_EM4INIT_DEFAULT    \
00181   { false,             /* Dont't lock configuration after it's been set */ \
00182     false,             /* No reset will be asserted due to Brownout when in EM4 */ \
00183     emuEM4Osc_ULFRCO,  /* Use default ULFRCO oscillator  */ \
00184     true,              /* Wake up on EM4 BURTC interrupt */ \
00185     true,              /* Enable VREG */ \
00186   }
00187 #else
00188  #define EMU_EM4INIT_DEFAULT    \
00189   { false,             /* Placeholder default value */ \
00190   }
00191 #endif
00192 
00193 
00194 #if defined( BU_PRESENT )
00195 
00196 typedef struct
00197 {
00198   /* Backup Power Domain power configuration */
00199 
00201   EMU_Probe_TypeDef     probe;
00203   bool                  bodCal;
00205   bool                  statusPinEnable;
00206 
00207   /* Backup Power Domain connection configuration */
00209   EMU_Resistor_TypeDef  resistor;
00211   bool                  voutStrong;
00213   bool                  voutMed;
00215   bool                  voutWeak;
00217   EMU_Power_TypeDef  inactivePower;
00219   EMU_Power_TypeDef     activePower;
00221   bool                  enable;
00222 } EMU_BUPDInit_TypeDef;
00223 
00225 #define EMU_BUPDINIT_DEFAULT                                                \
00226   { emuProbe_Disable, /* Do not enable voltage probe */                     \
00227     false,            /* Disable BOD calibration mode */                    \
00228     false,            /* Disable BU_STAT pin for backup mode indication */  \
00229                                                                             \
00230     emuRes_Res0,      /* RES0 series resistance between main and backup power */ \
00231     false,            /* Don't enable strong switch */                           \
00232     false,            /* Don't enable medium switch */                           \
00233     false,            /* Don't enable weak switch */                             \
00234                                                                                  \
00235     emuPower_None,    /* No connection between main and backup power (inactive mode) */  \
00236     emuPower_None,    /* No connection between main and backup power (active mode) */    \
00237     true              /* Enable BUPD enter on BOD, enable BU_VIN pin, release BU reset  */  \
00238   }
00239 #endif
00240 
00241 
00242 /*******************************************************************************
00243  *****************************   PROTOTYPES   **********************************
00244  ******************************************************************************/
00245 
00246 /***************************************************************************/
00250 __STATIC_INLINE void EMU_EnterEM1(void)
00251 {
00252   /* Just enter Cortex-M3 sleep mode */
00253   SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
00254   __WFI();
00255 }
00256 
00257 void EMU_EM23Init(EMU_EM23Init_TypeDef *em23Init);
00258 #if defined( _EMU_EM4CONF_MASK )
00259 void EMU_EM4Init(EMU_EM4Init_TypeDef *em4Init);
00260 #endif
00261 void EMU_EnterEM2(bool restore);
00262 void EMU_EnterEM3(bool restore);
00263 void EMU_EnterEM4(void);
00264 void EMU_MemPwrDown(uint32_t blocks);
00265 void EMU_UpdateOscConfig(void);
00266 #if defined( BU_PRESENT )
00267 void EMU_BUPDInit(EMU_BUPDInit_TypeDef *bupdInit);
00268 void EMU_BUThresholdSet(EMU_BODMode_TypeDef mode, uint32_t value);
00269 void EMU_BUThresRangeSet(EMU_BODMode_TypeDef mode, uint32_t value);
00270 #endif
00271 
00272 
00273 #if defined( _EMU_IF_MASK )
00274 /***************************************************************************/
00282 __STATIC_INLINE void EMU_IntClear(uint32_t flags)
00283 {
00284   EMU->IFC = flags;
00285 }
00286 
00287 
00288 /***************************************************************************/
00296 __STATIC_INLINE void EMU_IntDisable(uint32_t flags)
00297 {
00298   EMU->IEN &= ~(flags);
00299 }
00300 
00301 
00302 /***************************************************************************/
00315 __STATIC_INLINE void EMU_IntEnable(uint32_t flags)
00316 {
00317   EMU->IEN |= flags;
00318 }
00319 
00320 
00321 /***************************************************************************/
00332 __STATIC_INLINE uint32_t EMU_IntGet(void)
00333 {
00334   return EMU->IF;
00335 }
00336 
00337 
00338 /***************************************************************************/
00352 __STATIC_INLINE uint32_t EMU_IntGetEnabled(void)
00353 {
00354   uint32_t ien;
00355 
00356   ien = EMU->IEN;
00357   return EMU->IF & ien;
00358 }
00359 
00360 
00361 /***************************************************************************/
00369 __STATIC_INLINE void EMU_IntSet(uint32_t flags)
00370 {
00371   EMU->IFS = flags;
00372 }
00373 #endif /* _EMU_IF_MASK */
00374 
00375 
00376 #if defined( _EMU_EM4CONF_LOCKCONF_MASK )
00377 /***************************************************************************/
00383 __STATIC_INLINE void EMU_EM4Lock(bool enable)
00384 {
00385   BITBAND_Peripheral(&(EMU->EM4CONF), _EMU_EM4CONF_LOCKCONF_SHIFT, enable);
00386 }
00387 #endif
00388 
00389 
00390 #if defined( _EMU_STATUS_BURDY_MASK )
00391 /***************************************************************************/
00395 __STATIC_INLINE void EMU_BUReady(void)
00396 {
00397   while(!(EMU->STATUS & EMU_STATUS_BURDY));
00398 }
00399 #endif
00400 
00401 
00402 #if defined( _EMU_ROUTE_BUVINPEN_MASK )
00403 /***************************************************************************/
00409 __STATIC_INLINE void EMU_BUPinEnable(bool enable)
00410 {
00411   BITBAND_Peripheral(&(EMU->ROUTE), _EMU_ROUTE_BUVINPEN_SHIFT, enable);
00412 }
00413 #endif
00414 
00415 
00416 /***************************************************************************/
00427 __STATIC_INLINE void EMU_Lock(void)
00428 {
00429   EMU->LOCK = EMU_LOCK_LOCKKEY_LOCK;
00430 }
00431 
00432 
00433 /***************************************************************************/
00437 __STATIC_INLINE void EMU_Unlock(void)
00438 {
00439   EMU->LOCK = EMU_LOCK_LOCKKEY_UNLOCK;
00440 }
00441 
00442 /***************************************************************************/
00446 __STATIC_INLINE void EMU_EM2Block(void)
00447 {
00448   BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 1U);
00449 }
00450 
00451 
00452 /***************************************************************************/
00456 __STATIC_INLINE void EMU_EM2UnBlock(void)
00457 {
00458   BITBAND_Peripheral(&(EMU->CTRL), _EMU_CTRL_EM2BLOCK_SHIFT, 0U);
00459 }
00460 
00461 
00465 #ifdef __cplusplus
00466 }
00467 #endif
00468 
00469 #endif /* defined( EMU_PRESENT ) */
00470 #endif /* __EM_EMU_H */