1 /***************************************************************************//**
\r
3 * @brief Low Energy Timer (LETIMER) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 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
34 #ifndef __SILICON_LABS_EM_LETIMER_H_
\r
35 #define __SILICON_LABS_EM_LETIMER_H_
\r
37 #include <stdbool.h>
\r
38 #include "em_device.h"
\r
39 #if defined(LETIMER_COUNT) && (LETIMER_COUNT > 0)
\r
45 /***************************************************************************//**
\r
46 * @addtogroup EM_Library
\r
48 ******************************************************************************/
\r
50 /***************************************************************************//**
\r
51 * @addtogroup LETIMER
\r
53 ******************************************************************************/
\r
55 /*******************************************************************************
\r
56 ******************************** ENUMS ************************************
\r
57 ******************************************************************************/
\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
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
70 letimerRepeatBuffered = _LETIMER_CTRL_REPMODE_BUFFERED,
\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
75 letimerRepeatDouble = _LETIMER_CTRL_REPMODE_DOUBLE
\r
76 } LETIMER_RepeatMode_TypeDef;
\r
79 /** Underflow action on output. */
\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
92 /*******************************************************************************
\r
93 ******************************* STRUCTS ***********************************
\r
94 ******************************************************************************/
\r
96 /** LETIMER initialization structure. */
\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
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
128 /*******************************************************************************
\r
129 ***************************** PROTOTYPES **********************************
\r
130 ******************************************************************************/
\r
132 uint32_t LETIMER_CompareGet(LETIMER_TypeDef *letimer, unsigned int comp);
\r
133 void LETIMER_CompareSet(LETIMER_TypeDef *letimer,
\r
138 /***************************************************************************//**
\r
140 * Get LETIMER counter value.
\r
142 * @param[in] letimer
\r
143 * Pointer to LETIMER peripheral register block.
\r
146 * Current LETIMER counter value.
\r
147 ******************************************************************************/
\r
148 __STATIC_INLINE uint32_t LETIMER_CounterGet(LETIMER_TypeDef *letimer)
\r
150 return(letimer->CNT);
\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
159 /***************************************************************************//**
\r
161 * Clear one or more pending LETIMER interrupts.
\r
163 * @param[in] letimer
\r
164 * Pointer to LETIMER peripheral register block.
\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
173 letimer->IFC = flags;
\r
177 /***************************************************************************//**
\r
179 * Disable one or more LETIMER interrupts.
\r
181 * @param[in] letimer
\r
182 * Pointer to LETIMER peripheral register block.
\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
190 letimer->IEN &= ~(flags);
\r
194 /***************************************************************************//**
\r
196 * Enable one or more LETIMER interrupts.
\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
203 * @param[in] letimer
\r
204 * Pointer to LETIMER peripheral register block.
\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
212 letimer->IEN |= flags;
\r
216 /***************************************************************************//**
\r
218 * Get pending LETIMER interrupt flags.
\r
221 * The event bits are not cleared by the use of this function.
\r
223 * @param[in] letimer
\r
224 * Pointer to LETIMER peripheral register block.
\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
232 return(letimer->IF);
\r
236 /***************************************************************************//**
\r
238 * Set one or more pending LETIMER interrupts from SW.
\r
240 * @param[in] letimer
\r
241 * Pointer to LETIMER peripheral register block.
\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
249 letimer->IFS = flags;
\r
252 uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep);
\r
253 void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,
\r
256 void LETIMER_Reset(LETIMER_TypeDef *letimer);
\r
259 /** @} (end addtogroup LETIMER) */
\r
260 /** @} (end addtogroup EM_Library) */
\r
266 #endif /* defined(LETIMER_COUNT) && (LETIMER_COUNT > 0) */
\r
268 #endif /* __SILICON_LABS_EM_LETIMER_H_ */
\r