]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_rtc.h
Add EFM32 Giant Gecko Starter Kit demo - still a work in progress as the low power...
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_rtc.h
1 /***************************************************************************//**\r
2  * @file em_rtc.h\r
3  * @brief Real Time Counter (RTC) peripheral API\r
4  * @version 4.0.0\r
5  *******************************************************************************\r
6  * @section License\r
7  * <b>(C) Copyright 2014 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 \r
34 #ifndef __SILICON_LABS_EM_RTC_H_\r
35 #define __SILICON_LABS_EM_RTC_H_\r
36 \r
37 #include "em_device.h"\r
38 #if defined(RTC_COUNT) && (RTC_COUNT > 0)\r
39 \r
40 #include <stdbool.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 RTC\r
53  * @{\r
54  ******************************************************************************/\r
55 \r
56 /*******************************************************************************\r
57  *******************************   STRUCTS   ***********************************\r
58  ******************************************************************************/\r
59 \r
60 /** RTC initialization structure. */\r
61 typedef struct\r
62 {\r
63   bool enable;   /**< Start counting when init completed. */\r
64   bool debugRun; /**< Counter shall keep running during debug halt. */\r
65   bool comp0Top; /**< Use compare register 0 as max count value. */\r
66 } RTC_Init_TypeDef;\r
67 \r
68 /** Suggested default config for RTC init structure. */\r
69 #define RTC_INIT_DEFAULT                                       \\r
70   { true,    /* Start counting when init done */               \\r
71     false,   /* Disable updating during debug halt */          \\r
72     true     /* Restart counting from 0 when reaching COMP0 */ \\r
73   }\r
74 \r
75 \r
76 /*******************************************************************************\r
77  *****************************   PROTOTYPES   **********************************\r
78  ******************************************************************************/\r
79 \r
80 uint32_t RTC_CompareGet(unsigned int comp);\r
81 void RTC_CompareSet(unsigned int comp, uint32_t value);\r
82 \r
83 /***************************************************************************//**\r
84  * @brief\r
85  *   Get RTC counter value.\r
86  *\r
87  * @return\r
88  *   Current RTC counter value.\r
89  ******************************************************************************/\r
90 __STATIC_INLINE uint32_t RTC_CounterGet(void)\r
91 {\r
92   return(RTC->CNT);\r
93 }\r
94 \r
95 void RTC_CounterReset(void);\r
96 void RTC_Enable(bool enable);\r
97 void RTC_FreezeEnable(bool enable);\r
98 void RTC_Init(const RTC_Init_TypeDef *init);\r
99 \r
100 /***************************************************************************//**\r
101  * @brief\r
102  *   Clear one or more pending RTC interrupts.\r
103  *\r
104  * @param[in] flags\r
105  *   RTC interrupt sources to clear. Use a set of interrupt flags OR-ed\r
106  *   together to clear multiple interrupt sources for the RTC module\r
107  *   (RTC_IFS_nnn).\r
108  ******************************************************************************/\r
109 __STATIC_INLINE void RTC_IntClear(uint32_t flags)\r
110 {\r
111   RTC->IFC = flags;\r
112 }\r
113 \r
114 \r
115 /***************************************************************************//**\r
116  * @brief\r
117  *   Disable one or more RTC interrupts.\r
118  *\r
119  * @param[in] flags\r
120  *   RTC interrupt sources to disable. Use a set of interrupt flags OR-ed\r
121  *   together to disable multiple interrupt sources for the RTC module\r
122  *   (RTC_IFS_nnn).\r
123  ******************************************************************************/\r
124 __STATIC_INLINE void RTC_IntDisable(uint32_t flags)\r
125 {\r
126   RTC->IEN &= ~(flags);\r
127 }\r
128 \r
129 \r
130 /***************************************************************************//**\r
131  * @brief\r
132  *   Enable one or more RTC interrupts.\r
133  *\r
134  * @note\r
135  *   Depending on the use, a pending interrupt may already be set prior to\r
136  *   enabling the interrupt. Consider using RTC_IntClear() prior to enabling\r
137  *   if such a pending interrupt should be ignored.\r
138  *\r
139  * @param[in] flags\r
140  *   RTC interrupt sources to enable. Use a set of interrupt flags OR-ed\r
141  *   together to set multiple interrupt sources for the RTC module\r
142  *   (RTC_IFS_nnn).\r
143  ******************************************************************************/\r
144 __STATIC_INLINE void RTC_IntEnable(uint32_t flags)\r
145 {\r
146   RTC->IEN |= flags;\r
147 }\r
148 \r
149 \r
150 /***************************************************************************//**\r
151  * @brief\r
152  *   Get pending RTC interrupt flags.\r
153  *\r
154  * @note\r
155  *   The event bits are not cleared by the use of this function.\r
156  *\r
157  * @return\r
158  *   Pending RTC interrupt sources. Returns a set of interrupt flags OR-ed\r
159  *   together for multiple interrupt sources in the RTC module (RTC_IFS_nnn).\r
160  ******************************************************************************/\r
161 __STATIC_INLINE uint32_t RTC_IntGet(void)\r
162 {\r
163   return(RTC->IF);\r
164 }\r
165 \r
166 \r
167 /***************************************************************************//**\r
168  * @brief\r
169  *   Set one or more pending RTC interrupts from SW.\r
170  *\r
171  * @param[in] flags\r
172  *   RTC interrupt sources to set to pending. Use a set of interrupt flags\r
173  *   OR-ed together to set multiple interrupt sources for the RTC module\r
174  *   (RTC_IFS_nnn).\r
175  ******************************************************************************/\r
176 __STATIC_INLINE void RTC_IntSet(uint32_t flags)\r
177 {\r
178   RTC->IFS = flags;\r
179 }\r
180 \r
181 void RTC_Reset(void);\r
182 \r
183 /** @} (end addtogroup RTC) */\r
184 /** @} (end addtogroup EM_Library) */\r
185 \r
186 #ifdef __cplusplus\r
187 }\r
188 #endif\r
189 \r
190 #endif /* defined(RTC_COUNT) && (RTC_COUNT > 0) */\r
191 #endif /* __SILICON_LABS_EM_RTC_H_ */\r