EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
Utility Functions

Detailed Description

Utility functions.

DO_NOT_INCLUDE_WITH_DOXYGEN

Functions

static void adcDeInit (void)
 De-initializes the A/D converter. More...
 
static void adcInit (void)
 Initializes the A/D converter. More...
 
static uint16_t getAdcSample (void)
 Initiates an A/D conversion and reads the sample when done. More...
 
static float measureSupplyIR (uint8_t loadSetting)
 Measures the unladed and loaded supply voltage and calculates the intermal resistance of the connected supply. The load is provided by the heater element built in the Si7021. More...
 
static float measureSupplyVoltage (unsigned int avg)
 Measures the supply voltage by averaging multiple readings. More...
 
static void rtcCb (RTCDRV_TimerID_t id, void *user)
 RTC callback function, called when the timer expired. More...
 
void SysTick_Handler (void)
 Interrupt Service Routine for system tick counter. More...
 
void UTIL_delay (uint32_t ms)
 Delays number of msTick Systicks (1 ms) More...
 
uint32_t UTIL_init (void)
 Sets up the SysTick timer for 1ms interrupts and initializes and starts the RTC timer. More...
 
bool UTIL_isLowPower (void)
 Checks if the current power supply has low power capability. More...
 
void UTIL_shutdown (void)
 Enter lowest power shutdown mode, EM4S. More...
 
void UTIL_sleep (uint32_t ms)
 Delays number of milliseconds in sleep mode (EM2) using the RTC. More...
 
uint32_t UTIL_sleepInit (void)
 Sets up the RTC timer used for sleep functions. More...
 
void UTIL_supplyGetCharacteristics (uint8_t *type, float *voltage, float *ir)
 Retrieves the supply characteristic variables. More...
 
uint8_t UTIL_supplyGetType (void)
 Returns the type of the power supply. More...
 
void UTIL_supplyProbe (void)
 Probes the connected supply and determines its type. The results are stored in global variables. More...
 
uint32_t UTIL_waitForEvent (uint32_t timeout)
 Delays number of milliseconds in sleep mode (EM2) using the RTC but but returns if an event wakes up the MCU. More...
 

Function Documentation

static void adcDeInit ( void  )
static

De-initializes the A/D converter.

Returns
None

Definition at line 101 of file util_supply.c.

References _CMU_CTRL_CLKOUTSEL1_MASK, and CMU.

Referenced by measureSupplyVoltage().

static uint16_t getAdcSample ( void  )
static

Initiates an A/D conversion and reads the sample when done.

Returns
The output of the A/D conversion

Definition at line 118 of file util_supply.c.

References ADC0, ADC_DataSingleGet(), ADC_IF_SINGLE, ADC_IntGet(), ADC_Start(), and adcStartSingle.

Referenced by measureSupplyVoltage().

static float measureSupplyIR ( uint8_t  loadSetting)
static

Measures the unladed and loaded supply voltage and calculates the intermal resistance of the connected supply. The load is provided by the heater element built in the Si7021.

Parameters
[in]loadSettingHeater current setting of the Si7021
Returns
The measured internal resistance of the connected supply

Definition at line 175 of file util_supply.c.

References measureSupplyVoltage(), SI7021_CMD_WRITE_HEATER_CTRL, SI7021_CMD_WRITE_USER_REG1, SI7021_cmdWrite(), and UTIL_delay().

Referenced by UTIL_supplyProbe().

static float measureSupplyVoltage ( unsigned int  avg)
static

Measures the supply voltage by averaging multiple readings.

Parameters
[in]avgNumber of measurements to average
Returns
The measured voltage

Definition at line 139 of file util_supply.c.

References adcDeInit(), adcInit(), and getAdcSample().

Referenced by measureSupplyIR(), and UTIL_supplyProbe().

static void rtcCb ( RTCDRV_TimerID_t  id,
void *  user 
)
static

RTC callback function, called when the timer expired.

Parameters
[in]idThe id of the timer
[in]userExtra parameter for user application (not used)
Returns
None

Definition at line 132 of file util_sleep.c.

References rtcComplete.

Referenced by UTIL_sleep(), and UTIL_waitForEvent().

void SysTick_Handler ( void  )

Interrupt Service Routine for system tick counter.

Returns
None

Definition at line 78 of file util.c.

uint32_t UTIL_init ( void  )

Sets up the SysTick timer for 1ms interrupts and initializes and starts the RTC timer.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 57 of file util.c.

References CMU_ClockFreqGet(), and cmuClock_CORE.

bool UTIL_isLowPower ( void  )

Checks if the current power supply has low power capability.

Returns
True if the supply is low power type, false otherwise

Definition at line 305 of file util_supply.c.

References UTIL_SUPPLY_TYPE_CR2032, and UTIL_SUPPLY_TYPE_UNKNOWN.

void UTIL_shutdown ( void  )

Enter lowest power shutdown mode, EM4S.

Returns
None

Definition at line 118 of file util.c.

References BOARD_BUTTON_LEFT_PIN, BOARD_BUTTON_PORT, EMU_EnterEM4(), GPIO_PinModeSet(), and gpioModeInputPullFilter.

void UTIL_sleep ( uint32_t  ms)

Delays number of milliseconds in sleep mode (EM2) using the RTC.

Parameters
msNumber of milliseconds to sleep
Returns
None

Definition at line 78 of file util_sleep.c.

References EMU_EnterEM2(), rtcCb(), rtcComplete, RTCDRV_StartTimer(), rtcdrvTimerTypeOneshot, and rtcId.

uint32_t UTIL_sleepInit ( void  )

Sets up the RTC timer used for sleep functions.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 53 of file util_sleep.c.

References ECODE_EMDRV_RTCDRV_OK, RTCDRV_AllocateTimer(), RTCDRV_Init(), and rtcId.

void UTIL_supplyGetCharacteristics ( uint8_t *  type,
float *  voltage,
float *  ir 
)

Retrieves the supply characteristic variables.

Parameters
[in]typeSupply type
[in]voltageLoaded supply voltage
[in]irInternal resistance of the supply
Returns
None

Definition at line 273 of file util_supply.c.

uint8_t UTIL_supplyGetType ( void  )

Returns the type of the power supply.

Returns
The type of the supply

Definition at line 291 of file util_supply.c.

void UTIL_supplyProbe ( void  )

Probes the connected supply and determines its type. The results are stored in global variables.

Returns
None

Definition at line 224 of file util_supply.c.

References measureSupplyIR(), measureSupplyVoltage(), SI7021_deInit(), SI7021_init(), UTIL_SUPPLY_TYPE_AAA, UTIL_SUPPLY_TYPE_CR2032, UTIL_SUPPLY_TYPE_UNKNOWN, and UTIL_SUPPLY_TYPE_USB.

uint32_t UTIL_waitForEvent ( uint32_t  timeout)

Delays number of milliseconds in sleep mode (EM2) using the RTC but but returns if an event wakes up the MCU.

Parameters
timeoutTimeout, the maximum number of milliseconds to sleep
Returns
The number of milliseconds remained from the timeout

Definition at line 100 of file util_sleep.c.

References EMU_EnterEM2(), rtcCb(), rtcComplete, RTCDRV_StartTimer(), RTCDRV_TimeRemaining(), rtcdrvTimerTypeOneshot, and rtcId.