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