]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_rtcc.h
Add Pearl Gecko demo.
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_rtcc.h
1 /***************************************************************************//**\r
2  * @file\r
3  * @brief Real Time Counter (RTCC) peripheral API.\r
4  * @version 4.2.1\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>\r
8  *******************************************************************************\r
9  *\r
10  * Permission is granted to anyone to use this software for any purpose,\r
11  * including commercial applications, and to alter it and redistribute it\r
12  * freely, subject to the following restrictions:\r
13  *\r
14  * 1. The origin of this software must not be misrepresented; you must not\r
15  *    claim that you wrote the original software.\r
16  * 2. Altered source versions must be plainly marked as such, and must not be\r
17  *    misrepresented as being the original software.\r
18  * 3. This notice may not be removed or altered from any source distribution.\r
19  *\r
20  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no\r
21  * obligation to support this Software. Silicon Labs is providing the\r
22  * Software "AS IS", with no express or implied warranties of any kind,\r
23  * including, but not limited to, any implied warranties of merchantability\r
24  * or fitness for any particular purpose or warranties against infringement\r
25  * of any proprietary rights of a third party.\r
26  *\r
27  * Silicon Labs will not be liable for any consequential, incidental, or\r
28  * special damages, or any other relief, or for any claim by any third party,\r
29  * arising from your use of this Software.\r
30  *\r
31  ******************************************************************************/\r
32 \r
33 #ifndef __SILICON_LABS_EM_RTCC_H__\r
34 #define __SILICON_LABS_EM_RTCC_H__\r
35 \r
36 #include "em_device.h"\r
37 #if defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 )\r
38 \r
39 #include <stdbool.h>\r
40 #include "em_assert.h"\r
41 \r
42 #ifdef __cplusplus\r
43 extern "C" {\r
44 #endif\r
45 \r
46 /***************************************************************************//**\r
47  * @addtogroup EM_Library\r
48  * @{\r
49  ******************************************************************************/\r
50 \r
51 /***************************************************************************//**\r
52  * @addtogroup RTCC\r
53  * @{\r
54  ******************************************************************************/\r
55 \r
56 /*******************************************************************************\r
57  *********************************   ENUM   ************************************\r
58  ******************************************************************************/\r
59 \r
60 /** Operational mode of the counter. */\r
61 typedef enum\r
62 {\r
63   /** Normal counter mode. The counter is incremented by 1 for each tick. */\r
64   rtccCntModeNormal = _RTCC_CTRL_CNTTICK_PRESC,\r
65 \r
66   /** Calendar mode. Refer to the RTCC chapter of the Reference Manual for more\r
67    *  details on the calendar mode. */\r
68   rtccCntModeCalendar = _RTCC_CTRL_CNTTICK_CCV0MATCH\r
69 } RTCC_CntMode_TypeDef;\r
70 \r
71 /** Counter prescaler selection. */\r
72 typedef enum\r
73 {\r
74   rtccCntPresc_1     = _RTCC_CTRL_CNTPRESC_DIV1,      /**< Divide clock by 1. */\r
75   rtccCntPresc_2     = _RTCC_CTRL_CNTPRESC_DIV2,      /**< Divide clock by 2. */\r
76   rtccCntPresc_4     = _RTCC_CTRL_CNTPRESC_DIV4,      /**< Divide clock by 4. */\r
77   rtccCntPresc_8     = _RTCC_CTRL_CNTPRESC_DIV8,      /**< Divide clock by 8. */\r
78   rtccCntPresc_16    = _RTCC_CTRL_CNTPRESC_DIV16,     /**< Divide clock by 16. */\r
79   rtccCntPresc_32    = _RTCC_CTRL_CNTPRESC_DIV32,     /**< Divide clock by 32. */\r
80   rtccCntPresc_64    = _RTCC_CTRL_CNTPRESC_DIV64,     /**< Divide clock by 64. */\r
81   rtccCntPresc_128   = _RTCC_CTRL_CNTPRESC_DIV128,    /**< Divide clock by 128. */\r
82   rtccCntPresc_256   = _RTCC_CTRL_CNTPRESC_DIV256,    /**< Divide clock by 256. */\r
83   rtccCntPresc_512   = _RTCC_CTRL_CNTPRESC_DIV512,    /**< Divide clock by 512. */\r
84   rtccCntPresc_1024  = _RTCC_CTRL_CNTPRESC_DIV1024,   /**< Divide clock by 1024. */\r
85   rtccCntPresc_2048  = _RTCC_CTRL_CNTPRESC_DIV2048,   /**< Divide clock by 2048. */\r
86   rtccCntPresc_4096  = _RTCC_CTRL_CNTPRESC_DIV4096,   /**< Divide clock by 4096. */\r
87   rtccCntPresc_8192  = _RTCC_CTRL_CNTPRESC_DIV8192,   /**< Divide clock by 8192. */\r
88   rtccCntPresc_16384 = _RTCC_CTRL_CNTPRESC_DIV16384,  /**< Divide clock by 16384. */\r
89   rtccCntPresc_32768 = _RTCC_CTRL_CNTPRESC_DIV32768   /**< Divide clock by 32768. */\r
90 } RTCC_CntPresc_TypeDef;\r
91 \r
92 \r
93 /** Prescaler mode of the RTCC counter. */\r
94 typedef enum\r
95 {\r
96   /** CNT register ticks according to the prescaler value. */\r
97   rtccCntTickPresc = _RTCC_CTRL_CNTTICK_PRESC,\r
98 \r
99   /** CNT register ticks when PRECNT matches the 15 least significant bits of\r
100    *  ch. 0 CCV register. */\r
101   rtccCntTickCCV0Match = _RTCC_CTRL_CNTTICK_CCV0MATCH\r
102 } RTCC_PrescMode_TypeDef;\r
103 \r
104 \r
105 /** Capture/Compare channel mode. */\r
106 typedef enum\r
107 {\r
108   rtccCapComChModeOff     = _RTCC_CC_CTRL_MODE_OFF,           /**< Capture/Compare channel turned off. */\r
109   rtccCapComChModeCapture = _RTCC_CC_CTRL_MODE_INPUTCAPTURE,  /**< Capture mode. */\r
110   rtccCapComChModeCompare = _RTCC_CC_CTRL_MODE_OUTPUTCOMPARE, /**< Compare mode. */\r
111 } RTCC_CapComChMode_TypeDef;\r
112 \r
113 /** Compare match output action mode. */\r
114 typedef enum\r
115 {\r
116   rtccCompMatchOutActionPulse  = _RTCC_CC_CTRL_CMOA_PULSE,  /**< Generate a pulse. */\r
117   rtccCompMatchOutActionToggle = _RTCC_CC_CTRL_CMOA_TOGGLE, /**< Toggle output. */\r
118   rtccCompMatchOutActionClear  = _RTCC_CC_CTRL_CMOA_CLEAR,  /**< Clear output. */\r
119   rtccCompMatchOutActionSet    = _RTCC_CC_CTRL_CMOA_SET     /**< Set output. */\r
120 } RTCC_CompMatchOutAction_TypeDef;\r
121 \r
122 \r
123 /** PRS input sources. */\r
124 typedef enum\r
125 {\r
126   rtccPRSCh0 = _RTCC_CC_CTRL_PRSSEL_PRSCH0,   /**< PRS channel 0. */\r
127   rtccPRSCh1 = _RTCC_CC_CTRL_PRSSEL_PRSCH1,   /**< PRS channel 1. */\r
128   rtccPRSCh2 = _RTCC_CC_CTRL_PRSSEL_PRSCH2,   /**< PRS channel 2. */\r
129   rtccPRSCh3 = _RTCC_CC_CTRL_PRSSEL_PRSCH3,   /**< PRS channel 3. */\r
130   rtccPRSCh4 = _RTCC_CC_CTRL_PRSSEL_PRSCH4,   /**< PRS channel 4. */\r
131   rtccPRSCh5 = _RTCC_CC_CTRL_PRSSEL_PRSCH5,   /**< PRS channel 5. */\r
132   rtccPRSCh6 = _RTCC_CC_CTRL_PRSSEL_PRSCH6,   /**< PRS channel 6. */\r
133   rtccPRSCh7 = _RTCC_CC_CTRL_PRSSEL_PRSCH7,   /**< PRS channel 7. */\r
134   rtccPRSCh8 = _RTCC_CC_CTRL_PRSSEL_PRSCH8,   /**< PRS channel 8. */\r
135   rtccPRSCh9 = _RTCC_CC_CTRL_PRSSEL_PRSCH9,   /**< PRS channel 9. */\r
136   rtccPRSCh10 = _RTCC_CC_CTRL_PRSSEL_PRSCH10, /**< PRS channel 10. */\r
137   rtccPRSCh11 = _RTCC_CC_CTRL_PRSSEL_PRSCH11  /**< PRS channel 11. */\r
138 } RTCC_PRSSel_TypeDef;\r
139 \r
140 \r
141 /** Input edge select. */\r
142 typedef enum\r
143 {\r
144   rtccInEdgeRising  = _RTCC_CC_CTRL_ICEDGE_RISING,  /**< Rising edges detected. */\r
145   rtccInEdgeFalling = _RTCC_CC_CTRL_ICEDGE_FALLING, /**< Falling edges detected. */\r
146   rtccInEdgeBoth    = _RTCC_CC_CTRL_ICEDGE_BOTH,    /**< Both edges detected. */\r
147   rtccInEdgeNone    = _RTCC_CC_CTRL_ICEDGE_NONE     /**< No edge detection, signal is left as is. */\r
148 } RTCC_InEdgeSel_TypeDef;\r
149 \r
150 \r
151 /** Capture/Compare channel compare mode. */\r
152 typedef enum\r
153 {\r
154   /** CCVx is compared with the CNT register. */\r
155   rtccCompBaseCnt = _RTCC_CC_CTRL_COMPBASE_CNT,\r
156 \r
157   /** CCVx is compared with a CNT[16:0] and PRECNT[14:0]. */\r
158   rtccCompBasePreCnt = _RTCC_CC_CTRL_COMPBASE_PRECNT\r
159 } RTCC_CompBase_TypeDef;\r
160 \r
161   /** Day compare mode. */\r
162 typedef enum\r
163 {\r
164   rtccDayCompareModeMonth = _RTCC_CC_CTRL_DAYCC_MONTH,  /**< Day of month is selected for Capture/Compare. */\r
165   rtccDayCompareModeWeek  = _RTCC_CC_CTRL_DAYCC_WEEK    /**< Day of week is selected for Capture/Compare. */\r
166 } RTCC_DayCompareMode_TypeDef;\r
167 \r
168 /*******************************************************************************\r
169  *******************************   STRUCTS   ***********************************\r
170  ******************************************************************************/\r
171 \r
172 /** RTCC initialization structure. */\r
173 typedef struct\r
174 {\r
175   /** Enable/disable counting when initialization is completed. */\r
176   bool                   enable;\r
177 \r
178   /** Enable/disable timer counting during debug halt. */\r
179   bool                   debugRun;\r
180 \r
181   /** Enable/disable precounter wrap on ch. 0 CCV value. */\r
182   bool                   precntWrapOnCCV0;\r
183 \r
184   /** Enable/disable counter wrap on ch. 1 CCV value. */\r
185   bool                   cntWrapOnCCV1;\r
186 \r
187   /** Counter prescaler. */\r
188   RTCC_CntPresc_TypeDef  presc;\r
189 \r
190   /** Prescaler mode. */\r
191   RTCC_PrescMode_TypeDef prescMode;\r
192 \r
193 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)\r
194   /** Enable/disable storing RTCC counter value in RTCC_CCV2 upon backup mode\r
195    *  entry. */\r
196   bool                   enaBackupModeSet;\r
197 #endif\r
198 \r
199   /** Enable/disable the check that sets the OSCFFAIL interrupt flag if no\r
200    *  LFCLK-RTCC ticks are detected within one ULFRCO cycles. */\r
201   bool                   enaOSCFailDetect;\r
202 \r
203   /** Select the operational mode of the counter. */\r
204   RTCC_CntMode_TypeDef   cntMode;\r
205 \r
206   /** Disable leap year correction for the calendar mode. When this parameter is\r
207    *  set to false, February has 29 days if (year % 4 == 0). If true, February\r
208    *  always has 28 days. */\r
209   bool                   disLeapYearCorr;\r
210 } RTCC_Init_TypeDef;\r
211 \r
212 \r
213 /** RTCC capture/compare channel configuration structure. */\r
214 typedef struct\r
215 {\r
216   /** Select the mode of the Capture/Compare channel. */\r
217   RTCC_CapComChMode_TypeDef        chMode;\r
218 \r
219   /** Compare mode channel match output action. */\r
220   RTCC_CompMatchOutAction_TypeDef  compMatchOutAction;\r
221 \r
222   /** Capture mode channel PRS input channel selection. */\r
223   RTCC_PRSSel_TypeDef              prsSel;\r
224 \r
225   /** Capture mode channel input edge selection. */\r
226   RTCC_InEdgeSel_TypeDef           inputEdgeSel;\r
227 \r
228   /** Comparison base of the channel in compare mode. */\r
229   RTCC_CompBase_TypeDef            compBase;\r
230 \r
231   /** The COMPMASK (5 bit) most significant bits of the compare value will not\r
232    *  be subject to comparison.  */\r
233   uint8_t                          compMask;\r
234 \r
235   /** Day compare mode. */\r
236   RTCC_DayCompareMode_TypeDef      dayCompMode;\r
237 } RTCC_CCChConf_TypeDef;\r
238 \r
239 \r
240 /*******************************************************************************\r
241  *******************************   DEFINES   ***********************************\r
242  ******************************************************************************/\r
243 \r
244 /** Default RTCC init structure. */\r
245 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)\r
246 #define RTCC_INIT_DEFAULT                                                   \\r
247 {                                                                           \\r
248   true,     /* Start counting when init done.                           */  \\r
249   false,    /* Disable RTCC during debug halt.                          */  \\r
250   false,    /* Disable precounter wrap on ch. 0 CCV value.              */  \\r
251   false,    /* Disable counter wrap on ch. 1 CCV value.                 */  \\r
252   rtccCntPresc_32, /* 977 us per tick.                                  */  \\r
253   rtccCntTickPresc, /* Counter increments according to prescaler value. */  \\r
254   false,    /* No RTCC storage on backup mode entry.                    */  \\r
255   false,    /* No RTCC oscillator failure detection.                    */  \\r
256   rtccCntModeNormal, /* Normal RTCC mode.                               */  \\r
257   false,    /* No leap year correction.                                 */  \\r
258 }\r
259 #else\r
260 #define RTCC_INIT_DEFAULT                                                   \\r
261 {                                                                           \\r
262   true,     /* Start counting when init done.                           */  \\r
263   false,    /* Disable RTCC during debug halt.                          */  \\r
264   false,    /* Disable precounter wrap on ch. 0 CCV value.              */  \\r
265   false,    /* Disable counter wrap on ch. 1 CCV value.                 */  \\r
266   rtccCntPresc_32, /* 977 us per tick.                                  */  \\r
267   rtccCntTickPresc, /* Counter increments according to prescaler value. */  \\r
268   false,    /* No RTCC oscillator failure detection.                    */  \\r
269   rtccCntModeNormal, /* Normal RTCC mode.                               */  \\r
270   false,    /* No leap year correction.                                 */  \\r
271 }\r
272 #endif\r
273 \r
274 /** Default RTCC channel output compare init structure. */\r
275 #define RTCC_CH_INIT_COMPARE_DEFAULT                                        \\r
276 {                                                                           \\r
277   rtccCapComChModeCompare,     /* Select output compare mode.     */        \\r
278   rtccCompMatchOutActionPulse, /* Create pulse on compare match.  */        \\r
279   rtccPRSCh0,                  /* PRS channel 0 (not used).       */        \\r
280   rtccInEdgeNone,              /* No edge detection.              */        \\r
281   rtccCompBaseCnt,             /* Counter comparison base.        */        \\r
282   0,                           /* No compare mask bits set.       */        \\r
283   rtccDayCompareModeMonth      /* Don't care */                             \\r
284 }\r
285 \r
286 /** Default RTCC channel input capture init structure. */\r
287 #define RTCC_CH_INIT_CAPTURE_DEFAULT                                        \\r
288 {                                                                           \\r
289   rtccCapComChModeCapture,     /* Select input capture mode.      */        \\r
290   rtccCompMatchOutActionPulse, /* Create pulse on capture.        */        \\r
291   rtccPRSCh0,                  /* PRS channel 0.                  */        \\r
292   rtccInEdgeRising,            /* Rising edge detection.          */        \\r
293   rtccCompBaseCnt,             /* Don't care.                     */        \\r
294   0,                           /* Don't care.                     */        \\r
295   rtccDayCompareModeMonth      /* Don't care                      */        \\r
296 }\r
297 \r
298 /** Validation of valid RTCC channel for assert statements. */\r
299 #define RTCC_CH_VALID( ch )    ( ( ch ) < 3 )\r
300 \r
301 /*******************************************************************************\r
302  *****************************   PROTOTYPES   **********************************\r
303  ******************************************************************************/\r
304 \r
305 /***************************************************************************//**\r
306  * @brief\r
307  *   Get RTCC capture/compare register value (CCV) for selected channel.\r
308  *\r
309  * @param[in] ch\r
310  *   Channel selector.\r
311  *\r
312  * @return\r
313  *   Capture/compare register value.\r
314  ******************************************************************************/\r
315 __STATIC_INLINE uint32_t RTCC_ChannelCCVGet( int ch )\r
316 {\r
317   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
318   return RTCC->CC[ ch ].CCV;\r
319 }\r
320 \r
321 /***************************************************************************//**\r
322  * @brief\r
323  *   Set RTCC capture/compare register value (CCV) for selected channel.\r
324  *\r
325  * @param[in] ch\r
326  *   Channel selector.\r
327  *\r
328  * @param[in] value\r
329  *   CCV value.\r
330  ******************************************************************************/\r
331 __STATIC_INLINE void RTCC_ChannelCCVSet( int ch, uint32_t value )\r
332 {\r
333   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
334   RTCC->CC[ ch ].CCV = value;\r
335 }\r
336 \r
337 /***************************************************************************//**\r
338  * @brief\r
339  *   Get the calendar DATE register content for selected channel.\r
340  *\r
341  * @param[in] ch\r
342  *   Channel selector.\r
343  *\r
344  * @return\r
345  *   DATE register value.\r
346  ******************************************************************************/\r
347 __STATIC_INLINE uint32_t RTCC_ChannelDateGet( int ch )\r
348 {\r
349   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
350   return RTCC->CC[ ch ].DATE;\r
351 }\r
352 \r
353 /***************************************************************************//**\r
354  * @brief\r
355  *   Set the calendar DATE register for selected channel.\r
356  *\r
357  * @param[in] ch\r
358  *   Channel selector.\r
359  *\r
360  * @param[in] date\r
361  *   DATE value.\r
362  ******************************************************************************/\r
363 __STATIC_INLINE void RTCC_ChannelDateSet( int ch, uint32_t date )\r
364 {\r
365   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
366   RTCC->CC[ ch ].DATE = date;\r
367 }\r
368 \r
369 void RTCC_ChannelInit( int ch, RTCC_CCChConf_TypeDef const *confPtr );\r
370 \r
371 /***************************************************************************//**\r
372  * @brief\r
373  *   Get the calendar TIME register content for selected channel.\r
374  *\r
375  * @param[in] ch\r
376  *   Channel selector.\r
377  *\r
378  * @return\r
379  *   TIME register value.\r
380  ******************************************************************************/\r
381 __STATIC_INLINE uint32_t RTCC_ChannelTimeGet( int ch )\r
382 {\r
383   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
384   return RTCC->CC[ ch ].TIME;\r
385 }\r
386 \r
387 /***************************************************************************//**\r
388  * @brief\r
389  *   Set the calendar TIME register for selected channel.\r
390  *\r
391  * @param[in] ch\r
392  *   Channel selector.\r
393  *\r
394  * @param[in] time\r
395  *   TIME value.\r
396  ******************************************************************************/\r
397 __STATIC_INLINE void RTCC_ChannelTimeSet( int ch, uint32_t time )\r
398 {\r
399   EFM_ASSERT( RTCC_CH_VALID( ch ) );\r
400   RTCC->CC[ ch ].TIME = time;\r
401 }\r
402 \r
403 /***************************************************************************//**\r
404  * @brief\r
405  *   Get the combined CNT/PRECNT register content.\r
406  *\r
407  * @return\r
408  *   CNT/PRECNT register value.\r
409  ******************************************************************************/\r
410 __STATIC_INLINE uint32_t RTCC_CombinedCounterGet( void )\r
411 {\r
412   return RTCC->COMBCNT;\r
413 }\r
414 \r
415 /***************************************************************************//**\r
416  * @brief\r
417  *   Get RTCC counter value.\r
418  *\r
419  * @return\r
420  *   Current RTCC counter value.\r
421  ******************************************************************************/\r
422 __STATIC_INLINE uint32_t RTCC_CounterGet( void )\r
423 {\r
424   return RTCC->CNT;\r
425 }\r
426 \r
427 /***************************************************************************//**\r
428  * @brief\r
429  *   Set RTCC CNT counter.\r
430  *\r
431  * @param[in] value\r
432  *   CNT value.\r
433  ******************************************************************************/\r
434 __STATIC_INLINE void RTCC_CounterSet( uint32_t value )\r
435 {\r
436   RTCC->CNT = value;\r
437 }\r
438 \r
439 /***************************************************************************//**\r
440  * @brief\r
441  *   Get DATE register value.\r
442  *\r
443  * @return\r
444  *   Current DATE register value.\r
445  ******************************************************************************/\r
446 __STATIC_INLINE uint32_t RTCC_DateGet( void )\r
447 {\r
448   return RTCC->DATE;\r
449 }\r
450 \r
451 /***************************************************************************//**\r
452  * @brief\r
453  *   Set RTCC DATE register.\r
454  *\r
455  * @param[in] date\r
456  *   DATE value.\r
457  ******************************************************************************/\r
458 __STATIC_INLINE void RTCC_DateSet( uint32_t date )\r
459 {\r
460   RTCC->DATE = date;\r
461 }\r
462 \r
463 /***************************************************************************//**\r
464  * @brief\r
465  *   Enable/disable EM4 wakeup capability.\r
466  *\r
467  * @param[in] enable\r
468  *   True to enable EM4 wakeup, false to disable.\r
469  ******************************************************************************/\r
470 __STATIC_INLINE void RTCC_EM4WakeupEnable( bool enable )\r
471 {\r
472   if ( enable )\r
473   {\r
474     RTCC->EM4WUEN = RTCC_EM4WUEN_EM4WU;\r
475   }\r
476   else\r
477   {\r
478     RTCC->EM4WUEN = 0;\r
479   }\r
480 }\r
481 \r
482 void RTCC_Enable( bool enable );\r
483 \r
484 void RTCC_Init( const RTCC_Init_TypeDef *init );\r
485 \r
486 /***************************************************************************//**\r
487  * @brief\r
488  *   Clear one or more pending RTCC interrupts.\r
489  *\r
490  * @param[in] flags\r
491  *   RTCC interrupt sources to clear. Use a set of interrupt flags OR-ed\r
492  *   together to clear multiple interrupt sources.\r
493  ******************************************************************************/\r
494 __STATIC_INLINE void RTCC_IntClear( uint32_t flags )\r
495 {\r
496   RTCC->IFC = flags;\r
497 }\r
498 \r
499 /***************************************************************************//**\r
500  * @brief\r
501  *   Disable one or more RTCC interrupts.\r
502  *\r
503  * @param[in] flags\r
504  *   RTCC interrupt sources to disable. Use a set of interrupt flags OR-ed\r
505  *   together to disable multiple interrupt.\r
506  ******************************************************************************/\r
507 __STATIC_INLINE void RTCC_IntDisable( uint32_t flags )\r
508 {\r
509   RTCC->IEN &= ~flags;\r
510 }\r
511 \r
512 /***************************************************************************//**\r
513  * @brief\r
514  *   Enable one or more RTCC interrupts.\r
515  *\r
516  * @note\r
517  *   Depending on the use, a pending interrupt may already be set prior to\r
518  *   enabling the interrupt. Consider using RTCC_IntClear() prior to enabling\r
519  *   if such a pending interrupt should be ignored.\r
520  *\r
521  * @param[in] flags\r
522  *   RTCC interrupt sources to enable. Use a set of interrupt flags OR-ed\r
523  *   together to set multiple interrupt.\r
524  ******************************************************************************/\r
525 __STATIC_INLINE void RTCC_IntEnable( uint32_t flags )\r
526 {\r
527   RTCC->IEN |= flags;\r
528 }\r
529 \r
530 /***************************************************************************//**\r
531  * @brief\r
532  *   Get pending RTCC interrupt flags.\r
533  *\r
534  * @note\r
535  *   The event bits are not cleared by the use of this function.\r
536  *\r
537  * @return\r
538  *   Pending RTCC interrupt sources. Returns a set of interrupt flags OR-ed\r
539  *   together for the interrupt sources set.\r
540  ******************************************************************************/\r
541 __STATIC_INLINE uint32_t RTCC_IntGet( void )\r
542 {\r
543   return RTCC->IF;\r
544 }\r
545 \r
546 /***************************************************************************//**\r
547  * @brief\r
548  *   Get enabled and pending RTCC interrupt flags.\r
549  *\r
550  * @details\r
551  *   Useful for handling more interrupt sources in the same interrupt handler.\r
552  *\r
553  * @return\r
554  *   Pending and enabled RTCC interrupt sources. Returns a set of interrupt\r
555  *   flags OR-ed together for the interrupt sources set.\r
556  ******************************************************************************/\r
557 __STATIC_INLINE uint32_t RTCC_IntGetEnabled( void )\r
558 {\r
559   uint32_t tmp;\r
560 \r
561   tmp = RTCC->IEN;\r
562 \r
563   /* Bitwise AND of pending and enabled interrupt flags. */\r
564   return RTCC->IF & tmp;\r
565 }\r
566 \r
567 /***************************************************************************//**\r
568  * @brief\r
569  *   Set one or more pending RTCC interrupts from SW.\r
570  *\r
571  * @param[in] flags\r
572  *   RTCC interrupt sources to set to pending. Use a set of interrupt flags\r
573  *   (RTCC_IFS_nnn).\r
574  ******************************************************************************/\r
575 __STATIC_INLINE void RTCC_IntSet( uint32_t flags )\r
576 {\r
577   RTCC->IFS = flags;\r
578 }\r
579 \r
580 /***************************************************************************//**\r
581  * @brief\r
582  *   Lock RTCC registers.\r
583  *\r
584  * @note\r
585  *   When RTCC registers are locked, RTCC_CTRL, RTCC_PRECNT, RTCC_CNT,\r
586  *   RTCC_TIME, RTCC_DATE, RTCC_IEN, RTCC_POWERDOWN and RTCC_CCx_XXX registers\r
587  *   can not be written to.\r
588  ******************************************************************************/\r
589 __STATIC_INLINE void RTCC_Lock( void )\r
590 {\r
591   RTCC->LOCK = RTCC_LOCK_LOCKKEY_LOCK;\r
592 }\r
593 \r
594 /***************************************************************************//**\r
595  * @brief\r
596  *   Get RTCC pre-counter value.\r
597  *\r
598  * @return\r
599  *   Current RTCC pre-counter value.\r
600  ******************************************************************************/\r
601 __STATIC_INLINE uint32_t RTCC_PreCounterGet( void )\r
602 {\r
603   return RTCC->PRECNT;\r
604 }\r
605 \r
606 /***************************************************************************//**\r
607  * @brief\r
608  *   Set RTCC pre-counter value.\r
609  *\r
610  * @param[in] preCntVal\r
611  *   RTCC pre-counter value to be set.\r
612  ******************************************************************************/\r
613 __STATIC_INLINE void RTCC_PreCounterSet( uint32_t preCntVal )\r
614 {\r
615   RTCC->PRECNT = preCntVal;\r
616 }\r
617 \r
618 void RTCC_Reset( void );\r
619 \r
620 /***************************************************************************//**\r
621  * @brief\r
622  *   Power down the retention ram.\r
623  *\r
624  * @note\r
625  *   Once retention ram is powered down, it cannot be powered up again.\r
626  ******************************************************************************/\r
627 __STATIC_INLINE void RTCC_RetentionRamPowerDown( void )\r
628 {\r
629   RTCC->POWERDOWN = RTCC_POWERDOWN_RAM;\r
630 }\r
631 \r
632 void RTCC_StatusClear( void );\r
633 \r
634 /***************************************************************************//**\r
635  * @brief\r
636  *   Get STATUS register value.\r
637  *\r
638  * @return\r
639  *   Current STATUS register value.\r
640  ******************************************************************************/\r
641 __STATIC_INLINE uint32_t RTCC_StatusGet( void )\r
642 {\r
643   while ( RTCC->SYNCBUSY & RTCC_SYNCBUSY_CMD )\r
644   {\r
645     // Wait for syncronization.\r
646   }\r
647   return RTCC->STATUS;\r
648 }\r
649 \r
650 /***************************************************************************//**\r
651  * @brief\r
652  *   Get TIME register value.\r
653  *\r
654  * @return\r
655  *   Current TIME register value.\r
656  ******************************************************************************/\r
657 __STATIC_INLINE uint32_t RTCC_TimeGet( void )\r
658 {\r
659   return RTCC->TIME;\r
660 }\r
661 \r
662 /***************************************************************************//**\r
663  * @brief\r
664  *   Set RTCC TIME register.\r
665  *\r
666  * @param[in] time\r
667  *   TIME value.\r
668  ******************************************************************************/\r
669 __STATIC_INLINE void RTCC_TimeSet( uint32_t time )\r
670 {\r
671   RTCC->TIME = time;\r
672 }\r
673 \r
674 /***************************************************************************//**\r
675  * @brief\r
676  *   Unlock RTCC registers.\r
677  *\r
678  * @note\r
679  *   When RTCC registers are locked, RTCC_CTRL, RTCC_PRECNT, RTCC_CNT,\r
680  *   RTCC_TIME, RTCC_DATE, RTCC_IEN, RTCC_POWERDOWN and RTCC_CCx_XXX registers\r
681  *   can not be written to.\r
682  ******************************************************************************/\r
683 __STATIC_INLINE void RTCC_Unlock( void )\r
684 {\r
685   RTCC->LOCK = RTCC_LOCK_LOCKKEY_UNLOCK;\r
686 }\r
687 \r
688 /** @} (end addtogroup RTCC) */\r
689 /** @} (end addtogroup EM_Library) */\r
690 \r
691 #ifdef __cplusplus\r
692 }\r
693 #endif\r
694 \r
695 #endif /* defined( RTCC_COUNT ) && ( RTC_COUNT == 1 ) */\r
696 #endif /* __SILICON_LABS_EM_RTCC_H__ */\r