EFM32 Giant Gecko Software Documentation  efm32gg-doc-5.1.2
vddcheck.c
Go to the documentation of this file.
1 /**************************************************************************/
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include "em_cmu.h"
20 #include "em_vcmp.h"
21 #include "vddcheck.h"
22 
23 /**************************************************************************/
26 void VDDCHECK_Init(void)
27 {
28  /* Enable LE peripherals */
29  CMU_ClockEnable(cmuClock_CORELE, true);
30 
31  /* Enable VCMP clock */
33 }
34 
35 /**************************************************************************/
38 void VDDCHECK_Disable(void)
39 {
40  /* Disable VCMP */
41  VCMP_Disable();
42 
43  /* Disable clock to VCMP */
45 }
46 
47 /**************************************************************************/
55 bool VDDCHECK_LowVoltage(float vdd)
56 {
58 
59  /* Configure VCMP */
62  vcmp.lowPowerRef = false;
63  vcmp.enable = true;
64 
65  VCMP_Init(&vcmp);
66 
67  /* Delay until warm up ready */
68  while (!VCMP_Ready()) ;
69 
70  /* If zero result, voltage is lower */
71  if (VCMP_VDDHigher()) return false;
72 
73  /* Otherwise return false */
74  return true;
75 }
Clock management unit (CMU) API.
void VCMP_Init(const VCMP_Init_TypeDef *vcmpInit)
Configure and enable Voltage Comparator.
Definition: em_vcmp.c:60
Voltage Comparator (VCMP) peripheral API.
__STATIC_INLINE bool VCMP_VDDHigher(void)
Returns true, if Voltage Comparator indicated VDD > trigger level, else false.
Definition: em_vcmp.h:204
__STATIC_INLINE void VCMP_Disable(void)
Disable Voltage Comparator.
Definition: em_vcmp.h:159
void VDDCHECK_Init(void)
VCMP initialization routine.
Definition: vddcheck.c:26
__STATIC_INLINE bool VCMP_Ready(void)
VCMP output is ready.
Definition: em_vcmp.h:221
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1453
Vdd voltage check routines, using VCMP.
void VDDCHECK_Disable(void)
VCMP deinitialization routine.
Definition: vddcheck.c:38
__STATIC_INLINE uint32_t VCMP_VoltageToLevel(float v)
Calculate voltage to trigger level.
Definition: em_vcmp.h:175
VCMP_WarmTime_TypeDef warmup
Definition: em_vcmp.h:108
bool VDDCHECK_LowVoltage(float vdd)
Check if voltage is higher than indicated.
Definition: vddcheck.c:55
#define VCMP_INIT_DEFAULT
Definition: em_vcmp.h:123