EFM32 Zero Gecko Software Documentation  efm32zg-doc-4.2.1
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 /***************************************************************************/
79 /*******************************************************************************
80  ********************************* ENUM ************************************
81  ******************************************************************************/
82 
84 typedef enum
85 {
86  cryotimerPresc_1 = _CRYOTIMER_CTRL_PRESC_DIV1,
87  cryotimerPresc_2 = _CRYOTIMER_CTRL_PRESC_DIV2,
88  cryotimerPresc_4 = _CRYOTIMER_CTRL_PRESC_DIV4,
89  cryotimerPresc_8 = _CRYOTIMER_CTRL_PRESC_DIV8,
90  cryotimerPresc_16 = _CRYOTIMER_CTRL_PRESC_DIV16,
91  cryotimerPresc_32 = _CRYOTIMER_CTRL_PRESC_DIV32,
92  cryotimerPresc_64 = _CRYOTIMER_CTRL_PRESC_DIV64,
93  cryotimerPresc_128 = _CRYOTIMER_CTRL_PRESC_DIV128,
94 } CRYOTIMER_Presc_TypeDef;
95 
97 typedef enum
98 {
99  cryotimerOscLFRCO = _CRYOTIMER_CTRL_OSCSEL_LFRCO,
100  cryotimerOscLFXO = _CRYOTIMER_CTRL_OSCSEL_LFXO,
101  cryotimerOscULFRCO = _CRYOTIMER_CTRL_OSCSEL_ULFRCO,
102 } CRYOTIMER_Osc_TypeDef;
103 
105 typedef enum
106 {
107  cryotimerPeriod_1 = 0,
108  cryotimerPeriod_2 = 1,
109  cryotimerPeriod_4 = 2,
110  cryotimerPeriod_8 = 3,
111  cryotimerPeriod_16 = 4,
112  cryotimerPeriod_32 = 5,
113  cryotimerPeriod_64 = 6,
114  cryotimerPeriod_128 = 7,
115  cryotimerPeriod_256 = 8,
116  cryotimerPeriod_512 = 9,
117  cryotimerPeriod_1k = 10,
118  cryotimerPeriod_2k = 11,
119  cryotimerPeriod_4k = 12,
120  cryotimerPeriod_8k = 13,
121  cryotimerPeriod_16k = 14,
122  cryotimerPeriod_32k = 15,
123  cryotimerPeriod_64k = 16,
124  cryotimerPeriod_128k = 17,
125  cryotimerPeriod_256k = 18,
126  cryotimerPeriod_512k = 19,
127  cryotimerPeriod_1m = 20,
128  cryotimerPeriod_2m = 21,
129  cryotimerPeriod_4m = 22,
130  cryotimerPeriod_8m = 23,
131  cryotimerPeriod_16m = 24,
132  cryotimerPeriod_32m = 25,
133  cryotimerPeriod_64m = 26,
134  cryotimerPeriod_128m = 27,
135  cryotimerPeriod_256m = 28,
136  cryotimerPeriod_512m = 29,
137  cryotimerPeriod_1024m = 30,
138  cryotimerPeriod_2048m = 31,
139  cryotimerPeriod_4096m = 32,
140 } CRYOTIMER_Period_TypeDef;
141 
142 /*******************************************************************************
143  ******************************* STRUCTS ***********************************
144  ******************************************************************************/
145 
147 typedef struct
148 {
150  bool enable;
151 
153  bool debugRun;
154 
156  bool em4Wakeup;
157 
159  CRYOTIMER_Osc_TypeDef osc;
160 
162  CRYOTIMER_Presc_TypeDef presc;
163 
165  CRYOTIMER_Period_TypeDef period;
166 } CRYOTIMER_Init_TypeDef;
167 
168 /*******************************************************************************
169  ******************************* DEFINES ***********************************
170  ******************************************************************************/
171 
173 #define CRYOTIMER_INIT_DEFAULT \
174 { \
175  true, /* Start counting when init done. */ \
176  false, /* Disable CRYOTIMER during debug halt. */ \
177  false, /* Disable EM4 wakeup. */ \
178  cryotimerOscLFRCO, /* Select Low Frequency RC Oscillator. */ \
179  cryotimerPresc_1, /* LF Oscillator frequency undivided. */ \
180  cryotimerPeriod_4096m, /* Wakeup event after 4096M pre-scaled clock cycles. */ \
181 }
182 
183 /*******************************************************************************
184  ***************************** PROTOTYPES **********************************
185  ******************************************************************************/
186 
187 /***************************************************************************/
194 __STATIC_INLINE void CRYOTIMER_IntClear(uint32_t flags)
195 {
196  CRYOTIMER->IFC = flags & _CRYOTIMER_IFC_MASK;
197 }
198 
199 /***************************************************************************/
209 __STATIC_INLINE uint32_t CRYOTIMER_IntGet(void)
210 {
211  return CRYOTIMER->IF;
212 }
213 
214 /***************************************************************************/
228 __STATIC_INLINE uint32_t CRYOTIMER_IntGetEnabled(void)
229 {
230  uint32_t ien;
231 
232  ien = CRYOTIMER->IEN & _CRYOTIMER_IEN_MASK;
233  return CRYOTIMER->IF & ien;
234 }
235 
236 /***************************************************************************/
243 __STATIC_INLINE void CRYOTIMER_IntEnable(uint32_t flags)
244 {
245  CRYOTIMER->IEN |= (flags & _CRYOTIMER_IEN_MASK);
246 }
247 
248 /***************************************************************************/
255 __STATIC_INLINE void CRYOTIMER_IntDisable(uint32_t flags)
256 {
257  CRYOTIMER->IEN &= ~(flags & _CRYOTIMER_IEN_MASK);
258 }
259 
260 /***************************************************************************/
270 __STATIC_INLINE void CRYOTIMER_IntSet(uint32_t flags)
271 {
272  CRYOTIMER->IFS = flags & _CRYOTIMER_IFS_MASK;
273 }
274 
275 /***************************************************************************/
288 __STATIC_INLINE void CRYOTIMER_PeriodSet(uint32_t period)
289 {
290  CRYOTIMER->PERIODSEL = period & _CRYOTIMER_PERIODSEL_MASK;
291 }
292 
293 /***************************************************************************/
306 __STATIC_INLINE uint32_t CRYOTIMER_PeriodGet(void)
307 {
308  return CRYOTIMER->PERIODSEL;
309 }
310 
311 /***************************************************************************/
318 __STATIC_INLINE uint32_t CRYOTIMER_CounterGet(void)
319 {
320  return CRYOTIMER->CNT;
321 }
322 
323 /***************************************************************************/
330 __STATIC_INLINE void CRYOTIMER_EM4WakeupEnable(bool enable)
331 {
332  BUS_RegBitWrite((&CRYOTIMER->EM4WUEN), _CRYOTIMER_EM4WUEN_EM4WU_SHIFT, enable);
333 }
334 
335 /***************************************************************************/
342 __STATIC_INLINE void CRYOTIMER_Enable(bool enable)
343 {
344  BUS_RegBitWrite((&CRYOTIMER->CTRL), _CRYOTIMER_CTRL_EN_SHIFT, enable);
345 }
346 
347 void CRYOTIMER_Init(const CRYOTIMER_Init_TypeDef *init);
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
356 #endif /* defined(CRYOTIMER_PRESENT) && (CRYOTIMER_COUNT == 1) */
357 #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:146