1 /***************************************************************************//**
\r
3 * @brief Low Energy Timer (LETIMER) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\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
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
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
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
31 ******************************************************************************/
\r
33 #ifndef __SILICON_LABS_EM_LETIMER_H__
\r
34 #define __SILICON_LABS_EM_LETIMER_H__
\r
36 #include <stdbool.h>
\r
37 #include "em_device.h"
\r
38 #if defined(LETIMER_COUNT) && (LETIMER_COUNT > 0)
\r
44 /***************************************************************************//**
\r
45 * @addtogroup EM_Library
\r
47 ******************************************************************************/
\r
49 /***************************************************************************//**
\r
50 * @addtogroup LETIMER
\r
52 ******************************************************************************/
\r
54 /*******************************************************************************
\r
55 ******************************** ENUMS ************************************
\r
56 ******************************************************************************/
\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
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
69 letimerRepeatBuffered = _LETIMER_CTRL_REPMODE_BUFFERED,
\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
74 letimerRepeatDouble = _LETIMER_CTRL_REPMODE_DOUBLE
\r
75 } LETIMER_RepeatMode_TypeDef;
\r
78 /** Underflow action on output. */
\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
91 /*******************************************************************************
\r
92 ******************************* STRUCTS ***********************************
\r
93 ******************************************************************************/
\r
95 /** LETIMER initialization structure. */
\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
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
113 /** Default config for LETIMER init structure. */
\r
114 #if defined(LETIMER_CTRL_RTCC0TEN)
\r
115 #define LETIMER_INIT_DEFAULT \
\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
130 #define LETIMER_INIT_DEFAULT \
\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
144 /*******************************************************************************
\r
145 ***************************** PROTOTYPES **********************************
\r
146 ******************************************************************************/
\r
148 uint32_t LETIMER_CompareGet(LETIMER_TypeDef *letimer, unsigned int comp);
\r
149 void LETIMER_CompareSet(LETIMER_TypeDef *letimer,
\r
154 /***************************************************************************//**
\r
156 * Get LETIMER counter value.
\r
158 * @param[in] letimer
\r
159 * Pointer to LETIMER peripheral register block.
\r
162 * Current LETIMER counter value.
\r
163 ******************************************************************************/
\r
164 __STATIC_INLINE uint32_t LETIMER_CounterGet(LETIMER_TypeDef *letimer)
\r
166 return(letimer->CNT);
\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
174 void LETIMER_Init(LETIMER_TypeDef *letimer, const LETIMER_Init_TypeDef *init);
\r
177 /***************************************************************************//**
\r
179 * Clear one or more pending LETIMER interrupts.
\r
181 * @param[in] letimer
\r
182 * Pointer to LETIMER peripheral register block.
\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
191 letimer->IFC = flags;
\r
195 /***************************************************************************//**
\r
197 * Disable one or more LETIMER interrupts.
\r
199 * @param[in] letimer
\r
200 * Pointer to LETIMER peripheral register block.
\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
208 letimer->IEN &= ~flags;
\r
212 /***************************************************************************//**
\r
214 * Enable one or more LETIMER interrupts.
\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
221 * @param[in] letimer
\r
222 * Pointer to LETIMER peripheral register block.
\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
230 letimer->IEN |= flags;
\r
234 /***************************************************************************//**
\r
236 * Get pending LETIMER interrupt flags.
\r
239 * The event bits are not cleared by the use of this function.
\r
241 * @param[in] letimer
\r
242 * Pointer to LETIMER peripheral register block.
\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
250 return letimer->IF;
\r
254 /***************************************************************************//**
\r
256 * Get enabled and pending LETIMER interrupt flags.
\r
259 * Useful for handling more interrupt sources in the same interrupt handler.
\r
262 * The event bits are not cleared by the use of this function.
\r
264 * @param[in] letimer
\r
265 * Pointer to LETIMER peripheral register block.
\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
280 /* Store flags in temporary variable in order to define explicit order
\r
281 * of volatile accesses. */
\r
282 ien = letimer->IEN;
\r
284 /* Bitwise AND of pending and enabled interrupts */
\r
285 return letimer->IF & ien;
\r
289 /***************************************************************************//**
\r
291 * Set one or more pending LETIMER interrupts from SW.
\r
293 * @param[in] letimer
\r
294 * Pointer to LETIMER peripheral register block.
\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
302 letimer->IFS = flags;
\r
306 uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep);
\r
307 void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,
\r
310 void LETIMER_Reset(LETIMER_TypeDef *letimer);
\r
313 /** @} (end addtogroup LETIMER) */
\r
314 /** @} (end addtogroup EM_Library) */
\r
320 #endif /* defined(LETIMER_COUNT) && (LETIMER_COUNT > 0) */
\r
321 #endif /* __SILICON_LABS_EM_LETIMER_H__ */
\r