EZR32 Leopard Gecko Software Documentation  ezr32lg-doc-4.2.1
em_rtcc.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_RTCC_H__
34 #define __SILICON_LABS_EM_RTCC_H__
35 
36 #include "em_device.h"
37 #if defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 )
38 
39 #include <stdbool.h>
40 #include "em_assert.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ********************************* ENUM ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
64  rtccCntModeNormal = _RTCC_CTRL_CNTTICK_PRESC,
65 
68  rtccCntModeCalendar = _RTCC_CTRL_CNTTICK_CCV0MATCH
69 } RTCC_CntMode_TypeDef;
70 
72 typedef enum
73 {
74  rtccCntPresc_1 = _RTCC_CTRL_CNTPRESC_DIV1,
75  rtccCntPresc_2 = _RTCC_CTRL_CNTPRESC_DIV2,
76  rtccCntPresc_4 = _RTCC_CTRL_CNTPRESC_DIV4,
77  rtccCntPresc_8 = _RTCC_CTRL_CNTPRESC_DIV8,
78  rtccCntPresc_16 = _RTCC_CTRL_CNTPRESC_DIV16,
79  rtccCntPresc_32 = _RTCC_CTRL_CNTPRESC_DIV32,
80  rtccCntPresc_64 = _RTCC_CTRL_CNTPRESC_DIV64,
81  rtccCntPresc_128 = _RTCC_CTRL_CNTPRESC_DIV128,
82  rtccCntPresc_256 = _RTCC_CTRL_CNTPRESC_DIV256,
83  rtccCntPresc_512 = _RTCC_CTRL_CNTPRESC_DIV512,
84  rtccCntPresc_1024 = _RTCC_CTRL_CNTPRESC_DIV1024,
85  rtccCntPresc_2048 = _RTCC_CTRL_CNTPRESC_DIV2048,
86  rtccCntPresc_4096 = _RTCC_CTRL_CNTPRESC_DIV4096,
87  rtccCntPresc_8192 = _RTCC_CTRL_CNTPRESC_DIV8192,
88  rtccCntPresc_16384 = _RTCC_CTRL_CNTPRESC_DIV16384,
89  rtccCntPresc_32768 = _RTCC_CTRL_CNTPRESC_DIV32768
90 } RTCC_CntPresc_TypeDef;
91 
92 
94 typedef enum
95 {
97  rtccCntTickPresc = _RTCC_CTRL_CNTTICK_PRESC,
98 
101  rtccCntTickCCV0Match = _RTCC_CTRL_CNTTICK_CCV0MATCH
102 } RTCC_PrescMode_TypeDef;
103 
104 
106 typedef enum
107 {
108  rtccCapComChModeOff = _RTCC_CC_CTRL_MODE_OFF,
109  rtccCapComChModeCapture = _RTCC_CC_CTRL_MODE_INPUTCAPTURE,
110  rtccCapComChModeCompare = _RTCC_CC_CTRL_MODE_OUTPUTCOMPARE,
111 } RTCC_CapComChMode_TypeDef;
112 
114 typedef enum
115 {
116  rtccCompMatchOutActionPulse = _RTCC_CC_CTRL_CMOA_PULSE,
117  rtccCompMatchOutActionToggle = _RTCC_CC_CTRL_CMOA_TOGGLE,
118  rtccCompMatchOutActionClear = _RTCC_CC_CTRL_CMOA_CLEAR,
119  rtccCompMatchOutActionSet = _RTCC_CC_CTRL_CMOA_SET
120 } RTCC_CompMatchOutAction_TypeDef;
121 
122 
124 typedef enum
125 {
126  rtccPRSCh0 = _RTCC_CC_CTRL_PRSSEL_PRSCH0,
127  rtccPRSCh1 = _RTCC_CC_CTRL_PRSSEL_PRSCH1,
128  rtccPRSCh2 = _RTCC_CC_CTRL_PRSSEL_PRSCH2,
129  rtccPRSCh3 = _RTCC_CC_CTRL_PRSSEL_PRSCH3,
130  rtccPRSCh4 = _RTCC_CC_CTRL_PRSSEL_PRSCH4,
131  rtccPRSCh5 = _RTCC_CC_CTRL_PRSSEL_PRSCH5,
132  rtccPRSCh6 = _RTCC_CC_CTRL_PRSSEL_PRSCH6,
133  rtccPRSCh7 = _RTCC_CC_CTRL_PRSSEL_PRSCH7,
134  rtccPRSCh8 = _RTCC_CC_CTRL_PRSSEL_PRSCH8,
135  rtccPRSCh9 = _RTCC_CC_CTRL_PRSSEL_PRSCH9,
136  rtccPRSCh10 = _RTCC_CC_CTRL_PRSSEL_PRSCH10,
137  rtccPRSCh11 = _RTCC_CC_CTRL_PRSSEL_PRSCH11
138 } RTCC_PRSSel_TypeDef;
139 
140 
142 typedef enum
143 {
144  rtccInEdgeRising = _RTCC_CC_CTRL_ICEDGE_RISING,
145  rtccInEdgeFalling = _RTCC_CC_CTRL_ICEDGE_FALLING,
146  rtccInEdgeBoth = _RTCC_CC_CTRL_ICEDGE_BOTH,
147  rtccInEdgeNone = _RTCC_CC_CTRL_ICEDGE_NONE
148 } RTCC_InEdgeSel_TypeDef;
149 
150 
152 typedef enum
153 {
155  rtccCompBaseCnt = _RTCC_CC_CTRL_COMPBASE_CNT,
156 
158  rtccCompBasePreCnt = _RTCC_CC_CTRL_COMPBASE_PRECNT
159 } RTCC_CompBase_TypeDef;
160 
162 typedef enum
163 {
164  rtccDayCompareModeMonth = _RTCC_CC_CTRL_DAYCC_MONTH,
165  rtccDayCompareModeWeek = _RTCC_CC_CTRL_DAYCC_WEEK
166 } RTCC_DayCompareMode_TypeDef;
167 
168 /*******************************************************************************
169  ******************************* STRUCTS ***********************************
170  ******************************************************************************/
171 
173 typedef struct
174 {
176  bool enable;
177 
179  bool debugRun;
180 
182  bool precntWrapOnCCV0;
183 
185  bool cntWrapOnCCV1;
186 
188  RTCC_CntPresc_TypeDef presc;
189 
191  RTCC_PrescMode_TypeDef prescMode;
192 
193 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)
194 
196  bool enaBackupModeSet;
197 #endif
198 
201  bool enaOSCFailDetect;
202 
204  RTCC_CntMode_TypeDef cntMode;
205 
209  bool disLeapYearCorr;
210 } RTCC_Init_TypeDef;
211 
212 
214 typedef struct
215 {
217  RTCC_CapComChMode_TypeDef chMode;
218 
220  RTCC_CompMatchOutAction_TypeDef compMatchOutAction;
221 
223  RTCC_PRSSel_TypeDef prsSel;
224 
226  RTCC_InEdgeSel_TypeDef inputEdgeSel;
227 
229  RTCC_CompBase_TypeDef compBase;
230 
233  uint8_t compMask;
234 
236  RTCC_DayCompareMode_TypeDef dayCompMode;
237 } RTCC_CCChConf_TypeDef;
238 
239 
240 /*******************************************************************************
241  ******************************* DEFINES ***********************************
242  ******************************************************************************/
243 
245 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)
246 #define RTCC_INIT_DEFAULT \
247 { \
248  true, /* Start counting when init done. */ \
249  false, /* Disable RTCC during debug halt. */ \
250  false, /* Disable precounter wrap on ch. 0 CCV value. */ \
251  false, /* Disable counter wrap on ch. 1 CCV value. */ \
252  rtccCntPresc_32, /* 977 us per tick. */ \
253  rtccCntTickPresc, /* Counter increments according to prescaler value. */ \
254  false, /* No RTCC storage on backup mode entry. */ \
255  false, /* No RTCC oscillator failure detection. */ \
256  rtccCntModeNormal, /* Normal RTCC mode. */ \
257  false, /* No leap year correction. */ \
258 }
259 #else
260 #define RTCC_INIT_DEFAULT \
261 { \
262  true, /* Start counting when init done. */ \
263  false, /* Disable RTCC during debug halt. */ \
264  false, /* Disable precounter wrap on ch. 0 CCV value. */ \
265  false, /* Disable counter wrap on ch. 1 CCV value. */ \
266  rtccCntPresc_32, /* 977 us per tick. */ \
267  rtccCntTickPresc, /* Counter increments according to prescaler value. */ \
268  false, /* No RTCC oscillator failure detection. */ \
269  rtccCntModeNormal, /* Normal RTCC mode. */ \
270  false, /* No leap year correction. */ \
271 }
272 #endif
273 
275 #define RTCC_CH_INIT_COMPARE_DEFAULT \
276 { \
277  rtccCapComChModeCompare, /* Select output compare mode. */ \
278  rtccCompMatchOutActionPulse, /* Create pulse on compare match. */ \
279  rtccPRSCh0, /* PRS channel 0 (not used). */ \
280  rtccInEdgeNone, /* No edge detection. */ \
281  rtccCompBaseCnt, /* Counter comparison base. */ \
282  0, /* No compare mask bits set. */ \
283  rtccDayCompareModeMonth /* Don't care */ \
284 }
285 
287 #define RTCC_CH_INIT_CAPTURE_DEFAULT \
288 { \
289  rtccCapComChModeCapture, /* Select input capture mode. */ \
290  rtccCompMatchOutActionPulse, /* Create pulse on capture. */ \
291  rtccPRSCh0, /* PRS channel 0. */ \
292  rtccInEdgeRising, /* Rising edge detection. */ \
293  rtccCompBaseCnt, /* Don't care. */ \
294  0, /* Don't care. */ \
295  rtccDayCompareModeMonth /* Don't care */ \
296 }
297 
299 #define RTCC_CH_VALID( ch ) ( ( ch ) < 3 )
300 
301 /*******************************************************************************
302  ***************************** PROTOTYPES **********************************
303  ******************************************************************************/
304 
305 /***************************************************************************/
315 __STATIC_INLINE uint32_t RTCC_ChannelCCVGet( int ch )
316 {
317  EFM_ASSERT( RTCC_CH_VALID( ch ) );
318  return RTCC->CC[ ch ].CCV;
319 }
320 
321 /***************************************************************************/
331 __STATIC_INLINE void RTCC_ChannelCCVSet( int ch, uint32_t value )
332 {
333  EFM_ASSERT( RTCC_CH_VALID( ch ) );
334  RTCC->CC[ ch ].CCV = value;
335 }
336 
337 /***************************************************************************/
347 __STATIC_INLINE uint32_t RTCC_ChannelDateGet( int ch )
348 {
349  EFM_ASSERT( RTCC_CH_VALID( ch ) );
350  return RTCC->CC[ ch ].DATE;
351 }
352 
353 /***************************************************************************/
363 __STATIC_INLINE void RTCC_ChannelDateSet( int ch, uint32_t date )
364 {
365  EFM_ASSERT( RTCC_CH_VALID( ch ) );
366  RTCC->CC[ ch ].DATE = date;
367 }
368 
369 void RTCC_ChannelInit( int ch, RTCC_CCChConf_TypeDef const *confPtr );
370 
371 /***************************************************************************/
381 __STATIC_INLINE uint32_t RTCC_ChannelTimeGet( int ch )
382 {
383  EFM_ASSERT( RTCC_CH_VALID( ch ) );
384  return RTCC->CC[ ch ].TIME;
385 }
386 
387 /***************************************************************************/
397 __STATIC_INLINE void RTCC_ChannelTimeSet( int ch, uint32_t time )
398 {
399  EFM_ASSERT( RTCC_CH_VALID( ch ) );
400  RTCC->CC[ ch ].TIME = time;
401 }
402 
403 /***************************************************************************/
410 __STATIC_INLINE uint32_t RTCC_CombinedCounterGet( void )
411 {
412  return RTCC->COMBCNT;
413 }
414 
415 /***************************************************************************/
422 __STATIC_INLINE uint32_t RTCC_CounterGet( void )
423 {
424  return RTCC->CNT;
425 }
426 
427 /***************************************************************************/
434 __STATIC_INLINE void RTCC_CounterSet( uint32_t value )
435 {
436  RTCC->CNT = value;
437 }
438 
439 /***************************************************************************/
446 __STATIC_INLINE uint32_t RTCC_DateGet( void )
447 {
448  return RTCC->DATE;
449 }
450 
451 /***************************************************************************/
458 __STATIC_INLINE void RTCC_DateSet( uint32_t date )
459 {
460  RTCC->DATE = date;
461 }
462 
463 /***************************************************************************/
470 __STATIC_INLINE void RTCC_EM4WakeupEnable( bool enable )
471 {
472  if ( enable )
473  {
474  RTCC->EM4WUEN = RTCC_EM4WUEN_EM4WU;
475  }
476  else
477  {
478  RTCC->EM4WUEN = 0;
479  }
480 }
481 
482 void RTCC_Enable( bool enable );
483 
484 void RTCC_Init( const RTCC_Init_TypeDef *init );
485 
486 /***************************************************************************/
494 __STATIC_INLINE void RTCC_IntClear( uint32_t flags )
495 {
496  RTCC->IFC = flags;
497 }
498 
499 /***************************************************************************/
507 __STATIC_INLINE void RTCC_IntDisable( uint32_t flags )
508 {
509  RTCC->IEN &= ~flags;
510 }
511 
512 /***************************************************************************/
525 __STATIC_INLINE void RTCC_IntEnable( uint32_t flags )
526 {
527  RTCC->IEN |= flags;
528 }
529 
530 /***************************************************************************/
541 __STATIC_INLINE uint32_t RTCC_IntGet( void )
542 {
543  return RTCC->IF;
544 }
545 
546 /***************************************************************************/
557 __STATIC_INLINE uint32_t RTCC_IntGetEnabled( void )
558 {
559  uint32_t tmp;
560 
561  tmp = RTCC->IEN;
562 
563  /* Bitwise AND of pending and enabled interrupt flags. */
564  return RTCC->IF & tmp;
565 }
566 
567 /***************************************************************************/
575 __STATIC_INLINE void RTCC_IntSet( uint32_t flags )
576 {
577  RTCC->IFS = flags;
578 }
579 
580 /***************************************************************************/
589 __STATIC_INLINE void RTCC_Lock( void )
590 {
591  RTCC->LOCK = RTCC_LOCK_LOCKKEY_LOCK;
592 }
593 
594 /***************************************************************************/
601 __STATIC_INLINE uint32_t RTCC_PreCounterGet( void )
602 {
603  return RTCC->PRECNT;
604 }
605 
606 /***************************************************************************/
613 __STATIC_INLINE void RTCC_PreCounterSet( uint32_t preCntVal )
614 {
615  RTCC->PRECNT = preCntVal;
616 }
617 
618 void RTCC_Reset( void );
619 
620 /***************************************************************************/
627 __STATIC_INLINE void RTCC_RetentionRamPowerDown( void )
628 {
629  RTCC->POWERDOWN = RTCC_POWERDOWN_RAM;
630 }
631 
632 void RTCC_StatusClear( void );
633 
634 /***************************************************************************/
641 __STATIC_INLINE uint32_t RTCC_StatusGet( void )
642 {
643  while ( RTCC->SYNCBUSY & RTCC_SYNCBUSY_CMD )
644  {
645  // Wait for syncronization.
646  }
647  return RTCC->STATUS;
648 }
649 
650 /***************************************************************************/
657 __STATIC_INLINE uint32_t RTCC_TimeGet( void )
658 {
659  return RTCC->TIME;
660 }
661 
662 /***************************************************************************/
669 __STATIC_INLINE void RTCC_TimeSet( uint32_t time )
670 {
671  RTCC->TIME = time;
672 }
673 
674 /***************************************************************************/
683 __STATIC_INLINE void RTCC_Unlock( void )
684 {
685  RTCC->LOCK = RTCC_LOCK_LOCKKEY_UNLOCK;
686 }
687 
691 #ifdef __cplusplus
692 }
693 #endif
694 
695 #endif /* defined( RTCC_COUNT ) && ( RTC_COUNT == 1 ) */
696 #endif /* __SILICON_LABS_EM_RTCC_H__ */
Emlib peripheral API "assert" implementation.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.