EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
em_cryotimer.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_CRYOTIMER_H
34 #define EM_CRYOTIMER_H
35 
36 #include <stdbool.h>
37 #include "em_device.h"
38 #include "em_bus.h"
39 
40 #if defined(CRYOTIMER_PRESENT) && (CRYOTIMER_COUNT == 1)
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
114 /*******************************************************************************
115  ********************************* ENUM ************************************
116  ******************************************************************************/
117 
119 typedef enum
120 {
121  cryotimerPresc_1 = _CRYOTIMER_CTRL_PRESC_DIV1,
122  cryotimerPresc_2 = _CRYOTIMER_CTRL_PRESC_DIV2,
123  cryotimerPresc_4 = _CRYOTIMER_CTRL_PRESC_DIV4,
124  cryotimerPresc_8 = _CRYOTIMER_CTRL_PRESC_DIV8,
125  cryotimerPresc_16 = _CRYOTIMER_CTRL_PRESC_DIV16,
126  cryotimerPresc_32 = _CRYOTIMER_CTRL_PRESC_DIV32,
127  cryotimerPresc_64 = _CRYOTIMER_CTRL_PRESC_DIV64,
128  cryotimerPresc_128 = _CRYOTIMER_CTRL_PRESC_DIV128,
129 } CRYOTIMER_Presc_TypeDef;
130 
132 typedef enum
133 {
134  cryotimerOscLFRCO = _CRYOTIMER_CTRL_OSCSEL_LFRCO,
135  cryotimerOscLFXO = _CRYOTIMER_CTRL_OSCSEL_LFXO,
136  cryotimerOscULFRCO = _CRYOTIMER_CTRL_OSCSEL_ULFRCO,
137 } CRYOTIMER_Osc_TypeDef;
138 
140 typedef enum
141 {
142  cryotimerPeriod_1 = 0,
143  cryotimerPeriod_2 = 1,
144  cryotimerPeriod_4 = 2,
145  cryotimerPeriod_8 = 3,
146  cryotimerPeriod_16 = 4,
147  cryotimerPeriod_32 = 5,
148  cryotimerPeriod_64 = 6,
149  cryotimerPeriod_128 = 7,
150  cryotimerPeriod_256 = 8,
151  cryotimerPeriod_512 = 9,
152  cryotimerPeriod_1k = 10,
153  cryotimerPeriod_2k = 11,
154  cryotimerPeriod_4k = 12,
155  cryotimerPeriod_8k = 13,
156  cryotimerPeriod_16k = 14,
157  cryotimerPeriod_32k = 15,
158  cryotimerPeriod_64k = 16,
159  cryotimerPeriod_128k = 17,
160  cryotimerPeriod_256k = 18,
161  cryotimerPeriod_512k = 19,
162  cryotimerPeriod_1m = 20,
163  cryotimerPeriod_2m = 21,
164  cryotimerPeriod_4m = 22,
165  cryotimerPeriod_8m = 23,
166  cryotimerPeriod_16m = 24,
167  cryotimerPeriod_32m = 25,
168  cryotimerPeriod_64m = 26,
169  cryotimerPeriod_128m = 27,
170  cryotimerPeriod_256m = 28,
171  cryotimerPeriod_512m = 29,
172  cryotimerPeriod_1024m = 30,
173  cryotimerPeriod_2048m = 31,
174  cryotimerPeriod_4096m = 32,
175 } CRYOTIMER_Period_TypeDef;
176 
177 /*******************************************************************************
178  ******************************* STRUCTS ***********************************
179  ******************************************************************************/
180 
182 typedef struct
183 {
185  bool enable;
186 
188  bool debugRun;
189 
191  bool em4Wakeup;
192 
194  CRYOTIMER_Osc_TypeDef osc;
195 
197  CRYOTIMER_Presc_TypeDef presc;
198 
200  CRYOTIMER_Period_TypeDef period;
201 } CRYOTIMER_Init_TypeDef;
202 
203 /*******************************************************************************
204  ******************************* DEFINES ***********************************
205  ******************************************************************************/
206 
208 #define CRYOTIMER_INIT_DEFAULT \
209 { \
210  true, /* Start counting when init done. */ \
211  false, /* Disable CRYOTIMER during debug halt. */ \
212  false, /* Disable EM4 wakeup. */ \
213  cryotimerOscLFRCO, /* Select Low Frequency RC Oscillator. */ \
214  cryotimerPresc_1, /* LF Oscillator frequency undivided. */ \
215  cryotimerPeriod_4096m, /* Wakeup event after 4096M pre-scaled clock cycles. */ \
216 }
217 
218 /*******************************************************************************
219  ***************************** PROTOTYPES **********************************
220  ******************************************************************************/
221 
222 /***************************************************************************/
229 __STATIC_INLINE void CRYOTIMER_IntClear(uint32_t flags)
230 {
231  CRYOTIMER->IFC = flags & _CRYOTIMER_IFC_MASK;
232 }
233 
234 /***************************************************************************/
245 __STATIC_INLINE uint32_t CRYOTIMER_IntGet(void)
246 {
247  return CRYOTIMER->IF;
248 }
249 
250 /***************************************************************************/
264 __STATIC_INLINE uint32_t CRYOTIMER_IntGetEnabled(void)
265 {
266  uint32_t ien;
267 
268  ien = CRYOTIMER->IEN & _CRYOTIMER_IEN_MASK;
269  return CRYOTIMER->IF & ien;
270 }
271 
272 /***************************************************************************/
279 __STATIC_INLINE void CRYOTIMER_IntEnable(uint32_t flags)
280 {
281  CRYOTIMER->IEN |= (flags & _CRYOTIMER_IEN_MASK);
282 }
283 
284 /***************************************************************************/
291 __STATIC_INLINE void CRYOTIMER_IntDisable(uint32_t flags)
292 {
293  CRYOTIMER->IEN &= ~(flags & _CRYOTIMER_IEN_MASK);
294 }
295 
296 /***************************************************************************/
307 __STATIC_INLINE void CRYOTIMER_IntSet(uint32_t flags)
308 {
309  CRYOTIMER->IFS = flags & _CRYOTIMER_IFS_MASK;
310 }
311 
312 /***************************************************************************/
325 __STATIC_INLINE void CRYOTIMER_PeriodSet(uint32_t period)
326 {
327  CRYOTIMER->PERIODSEL = period & _CRYOTIMER_PERIODSEL_MASK;
328 }
329 
330 /***************************************************************************/
343 __STATIC_INLINE uint32_t CRYOTIMER_PeriodGet(void)
344 {
345  return CRYOTIMER->PERIODSEL;
346 }
347 
348 /***************************************************************************/
355 __STATIC_INLINE uint32_t CRYOTIMER_CounterGet(void)
356 {
357  return CRYOTIMER->CNT;
358 }
359 
360 /***************************************************************************/
367 __STATIC_INLINE void CRYOTIMER_EM4WakeupEnable(bool enable)
368 {
369  BUS_RegBitWrite((&CRYOTIMER->EM4WUEN), _CRYOTIMER_EM4WUEN_EM4WU_SHIFT, enable);
370 }
371 
372 /***************************************************************************/
379 __STATIC_INLINE void CRYOTIMER_Enable(bool enable)
380 {
381  BUS_RegBitWrite((&CRYOTIMER->CTRL), _CRYOTIMER_CTRL_EN_SHIFT, enable);
382 }
383 
384 void CRYOTIMER_Init(const CRYOTIMER_Init_TypeDef *init);
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 
393 #endif /* defined(CRYOTIMER_PRESENT) && (CRYOTIMER_COUNT == 1) */
394 #endif /* EM_CRYOTIMER_H */
RAM and peripheral bit-field set and clear API.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.
Definition: em_bus.h:148