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
        
         34
        
        of file
        
         util.h
        
        .
       
| #define UTIL_SUPPLY_TYPE_AAA 3 | 
The board powered from AAA batteries
        Definition at line
        
         35
        
        of file
        
         util.h
        
        .
       
Referenced by UTIL_supplyProbe() .
| #define UTIL_SUPPLY_TYPE_CR2032 4 | 
The board powered from a CR2032 battery
        Definition at line
        
         36
        
        of file
        
         util.h
        
        .
       
Referenced by UTIL_isLowPower() , and UTIL_supplyProbe() .
| #define UTIL_SUPPLY_TYPE_UNKNOWN 0 | 
Unknown power supply type
        Definition at line
        
         32
        
        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
        
         33
        
        of file
        
         util.h
        
        .
       
Referenced by UTIL_supplyProbe() .
Function Documentation
| 
 | static | 
De-initializes the A/D converter.
- Returns
- None
        Definition at line
        
         91
        
        of file
        
         util_supply.c
        
        .
       
References _CMU_CTRL_CLKOUTSEL1_MASK , CMU , and PRS_SourceAsyncSignalSet() .
Referenced by measureSupplyVoltage() .
| 
 | static | 
Initializes the A/D converter.
- Returns
- None
        Definition at line
        
         57
        
        of file
        
         util_supply.c
        
        .
       
References _ADC_CTRL_RESETVALUE , ADC_InitSingle_TypeDef::acqTime , ADC0 , ADC_Init() , ADC_INIT_DEFAULT , ADC_InitSingle() , ADC_INITSINGLE_DEFAULT , ADC_PrescaleCalc() , ADC_TimebaseCalc() , adcAcqTime16 , adcPRSSELCh4 , CMU_ClockEnable() , cmuClock_ADC0 , cmuClock_PRS , ADC_InitSingle_TypeDef::negSel , ADC_InitSingle_TypeDef::posSel , ADC_Init_TypeDef::prescale , ADC_InitSingle_TypeDef::prsEnable , ADC_InitSingle_TypeDef::prsSel , ADC_InitSingle_TypeDef::reference , and ADC_Init_TypeDef::timebase .
Referenced by measureSupplyVoltage() , and MIC_init() .
| 
 | static | 
Initiates an A/D conversion and reads the sample when done.
- Returns
- The output of the A/D conversion
        Definition at line
        
         106
        
        of file
        
         util_supply.c
        
        .
       
References ADC0 , ADC_DataSingleGet() , ADC_IF_SINGLE , ADC_IntGet() , ADC_Start() , and adcStartSingle .
Referenced by measureSupplyVoltage() .
| 
 | 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
        
         159
        
        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 | 
Measures the supply voltage by averaging multiple readings.
- Parameters
- 
         [in] avgNumber of measurements to average 
- Returns
- The measured voltage
        Definition at line
        
         125
        
        of file
        
         util_supply.c
        
        .
       
References adcDeInit() , adcInit() , and getAdcSample() .
Referenced by measureSupplyIR() , and UTIL_supplyProbe() .
| 
 | 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
        
         127
        
        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
        
         67
        
        of file
        
         util.c
        
        .
       
| void UTIL_delay | ( | uint32_t | 
            ms
            | ) | 
Delays number of msTick Systicks (1 ms)
- Parameters
- 
         [in] msNumber of ticks (ms) to delay 
- Returns
- None
        Definition at line
        
         84
        
        of file
        
         util.c
        
        .
       
References EMU_EnterEM1() .
Referenced by BAP_init() , BOARD_flashDeepPowerDown() , BOARD_gasSensorWake() , BOARD_init() , CCS811_init() , HALL_init() , ICM20648_accelGyroCalibrate() , ICM20648_gyroCalibrate() , ICM20648_init() , ICM20648_lowPowerModeEnter() , ICM20648_reset() , ICM20648_wakeOnMotionITEnable() , IMU_config() , measureSupplyIR() , SI1133_init() , SI1133_measureLuxUvi() , SI1133_reset() , SI7021_init() , and SI7021_measure() .
| 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
        
         48
        
        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
        
         279
        
        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
        
         103
        
        of file
        
         util.c
        
        .
       
References _GPIO_EM4WUEN_EM4WUEN_SHIFT , EMU_EM4Init() , EMU_EM4INIT_DEFAULT , EMU_EnterEM4() , emuPinRetentionEm4Exit , GPIO_EM4EnablePinWakeup() , GPIO_PinModeSet() , gpioModeInputPullFilter , and EMU_EM4Init_TypeDef::pinRetentionMode .
| 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
        
         74
        
        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
        
         49
        
        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] typeSupply type [in] voltageLoaded supply voltage [in] irInternal resistance of the supply 
- Returns
- None
        Definition at line
        
         251
        
        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
        
         267
        
        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
        
         206
        
        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
        
         96
        
        of file
        
         util_sleep.c
        
        .
       
References EMU_EnterEM2() , rtcCb() , RTCDRV_StartTimer() , RTCDRV_TimeRemaining() , and rtcdrvTimerTypeOneshot .