]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/emlib/inc/em_letimer.h
Add Pearl Gecko demo.
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / emlib / inc / em_letimer.h
1 /***************************************************************************//**\r
2  * @file em_letimer.h\r
3  * @brief Low Energy Timer (LETIMER) 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_LETIMER_H__\r
34 #define __SILICON_LABS_EM_LETIMER_H__\r
35 \r
36 #include <stdbool.h>\r
37 #include "em_device.h"\r
38 #if defined(LETIMER_COUNT) && (LETIMER_COUNT > 0)\r
39 \r
40 #ifdef __cplusplus\r
41 extern "C" {\r
42 #endif\r
43 \r
44 /***************************************************************************//**\r
45  * @addtogroup EM_Library\r
46  * @{\r
47  ******************************************************************************/\r
48 \r
49 /***************************************************************************//**\r
50  * @addtogroup LETIMER\r
51  * @{\r
52  ******************************************************************************/\r
53 \r
54 /*******************************************************************************\r
55  ********************************   ENUMS   ************************************\r
56  ******************************************************************************/\r
57 \r
58 /** Repeat mode. */\r
59 typedef enum\r
60 {\r
61   /** Count until stopped by SW. */\r
62   letimerRepeatFree     = _LETIMER_CTRL_REPMODE_FREE,\r
63   /** Count REP0 times. */\r
64   letimerRepeatOneshot  = _LETIMER_CTRL_REPMODE_ONESHOT,\r
65   /**\r
66    * Count REP0 times, if REP1 has been written to, it is loaded into\r
67    * REP0 when REP0 is about to be decremented to 0.\r
68    */\r
69   letimerRepeatBuffered = _LETIMER_CTRL_REPMODE_BUFFERED,\r
70   /**\r
71    * Run as long as both REP0 and REP1 are not 0. Both REP0 and REP1\r
72    * are decremented when counter underflows.\r
73    */\r
74   letimerRepeatDouble   = _LETIMER_CTRL_REPMODE_DOUBLE\r
75 } LETIMER_RepeatMode_TypeDef;\r
76 \r
77 \r
78 /** Underflow action on output. */\r
79 typedef enum\r
80 {\r
81   /** No output action. */\r
82   letimerUFOANone   = _LETIMER_CTRL_UFOA0_NONE,\r
83   /** Toggle output when counter underflows. */\r
84   letimerUFOAToggle = _LETIMER_CTRL_UFOA0_TOGGLE,\r
85   /** Hold output one LETIMER clock cycle when counter underflows. */\r
86   letimerUFOAPulse  = _LETIMER_CTRL_UFOA0_PULSE,\r
87   /** Set output idle when counter underflows, and active when matching COMP1. */\r
88   letimerUFOAPwm    = _LETIMER_CTRL_UFOA0_PWM\r
89 } LETIMER_UFOA_TypeDef;\r
90 \r
91 /*******************************************************************************\r
92  *******************************   STRUCTS   ***********************************\r
93  ******************************************************************************/\r
94 \r
95 /** LETIMER initialization structure. */\r
96 typedef struct\r
97 {\r
98   bool                       enable;         /**< Start counting when init completed. */\r
99   bool                       debugRun;       /**< Counter shall keep running during debug halt. */\r
100 #if defined(LETIMER_CTRL_RTCC0TEN)\r
101   bool                       rtcComp0Enable; /**< Start counting on RTC COMP0 match. */\r
102   bool                       rtcComp1Enable; /**< Start counting on RTC COMP1 match. */\r
103 #endif\r
104   bool                       comp0Top;       /**< Load COMP0 register into CNT when counter underflows. */\r
105   bool                       bufTop;         /**< Load COMP1 into COMP0 when REP0 reaches 0. */\r
106   uint8_t                    out0Pol;        /**< Idle value for output 0. */\r
107   uint8_t                    out1Pol;        /**< Idle value for output 1. */\r
108   LETIMER_UFOA_TypeDef       ufoa0;          /**< Underflow output 0 action. */\r
109   LETIMER_UFOA_TypeDef       ufoa1;          /**< Underflow output 1 action. */\r
110   LETIMER_RepeatMode_TypeDef repMode;        /**< Repeat mode. */\r
111 } LETIMER_Init_TypeDef;\r
112 \r
113 /** Default config for LETIMER init structure. */\r
114 #if defined(LETIMER_CTRL_RTCC0TEN)\r
115 #define LETIMER_INIT_DEFAULT                                                  \\r
116 {                                                                             \\r
117   true,               /* Enable timer when init complete. */                  \\r
118   false,              /* Stop counter during debug halt. */                   \\r
119   false,              /* Do not start counting on RTC COMP0 match. */         \\r
120   false,              /* Do not start counting on RTC COMP1 match. */         \\r
121   false,              /* Do not load COMP0 into CNT on underflow. */          \\r
122   false,              /* Do not load COMP1 into COMP0 when REP0 reaches 0. */ \\r
123   0,                  /* Idle value 0 for output 0. */                        \\r
124   0,                  /* Idle value 0 for output 1. */                        \\r
125   letimerUFOANone,    /* No action on underflow on output 0. */               \\r
126   letimerUFOANone,    /* No action on underflow on output 1. */               \\r
127   letimerRepeatFree   /* Count until stopped by SW. */                        \\r
128 }\r
129 #else\r
130 #define LETIMER_INIT_DEFAULT                                                  \\r
131 {                                                                             \\r
132   true,               /* Enable timer when init complete. */                  \\r
133   false,              /* Stop counter during debug halt. */                   \\r
134   false,              /* Do not load COMP0 into CNT on underflow. */          \\r
135   false,              /* Do not load COMP1 into COMP0 when REP0 reaches 0. */ \\r
136   0,                  /* Idle value 0 for output 0. */                        \\r
137   0,                  /* Idle value 0 for output 1. */                        \\r
138   letimerUFOANone,    /* No action on underflow on output 0. */               \\r
139   letimerUFOANone,    /* No action on underflow on output 1. */               \\r
140   letimerRepeatFree   /* Count until stopped by SW. */                        \\r
141 }\r
142 #endif\r
143 \r
144 /*******************************************************************************\r
145  *****************************   PROTOTYPES   **********************************\r
146  ******************************************************************************/\r
147 \r
148 uint32_t LETIMER_CompareGet(LETIMER_TypeDef *letimer, unsigned int comp);\r
149 void LETIMER_CompareSet(LETIMER_TypeDef *letimer,\r
150                         unsigned int comp,\r
151                         uint32_t value);\r
152 \r
153 \r
154 /***************************************************************************//**\r
155  * @brief\r
156  *   Get LETIMER counter value.\r
157  *\r
158  * @param[in] letimer\r
159  *   Pointer to LETIMER peripheral register block.\r
160  *\r
161  * @return\r
162  *   Current LETIMER counter value.\r
163  ******************************************************************************/\r
164 __STATIC_INLINE uint32_t LETIMER_CounterGet(LETIMER_TypeDef *letimer)\r
165 {\r
166   return(letimer->CNT);\r
167 }\r
168 \r
169 \r
170 void LETIMER_Enable(LETIMER_TypeDef *letimer, bool enable);\r
171 #if defined(_LETIMER_FREEZE_MASK)\r
172 void LETIMER_FreezeEnable(LETIMER_TypeDef *letimer, bool enable);\r
173 #endif\r
174 void LETIMER_Init(LETIMER_TypeDef *letimer, const LETIMER_Init_TypeDef *init);\r
175 \r
176 \r
177 /***************************************************************************//**\r
178  * @brief\r
179  *   Clear one or more pending LETIMER interrupts.\r
180  *\r
181  * @param[in] letimer\r
182  *   Pointer to LETIMER peripheral register block.\r
183  *\r
184  * @param[in] flags\r
185  *   Pending LETIMER interrupt source to clear. Use a bitwise logic OR\r
186  *    combination of valid interrupt flags for the LETIMER module\r
187  *    (LETIMER_IF_nnn).\r
188  ******************************************************************************/\r
189 __STATIC_INLINE void LETIMER_IntClear(LETIMER_TypeDef *letimer, uint32_t flags)\r
190 {\r
191   letimer->IFC = flags;\r
192 }\r
193 \r
194 \r
195 /***************************************************************************//**\r
196  * @brief\r
197  *   Disable one or more LETIMER interrupts.\r
198  *\r
199  * @param[in] letimer\r
200  *   Pointer to LETIMER peripheral register block.\r
201  *\r
202  * @param[in] flags\r
203  *   LETIMER interrupt sources to disable. Use a bitwise logic OR combination of\r
204  *   valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).\r
205  ******************************************************************************/\r
206 __STATIC_INLINE void LETIMER_IntDisable(LETIMER_TypeDef *letimer, uint32_t flags)\r
207 {\r
208   letimer->IEN &= ~flags;\r
209 }\r
210 \r
211 \r
212 /***************************************************************************//**\r
213  * @brief\r
214  *   Enable one or more LETIMER interrupts.\r
215  *\r
216  * @note\r
217  *   Depending on the use, a pending interrupt may already be set prior to\r
218  *   enabling the interrupt. Consider using LETIMER_IntClear() prior to enabling\r
219  *   if such a pending interrupt should be ignored.\r
220  *\r
221  * @param[in] letimer\r
222  *   Pointer to LETIMER peripheral register block.\r
223  *\r
224  * @param[in] flags\r
225  *   LETIMER interrupt sources to enable. Use a bitwise logic OR combination of\r
226  *   valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).\r
227  ******************************************************************************/\r
228 __STATIC_INLINE void LETIMER_IntEnable(LETIMER_TypeDef *letimer, uint32_t flags)\r
229 {\r
230   letimer->IEN |= flags;\r
231 }\r
232 \r
233 \r
234 /***************************************************************************//**\r
235  * @brief\r
236  *   Get pending LETIMER interrupt flags.\r
237  *\r
238  * @note\r
239  *   The event bits are not cleared by the use of this function.\r
240  *\r
241  * @param[in] letimer\r
242  *   Pointer to LETIMER peripheral register block.\r
243  *\r
244  * @return\r
245  *   LETIMER interrupt sources pending. A bitwise logic OR combination of\r
246  *    valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).\r
247  ******************************************************************************/\r
248 __STATIC_INLINE uint32_t LETIMER_IntGet(LETIMER_TypeDef *letimer)\r
249 {\r
250   return letimer->IF;\r
251 }\r
252 \r
253 \r
254 /***************************************************************************//**\r
255  * @brief\r
256  *   Get enabled and pending LETIMER interrupt flags.\r
257  *\r
258  * @details\r
259  *   Useful for handling more interrupt sources in the same interrupt handler.\r
260  *\r
261  * @note\r
262  *   The event bits are not cleared by the use of this function.\r
263  *\r
264  * @param[in] letimer\r
265  *   Pointer to LETIMER peripheral register block.\r
266  *\r
267  * @return\r
268  *   Pending and enabled LETIMER interrupt sources.\r
269  *   The return value is the bitwise AND combination of\r
270  *   - the OR combination of enabled interrupt sources in LETIMER_IEN_nnn\r
271  *   register (LETIMER_IEN_nnn) and\r
272  *   - the OR combination of valid interrupt flags of the LETIMER module\r
273  *   (LETIMER_IF_nnn).\r
274  ******************************************************************************/\r
275 __STATIC_INLINE uint32_t LETIMER_IntGetEnabled(LETIMER_TypeDef *letimer)\r
276 {\r
277   uint32_t ien;\r
278 \r
279 \r
280   /* Store flags in temporary variable in order to define explicit order\r
281    * of volatile accesses. */\r
282   ien = letimer->IEN;\r
283 \r
284   /* Bitwise AND of pending and enabled interrupts */\r
285   return letimer->IF & ien;\r
286 }\r
287 \r
288 \r
289 /***************************************************************************//**\r
290  * @brief\r
291  *   Set one or more pending LETIMER interrupts from SW.\r
292  *\r
293  * @param[in] letimer\r
294  *   Pointer to LETIMER peripheral register block.\r
295  *\r
296  * @param[in] flags\r
297  *   LETIMER interrupt sources to set to pending. Use a bitwise logic OR\r
298  *   combination of valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).\r
299  ******************************************************************************/\r
300 __STATIC_INLINE void LETIMER_IntSet(LETIMER_TypeDef *letimer, uint32_t flags)\r
301 {\r
302   letimer->IFS = flags;\r
303 }\r
304 \r
305 \r
306 uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep);\r
307 void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,\r
308                        unsigned int rep,\r
309                        uint32_t value);\r
310 void LETIMER_Reset(LETIMER_TypeDef *letimer);\r
311 \r
312 \r
313 /** @} (end addtogroup LETIMER) */\r
314 /** @} (end addtogroup EM_Library) */\r
315 \r
316 #ifdef __cplusplus\r
317 }\r
318 #endif\r
319 \r
320 #endif /* defined(LETIMER_COUNT) && (LETIMER_COUNT > 0) */\r
321 #endif /* __SILICON_LABS_EM_LETIMER_H__ */\r