EFR32 Blue Gecko 1 Software Documentation  efr32bg1-doc-5.1.2
em_burtc.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_BURTC_H
34 #define EM_BURTC_H
35 
36 #include "em_device.h"
37 #if defined(BURTC_PRESENT)
38 
39 #include <stdbool.h>
40 #include "em_assert.h"
41 #include "em_bus.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /***************************************************************************/
52 /***************************************************************************/
57 /*******************************************************************************
58  ******************************* DEFINES ***********************************
59  ******************************************************************************/
60 
62 #define burtcClkDiv_1 1
63 #define burtcClkDiv_2 2
64 #define burtcClkDiv_4 4
65 #define burtcClkDiv_8 8
66 #define burtcClkDiv_16 16
67 #define burtcClkDiv_32 32
68 #define burtcClkDiv_64 64
69 #define burtcClkDiv_128 128
71 /*******************************************************************************
72  ******************************** ENUMS ************************************
73  ******************************************************************************/
74 
76 typedef enum
77 {
79  burtcClkSelULFRCO = BURTC_CTRL_CLKSEL_ULFRCO,
81  burtcClkSelLFRCO = BURTC_CTRL_CLKSEL_LFRCO,
83  burtcClkSelLFXO = BURTC_CTRL_CLKSEL_LFXO
84 } BURTC_ClkSel_TypeDef;
85 
86 
88 typedef enum
89 {
91  burtcModeDisable = BURTC_CTRL_MODE_DISABLE,
93  burtcModeEM2 = BURTC_CTRL_MODE_EM2EN,
95  burtcModeEM3 = BURTC_CTRL_MODE_EM3EN,
97  burtcModeEM4 = BURTC_CTRL_MODE_EM4EN,
98 } BURTC_Mode_TypeDef;
99 
101 typedef enum
102 {
104  burtcLPDisable = BURTC_LPMODE_LPMODE_DISABLE,
106  burtcLPEnable = BURTC_LPMODE_LPMODE_ENABLE,
108  burtcLPBU = BURTC_LPMODE_LPMODE_BUEN
109 } BURTC_LP_TypeDef;
110 
111 /*******************************************************************************
112  ******************************* STRUCTS ***********************************
113  ******************************************************************************/
114 
116 typedef struct
117 {
118  bool enable;
120  BURTC_Mode_TypeDef mode;
121  bool debugRun;
122  BURTC_ClkSel_TypeDef clkSel;
123  uint32_t clkDiv;
125  uint32_t lowPowerComp;
126  bool timeStamp;
128  bool compare0Top;
130  BURTC_LP_TypeDef lowPowerMode;
131 } BURTC_Init_TypeDef;
132 
134 #define BURTC_INIT_DEFAULT \
135 { \
136  true, \
137  burtcModeEM2, \
138  false, \
139  burtcClkSelULFRCO, \
140  burtcClkDiv_1, \
141  0, \
142  true, \
143  false, \
144  burtcLPDisable, \
145 }
146 
147 /*******************************************************************************
148  ***************************** PROTOTYPES **********************************
149  ******************************************************************************/
150 
151 /***************************************************************************/
160 __STATIC_INLINE void BURTC_IntClear(uint32_t flags)
161 {
162  BURTC->IFC = flags;
163 }
164 
165 
166 /***************************************************************************/
175 __STATIC_INLINE void BURTC_IntDisable(uint32_t flags)
176 {
177  BURTC->IEN &= ~(flags);
178 }
179 
180 
181 /***************************************************************************/
195 __STATIC_INLINE void BURTC_IntEnable(uint32_t flags)
196 {
197  BURTC->IEN |= flags;
198 }
199 
200 
201 /***************************************************************************/
212 __STATIC_INLINE uint32_t BURTC_IntGet(void)
213 {
214  return(BURTC->IF);
215 }
216 
217 
218 /***************************************************************************/
230 __STATIC_INLINE uint32_t BURTC_IntGetEnabled(void)
231 {
232  uint32_t tmp;
233 
234  /* Get enabled interrupts */
235  tmp = BURTC->IEN;
236 
237  /* Return set intterupts */
238  return BURTC->IF & tmp;
239 }
240 
241 
242 /***************************************************************************/
251 __STATIC_INLINE void BURTC_IntSet(uint32_t flags)
252 {
253  BURTC->IFS = flags;
254 }
255 
256 
257 /***************************************************************************/
263 __STATIC_INLINE uint32_t BURTC_Status(void)
264 {
265  return BURTC->STATUS;
266 }
267 
268 
269 /***************************************************************************/
273 __STATIC_INLINE void BURTC_StatusClear(void)
274 {
275  BURTC->CMD = BURTC_CMD_CLRSTATUS;
276 }
277 
278 
279 /***************************************************************************/
285 __STATIC_INLINE void BURTC_Enable(bool enable)
286 {
287  /* Note! If mode is disabled, BURTC counter will not start */
288  EFM_ASSERT(((enable == true)
289  && ((BURTC->CTRL & _BURTC_CTRL_MODE_MASK)
290  != BURTC_CTRL_MODE_DISABLE))
291  || (enable == false));
292  if (enable)
293  {
294  BUS_RegBitWrite(&BURTC->CTRL, _BURTC_CTRL_RSTEN_SHIFT, 0);
295  }
296  else
297  {
298  BUS_RegBitWrite(&BURTC->CTRL, _BURTC_CTRL_RSTEN_SHIFT, 1);
299  }
300 }
301 
302 
303 /***************************************************************************/
309 __STATIC_INLINE uint32_t BURTC_CounterGet(void)
310 {
311  return BURTC->CNT;
312 }
313 
314 
315 /***************************************************************************/
321 __STATIC_INLINE uint32_t BURTC_TimestampGet(void)
322 {
323  return BURTC->TIMESTAMP;
324 }
325 
326 
327 /***************************************************************************/
331 __STATIC_INLINE void BURTC_FreezeEnable(bool enable)
332 {
333  BUS_RegBitWrite(&BURTC->FREEZE, _BURTC_FREEZE_REGFREEZE_SHIFT, enable);
334 }
335 
336 
337 /***************************************************************************/
345 __STATIC_INLINE void BURTC_Powerdown(bool enable)
346 {
347  BUS_RegBitWrite(&BURTC->POWERDOWN, _BURTC_POWERDOWN_RAM_SHIFT, enable);
348 }
349 
350 
351 /***************************************************************************/
360 __STATIC_INLINE void BURTC_RetRegSet(uint32_t num, uint32_t data)
361 {
362  EFM_ASSERT(num <= 127);
363 
364  BURTC->RET[num].REG = data;
365 }
366 
367 
368 /***************************************************************************/
375 __STATIC_INLINE uint32_t BURTC_RetRegGet(uint32_t num)
376 {
377  EFM_ASSERT(num <= 127);
378 
379  return BURTC->RET[num].REG;
380 }
381 
382 
383 /***************************************************************************/
387 __STATIC_INLINE void BURTC_Lock(void)
388 {
389  BURTC->LOCK = BURTC_LOCK_LOCKKEY_LOCK;
390 }
391 
392 
393 /***************************************************************************/
397 __STATIC_INLINE void BURTC_Unlock(void)
398 {
399  BURTC->LOCK = BURTC_LOCK_LOCKKEY_UNLOCK;
400 }
401 
402 
403 void BURTC_Reset(void);
404 void BURTC_Init(const BURTC_Init_TypeDef *burtcInit);
405 void BURTC_CounterReset(void);
406 void BURTC_CompareSet(unsigned int comp, uint32_t value);
407 uint32_t BURTC_CompareGet(unsigned int comp);
408 uint32_t BURTC_ClockFreqGet(void);
409 
410 
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #endif /* BURTC_PRESENT */
419 #endif /* EM_BURTC_H */
Emlib peripheral API "assert" implementation.
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