]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_rtc.h
Add files necessary to create a Pearl Gecko build configuration in the new EFM32...
[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.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_RTC_H__\r
34 #define __SILICON_LABS_EM_RTC_H__\r
35 \r
36 #include "em_device.h"\r
37 #if defined(RTC_COUNT) && (RTC_COUNT > 0)\r
38 \r
39 #include <stdbool.h>\r
40 \r
41 #ifdef __cplusplus\r
42 extern "C" {\r
43 #endif\r
44 \r
45 /***************************************************************************//**\r
46  * @addtogroup EM_Library\r
47  * @{\r
48  ******************************************************************************/\r
49 \r
50 /***************************************************************************//**\r
51  * @addtogroup RTC\r
52  * @{\r
53  ******************************************************************************/\r
54 \r
55 /*******************************************************************************\r
56  *******************************   STRUCTS   ***********************************\r
57  ******************************************************************************/\r
58 \r
59 /** RTC initialization structure. */\r
60 typedef struct\r
61 {\r
62   bool enable;   /**< Start counting when init completed. */\r
63   bool debugRun; /**< Counter shall keep running during debug halt. */\r
64   bool comp0Top; /**< Use compare register 0 as max count value. */\r
65 } RTC_Init_TypeDef;\r
66 \r
67 /** Suggested default config for RTC init structure. */\r
68 #define RTC_INIT_DEFAULT                                     \\r
69 {                                                            \\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  *   Get enabled and pending RTC interrupt flags.\r
170  *   Useful for handling more interrupt sources in the same interrupt handler.\r
171  *\r
172  * @note\r
173  *   Interrupt flags are not cleared by the use of this function.\r
174  *\r
175  * @return\r
176  *   Pending and enabled RTC interrupt sources\r
177  *   The return value is the bitwise AND of\r
178  *   - the enabled interrupt sources in RTC_IEN and\r
179  *   - the pending interrupt flags RTC_IF\r
180  ******************************************************************************/\r
181 __STATIC_INLINE uint32_t RTC_IntGetEnabled(void)\r
182 {\r
183   uint32_t ien;\r
184 \r
185   ien = RTC->IEN;\r
186   return RTC->IF & ien;\r
187 }\r
188 \r
189 \r
190 /***************************************************************************//**\r
191  * @brief\r
192  *   Set one or more pending RTC interrupts from SW.\r
193  *\r
194  * @param[in] flags\r
195  *   RTC interrupt sources to set to pending. Use a set of interrupt flags\r
196  *   OR-ed together to set multiple interrupt sources for the RTC module\r
197  *   (RTC_IFS_nnn).\r
198  ******************************************************************************/\r
199 __STATIC_INLINE void RTC_IntSet(uint32_t flags)\r
200 {\r
201   RTC->IFS = flags;\r
202 }\r
203 \r
204 void RTC_Reset(void);\r
205 \r
206 /** @} (end addtogroup RTC) */\r
207 /** @} (end addtogroup EM_Library) */\r
208 \r
209 #ifdef __cplusplus\r
210 }\r
211 #endif\r
212 \r
213 #endif /* defined(RTC_COUNT) && (RTC_COUNT > 0) */\r
214 #endif /* __SILICON_LABS_EM_RTC_H__ */\r