EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
util.c
Go to the documentation of this file.
1 /***************************************************************************/
16 #include "thunderboard/board.h"
17 #include "thunderboard/util.h"
18 #include "em_cmu.h"
19 #include "em_emu.h"
20 #include "em_gpio.h"
21 
22 /***************************************************************************/
30 /***************************************************************************/
36 /* Local variables */
37 volatile uint32_t msTickCount;
43 /***************************************************************************/
49 /***************************************************************************/
57 uint32_t UTIL_init( void )
58 {
59 
60  uint32_t stat;
61  uint32_t ticks;
62 
63  /* Setup SysTick Timer for 1 msec interrupts */
64  ticks = CMU_ClockFreqGet( cmuClock_CORE ) / 1000;
65  stat = SysTick_Config( ticks );
66 
67  return stat;
68 
69 }
70 
71 /***************************************************************************/
78 void SysTick_Handler( void )
79 {
80 
81  msTickCount++;
82 
83  return;
84 
85 }
86 
87 /***************************************************************************/
97 void UTIL_delay( uint32_t ms )
98 {
99 
100  uint32_t curTicks;
101 
102  curTicks = msTickCount;
103  while( ( msTickCount - curTicks ) < ms ) {
104  EMU_EnterEM1();
105  }
106 
107  return;
108 
109 }
110 
111 /***************************************************************************/
118 void UTIL_shutdown( void )
119 {
120 
122 
124  EMU_EM4Init( &em4Init );
125 
126  /* Set up for EM4 wakeup from gpio PD14 (EM4WU4). Need to enable glitch filter */
129 
130  EMU_EnterEM4();
131 
132  return;
133 
134 }
135 
Clock management unit (CMU) API.
EMU_EM4PinRetention_TypeDef pinRetentionMode
Definition: em_emu.h:427
void EMU_EnterEM4(void)
Enter energy mode 4 (EM4).
Definition: em_emu.c:705
void EMU_EM4Init(const EMU_EM4Init_TypeDef *em4Init)
Update EMU module with Energy Mode 4 configuration.
Definition: em_emu.c:1105
void UTIL_delay(uint32_t ms)
Delays number of msTick Systicks (1 ms)
Definition: util.c:97
#define BOARD_BUTTON_LEFT_PIN
Definition: board.h:76
void GPIO_EM4EnablePinWakeup(uint32_t pinmask, uint32_t polaritymask)
Enable GPIO pin wake-up from EM4. When the function exits, EM4 mode can be safely entered...
Definition: em_gpio.c:361
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Definition: em_gpio.c:269
__STATIC_INLINE void EMU_EnterEM1(void)
Enter energy mode 1 (EM1).
Definition: em_emu.h:713
General Purpose IO (GPIO) peripheral API.
uint32_t UTIL_init(void)
Sets up the SysTick timer for 1ms interrupts and initializes and starts the RTC timer.
Definition: util.c:57
Utility Functions for the Thunderboard Sense.
Energy management unit (EMU) peripheral API.
void SysTick_Handler(void)
Interrupt Service Routine for system tick counter.
Definition: util.c:78
#define _GPIO_EM4WUEN_EM4WUEN_SHIFT
#define BOARD_BUTTON_PORT
Definition: board.h:70
uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock)
Get clock frequency for a clock point.
Definition: em_cmu.c:1550
BOARD module header file.
void UTIL_shutdown(void)
Enter lowest power shutdown mode, EM4S.
Definition: util.c:118
#define EMU_EM4INIT_DEFAULT
Definition: em_emu.h:460