Utility FunctionsBSP > Thunderboard Sense BSP

Detailed Description

Utility functions.

Macros

#define UTIL_SUPPLY_TYPE_AA 2
#define UTIL_SUPPLY_TYPE_AAA 3
#define UTIL_SUPPLY_TYPE_CR2032 4
#define UTIL_SUPPLY_TYPE_UNKNOWN 0
#define UTIL_SUPPLY_TYPE_USB 1

Functions

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

Macro Definition Documentation

#define UTIL_SUPPLY_TYPE_AA   2

The board powered from AA batteries

Definition at line 36 of file util.h .

#define UTIL_SUPPLY_TYPE_AAA   3

The board powered from AAA batteries

Definition at line 37 of file util.h .

Referenced by UTIL_supplyProbe() .

#define UTIL_SUPPLY_TYPE_CR2032   4

The board powered from a CR2032 battery

Definition at line 38 of file util.h .

Referenced by UTIL_isLowPower() , and UTIL_supplyProbe() .

#define UTIL_SUPPLY_TYPE_UNKNOWN   0

Unknown power supply type

Definition at line 34 of file util.h .

Referenced by UTIL_isLowPower() , and UTIL_supplyProbe() .

#define UTIL_SUPPLY_TYPE_USB   1

The board powered from the USB connector

Definition at line 35 of file util.h .

Referenced by UTIL_supplyProbe() .

Function Documentation

static void adcDeInit ( void )
static

De-initializes the A/D converter.

Returns
None

Definition at line 93 of file util_supply.c .

References _CMU_CTRL_CLKOUTSEL1_MASK , CMU , and PRS_SourceAsyncSignalSet() .

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 108 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] loadSetting Heater current setting of the Si7021
Returns
The measured internal resistance of the connected supply

Definition at line 161 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] avg Number of measurements to average
Returns
The measured voltage

Definition at line 127 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] id The id of the timer
[in] user Extra parameter for user application (not used)
Returns
None

Definition at line 129 of file util_sleep.c .

Referenced by UTIL_sleep() , and UTIL_waitForEvent() .

void SysTick_Handler ( void )

Interrupt Service Routine for system tick counter.

Returns
None

Definition at line 69 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 50 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 281 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 105 of file util.c .

References _GPIO_EM4WUEN_EM4WUEN_SHIFT , EMU_EM4Init() , EMU_EM4INIT_DEFAULT , EMU_EnterEM4() , GPIO_EM4EnablePinWakeup() , GPIO_PinModeSet() , and gpioModeInputPullFilter .

void UTIL_sleep ( uint32_t ms )

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

Parameters
ms Number of milliseconds to sleep
Returns
None

Definition at line 76 of file util_sleep.c .

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

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 51 of file util_sleep.c .

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

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

Retrieves the supply characteristic variables.

Parameters
[in] type Supply type
[in] voltage Loaded supply voltage
[in] ir Internal resistance of the supply
Returns
None

Definition at line 253 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 269 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 208 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
timeout Timeout, the maximum number of milliseconds to sleep
Returns
The number of milliseconds remained from the timeout

Definition at line 98 of file util_sleep.c .

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