vddcheck.c

Go to the documentation of this file.
00001 /**************************************************************************/
00017 #include <stdint.h>
00018 #include <stdbool.h>
00019 #include "em_cmu.h"
00020 #include "em_vcmp.h"
00021 #include "vddcheck.h"
00022 
00023 /**************************************************************************/
00026 void VDDCHECK_Init(void)
00027 {
00028   /* Enable LE peripherals */
00029   CMU_ClockEnable(cmuClock_CORELE, true);
00030 
00031   /* Enable VCMP clock */
00032   CMU_ClockEnable(cmuClock_VCMP, true);
00033 }
00034 
00035 /**************************************************************************/
00038 void VDDCHECK_Disable(void)
00039 {
00040   /* Disable VCMP */
00041   VCMP_Disable();
00042 
00043   /* Disable clock to VCMP */
00044   CMU_ClockEnable(cmuClock_VCMP, false);
00045 }
00046 
00047 /**************************************************************************/
00055 bool VDDCHECK_LowVoltage(float vdd)
00056 {
00057   VCMP_Init_TypeDef vcmp = VCMP_INIT_DEFAULT;
00058 
00059   /* Configure VCMP */
00060   vcmp.triggerLevel = VCMP_VoltageToLevel(vdd);
00061   vcmp.warmup       = vcmpWarmTime128Cycles;
00062   vcmp.lowPowerRef  = false;
00063   vcmp.enable       = true;
00064 
00065   VCMP_Init(&vcmp);
00066 
00067   /* Delay until warm up ready */
00068   while (!VCMP_Ready()) ;
00069 
00070   /* If zero result, voltage is lower */
00071   if (VCMP_VDDHigher()) return false;
00072 
00073   /* Otherwise return false */
00074   return true;
00075 }