vddcheck.c

Go to the documentation of this file.
00001 /**************************************************************************/
00035 #include <stdint.h>
00036 #include <stdbool.h>
00037 #include "em_cmu.h"
00038 #include "em_vcmp.h"
00039 #include "vddcheck.h"
00040 
00041 /**************************************************************************/
00044 void VDDCHECK_Init(void)
00045 {
00046   /* Enable LE peripherals */
00047   CMU_ClockEnable(cmuClock_CORELE, true);
00048 
00049   /* Enable VCMP clock */
00050   CMU_ClockEnable(cmuClock_VCMP, true);
00051 }
00052 
00053 /**************************************************************************/
00056 void VDDCHECK_Disable(void)
00057 {
00058   /* Disable VCMP */
00059   VCMP_Disable();
00060 
00061   /* Disable clock to VCMP */
00062   CMU_ClockEnable(cmuClock_VCMP, false);
00063 }
00064 
00065 /**************************************************************************/
00073 bool VDDCHECK_LowVoltage(float vdd)
00074 {
00075   VCMP_Init_TypeDef vcmp = VCMP_INIT_DEFAULT;
00076 
00077   /* Configure VCMP */
00078   vcmp.triggerLevel = VCMP_VoltageToLevel(vdd);
00079   vcmp.warmup       = vcmpWarmTime128Cycles;
00080   vcmp.lowPowerRef  = false;
00081   vcmp.enable       = true;
00082 
00083   VCMP_Init(&vcmp);
00084 
00085   /* Delay until warm up ready */
00086   while (!VCMP_Ready()) ;
00087 
00088   /* If zero result, voltage is lower */
00089   if (VCMP_VDDHigher()) return false;
00090 
00091   /* Otherwise return false */
00092   return true;
00093 }