EFR32 Blue Gecko 13 Software Documentation  efr32bg13-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 */
32  CMU_ClockEnable(cmuClock_VCMP, true);
33 }
34 
35 /**************************************************************************/
38 void VDDCHECK_Disable(void)
39 {
40  /* Disable VCMP */
41  VCMP_Disable();
42 
43  /* Disable clock to VCMP */
44  CMU_ClockEnable(cmuClock_VCMP, false);
45 }
46 
47 /**************************************************************************/
55 bool VDDCHECK_LowVoltage(float vdd)
56 {
57  VCMP_Init_TypeDef vcmp = VCMP_INIT_DEFAULT;
58 
59  /* Configure VCMP */
60  vcmp.triggerLevel = VCMP_VoltageToLevel(vdd);
61  vcmp.warmup = vcmpWarmTime128Cycles;
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.
Voltage Comparator (VCMP) peripheral API.
void VDDCHECK_Init(void)
VCMP initialization routine.
Definition: vddcheck.c:26
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
bool VDDCHECK_LowVoltage(float vdd)
Check if voltage is higher than indicated.
Definition: vddcheck.c:55