1 /***************************************************************************//**
\r
3 * @brief Timer/counter (TIMER) 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_TIMER_H_
\r
35 #define __SILICON_LABS_EM_TIMER_H_
\r
37 #include "em_device.h"
\r
38 #if defined(TIMER_COUNT) && (TIMER_COUNT > 0)
\r
40 #include <stdbool.h>
\r
41 #include "em_assert.h"
\r
47 /***************************************************************************//**
\r
48 * @addtogroup EM_Library
\r
50 ******************************************************************************/
\r
52 /***************************************************************************//**
\r
55 ******************************************************************************/
\r
57 /*******************************************************************************
\r
58 ******************************* DEFINES ***********************************
\r
59 ******************************************************************************/
\r
61 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
\r
64 /** Validation of TIMER register block pointer reference for assert statements. */
\r
65 #if (TIMER_COUNT == 1)
\r
66 #define TIMER_REF_VALID(ref) ((ref) == TIMER0)
\r
67 #elif (TIMER_COUNT == 2)
\r
68 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) || ((ref) == TIMER1))
\r
69 #elif (TIMER_COUNT == 3)
\r
70 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) || \
\r
71 ((ref) == TIMER1) || \
\r
73 #elif (TIMER_COUNT == 4)
\r
74 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) || \
\r
75 ((ref) == TIMER1) || \
\r
76 ((ref) == TIMER2) || \
\r
79 #error Undefined number of timers.
\r
82 /** Validation of TIMER compare/capture channel number */
\r
83 #define TIMER_CH_VALID(ch) ((ch) < 3)
\r
87 /*******************************************************************************
\r
88 ******************************** ENUMS ************************************
\r
89 ******************************************************************************/
\r
91 /** Timer compare/capture mode. */
\r
94 timerCCModeOff = _TIMER_CC_CTRL_MODE_OFF, /**< Channel turned off. */
\r
95 timerCCModeCapture = _TIMER_CC_CTRL_MODE_INPUTCAPTURE, /**< Input capture. */
\r
96 timerCCModeCompare = _TIMER_CC_CTRL_MODE_OUTPUTCOMPARE, /**< Output compare. */
\r
97 timerCCModePWM = _TIMER_CC_CTRL_MODE_PWM /**< Pulse-Width modulation. */
\r
98 } TIMER_CCMode_TypeDef;
\r
101 /** Clock select. */
\r
104 /** Prescaled HFPER clock. */
\r
105 timerClkSelHFPerClk = _TIMER_CTRL_CLKSEL_PRESCHFPERCLK,
\r
107 /** Prescaled HFPER clock. */
\r
108 timerClkSelCC1 = _TIMER_CTRL_CLKSEL_CC1,
\r
111 * Cascaded, clocked by underflow (down-counting) or overflow (up-counting)
\r
112 * by lower numbered timer.
\r
114 timerClkSelCascade = _TIMER_CTRL_CLKSEL_TIMEROUF
\r
115 } TIMER_ClkSel_TypeDef;
\r
118 /** Input capture edge select. */
\r
121 /** Rising edges detected. */
\r
122 timerEdgeRising = _TIMER_CC_CTRL_ICEDGE_RISING,
\r
124 /** Falling edges detected. */
\r
125 timerEdgeFalling = _TIMER_CC_CTRL_ICEDGE_FALLING,
\r
127 /** Both edges detected. */
\r
128 timerEdgeBoth = _TIMER_CC_CTRL_ICEDGE_BOTH,
\r
130 /** No edge detection, leave signal as is. */
\r
131 timerEdgeNone = _TIMER_CC_CTRL_ICEDGE_NONE
\r
132 } TIMER_Edge_TypeDef;
\r
135 /** Input capture event control. */
\r
138 /** PRS output pulse, interrupt flag and DMA request set on every capture. */
\r
139 timerEventEveryEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYEDGE,
\r
140 /** PRS output pulse, interrupt flag and DMA request set on every second capture. */
\r
141 timerEventEvery2ndEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYSECONDEDGE,
\r
143 * PRS output pulse, interrupt flag and DMA request set on rising edge (if
\r
144 * input capture edge = BOTH).
\r
146 timerEventRising = _TIMER_CC_CTRL_ICEVCTRL_RISING,
\r
148 * PRS output pulse, interrupt flag and DMA request set on falling edge (if
\r
149 * input capture edge = BOTH).
\r
151 timerEventFalling = _TIMER_CC_CTRL_ICEVCTRL_FALLING
\r
152 } TIMER_Event_TypeDef;
\r
155 /** Input edge action. */
\r
158 /** No action taken. */
\r
159 timerInputActionNone = _TIMER_CTRL_FALLA_NONE,
\r
161 /** Start counter without reload. */
\r
162 timerInputActionStart = _TIMER_CTRL_FALLA_START,
\r
164 /** Stop counter without reload. */
\r
165 timerInputActionStop = _TIMER_CTRL_FALLA_STOP,
\r
167 /** Reload and start counter. */
\r
168 timerInputActionReloadStart = _TIMER_CTRL_FALLA_RELOADSTART
\r
169 } TIMER_InputAction_TypeDef;
\r
175 timerModeUp = _TIMER_CTRL_MODE_UP, /**< Up-counting. */
\r
176 timerModeDown = _TIMER_CTRL_MODE_DOWN, /**< Down-counting. */
\r
177 timerModeUpDown = _TIMER_CTRL_MODE_UPDOWN, /**< Up/down-counting. */
\r
178 timerModeQDec = _TIMER_CTRL_MODE_QDEC /**< Quadrature decoder. */
\r
179 } TIMER_Mode_TypeDef;
\r
182 /** Compare/capture output action. */
\r
186 timerOutputActionNone = _TIMER_CC_CTRL_CUFOA_NONE,
\r
188 /** Toggle on event. */
\r
189 timerOutputActionToggle = _TIMER_CC_CTRL_CUFOA_TOGGLE,
\r
191 /** Clear on event. */
\r
192 timerOutputActionClear = _TIMER_CC_CTRL_CUFOA_CLEAR,
\r
194 /** Set on event. */
\r
195 timerOutputActionSet = _TIMER_CC_CTRL_CUFOA_SET
\r
196 } TIMER_OutputAction_TypeDef;
\r
202 timerPrescale1 = _TIMER_CTRL_PRESC_DIV1, /**< Divide by 1. */
\r
203 timerPrescale2 = _TIMER_CTRL_PRESC_DIV2, /**< Divide by 2. */
\r
204 timerPrescale4 = _TIMER_CTRL_PRESC_DIV4, /**< Divide by 4. */
\r
205 timerPrescale8 = _TIMER_CTRL_PRESC_DIV8, /**< Divide by 8. */
\r
206 timerPrescale16 = _TIMER_CTRL_PRESC_DIV16, /**< Divide by 16. */
\r
207 timerPrescale32 = _TIMER_CTRL_PRESC_DIV32, /**< Divide by 32. */
\r
208 timerPrescale64 = _TIMER_CTRL_PRESC_DIV64, /**< Divide by 64. */
\r
209 timerPrescale128 = _TIMER_CTRL_PRESC_DIV128, /**< Divide by 128. */
\r
210 timerPrescale256 = _TIMER_CTRL_PRESC_DIV256, /**< Divide by 256. */
\r
211 timerPrescale512 = _TIMER_CTRL_PRESC_DIV512, /**< Divide by 512. */
\r
212 timerPrescale1024 = _TIMER_CTRL_PRESC_DIV1024 /**< Divide by 1024. */
\r
213 } TIMER_Prescale_TypeDef;
\r
216 /** Peripheral Reflex System signal. */
\r
219 timerPRSSELCh0 = _TIMER_CC_CTRL_PRSSEL_PRSCH0, /**< PRS channel 0. */
\r
220 timerPRSSELCh1 = _TIMER_CC_CTRL_PRSSEL_PRSCH1, /**< PRS channel 1. */
\r
221 timerPRSSELCh2 = _TIMER_CC_CTRL_PRSSEL_PRSCH2, /**< PRS channel 2. */
\r
222 timerPRSSELCh3 = _TIMER_CC_CTRL_PRSSEL_PRSCH3, /**< PRS channel 3. */
\r
223 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH4 )
\r
224 timerPRSSELCh4 = _TIMER_CC_CTRL_PRSSEL_PRSCH4, /**< PRS channel 4. */
\r
226 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH5 )
\r
227 timerPRSSELCh5 = _TIMER_CC_CTRL_PRSSEL_PRSCH5, /**< PRS channel 5. */
\r
229 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH6 )
\r
230 timerPRSSELCh6 = _TIMER_CC_CTRL_PRSSEL_PRSCH6, /**< PRS channel 6. */
\r
232 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH7 )
\r
233 timerPRSSELCh7 = _TIMER_CC_CTRL_PRSSEL_PRSCH7, /**< PRS channel 7. */
\r
235 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH8 )
\r
236 timerPRSSELCh8 = _TIMER_CC_CTRL_PRSSEL_PRSCH8, /**< PRS channel 8. */
\r
238 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH9 )
\r
239 timerPRSSELCh9 = _TIMER_CC_CTRL_PRSSEL_PRSCH9, /**< PRS channel 9. */
\r
241 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH10 )
\r
242 timerPRSSELCh10 = _TIMER_CC_CTRL_PRSSEL_PRSCH10, /**< PRS channel 10. */
\r
244 #if defined( _TIMER_CC_CTRL_PRSSEL_PRSCH11 )
\r
245 timerPRSSELCh11 = _TIMER_CC_CTRL_PRSSEL_PRSCH11, /**< PRS channel 11. */
\r
247 } TIMER_PRSSEL_TypeDef;
\r
249 #ifdef _TIMER_DTFC_DTFA_NONE
\r
250 /** DT (Dead Time) Fault Actions. */
\r
253 timerDtiFaultActionNone = _TIMER_DTFC_DTFA_NONE, /**< No action on fault. */
\r
254 timerDtiFaultActionInactive = _TIMER_DTFC_DTFA_INACTIVE, /**< Set outputs inactive. */
\r
255 timerDtiFaultActionClear = _TIMER_DTFC_DTFA_CLEAR, /**< Clear outputs. */
\r
256 timerDtiFaultActionTristate = _TIMER_DTFC_DTFA_TRISTATE /**< Tristate outputs. */
\r
257 } TIMER_DtiFaultAction_TypeDef;
\r
260 /*******************************************************************************
\r
261 ******************************* STRUCTS ***********************************
\r
262 ******************************************************************************/
\r
264 /** TIMER initialization structure. */
\r
267 /** Start counting when init completed. */
\r
270 /** Counter shall keep running during debug halt. */
\r
273 /** Prescaling factor, if HFPER clock used. */
\r
274 TIMER_Prescale_TypeDef prescale;
\r
276 /** Clock selection. */
\r
277 TIMER_ClkSel_TypeDef clkSel;
\r
279 #if defined( TIMER_CTRL_X2CNT ) && defined( TIMER_CTRL_ATI )
\r
280 /** 2x Count mode, counter increments/decrements by 2, meant for PWN mode. */
\r
283 /** ATI (Always Track Inputs) makes CCPOL always track
\r
284 * the polarity of the inputs. */
\r
288 /** Action on falling input edge. */
\r
289 TIMER_InputAction_TypeDef fallAction;
\r
291 /** Action on rising input edge. */
\r
292 TIMER_InputAction_TypeDef riseAction;
\r
294 /** Counting mode. */
\r
295 TIMER_Mode_TypeDef mode;
\r
297 /** DMA request clear on active. */
\r
300 /** Select X2 or X4 quadrature decode mode (if used). */
\r
303 /** Determines if only counting up or down once. */
\r
306 /** Timer start/stop/reload by other timers. */
\r
308 } TIMER_Init_TypeDef;
\r
310 /** Default config for TIMER init structure. */
\r
311 #if defined( TIMER_CTRL_X2CNT ) && defined( TIMER_CTRL_ATI )
\r
312 #define TIMER_INIT_DEFAULT \
\r
313 { true, /* Enable timer when init complete. */ \
\r
314 false, /* Stop counter during debug halt. */ \
\r
315 timerPrescale1, /* No prescaling. */ \
\r
316 timerClkSelHFPerClk, /* Select HFPER clock. */ \
\r
317 false, /* Not 2x count mode. */ \
\r
318 false, /* No ATI. */ \
\r
319 timerInputActionNone, /* No action on falling input edge. */ \
\r
320 timerInputActionNone, /* No action on rising input edge. */ \
\r
321 timerModeUp, /* Up-counting. */ \
\r
322 false, /* Do not clear DMA requests when DMA channel is active. */ \
\r
323 false, /* Select X2 quadrature decode mode (if used). */ \
\r
324 false, /* Disable one shot. */ \
\r
325 false /* Not started/stopped/reloaded by other timers. */ \
\r
328 #define TIMER_INIT_DEFAULT \
\r
329 { true, /* Enable timer when init complete. */ \
\r
330 false, /* Stop counter during debug halt. */ \
\r
331 timerPrescale1, /* No prescaling. */ \
\r
332 timerClkSelHFPerClk, /* Select HFPER clock. */ \
\r
333 timerInputActionNone, /* No action on falling input edge. */ \
\r
334 timerInputActionNone, /* No action on rising input edge. */ \
\r
335 timerModeUp, /* Up-counting. */ \
\r
336 false, /* Do not clear DMA requests when DMA channel is active. */ \
\r
337 false, /* Select X2 quadrature decode mode (if used). */ \
\r
338 false, /* Disable one shot. */ \
\r
339 false /* Not started/stopped/reloaded by other timers. */ \
\r
343 /** TIMER compare/capture initialization structure. */
\r
346 /** Input capture event control. */
\r
347 TIMER_Event_TypeDef eventCtrl;
\r
349 /** Input capture edge select. */
\r
350 TIMER_Edge_TypeDef edge;
\r
353 * Peripheral reflex system trigger selection. Only applicable if @p prsInput
\r
356 TIMER_PRSSEL_TypeDef prsSel;
\r
358 /** Counter underflow output action. */
\r
359 TIMER_OutputAction_TypeDef cufoa;
\r
361 /** Counter overflow output action. */
\r
362 TIMER_OutputAction_TypeDef cofoa;
\r
364 /** Counter match output action. */
\r
365 TIMER_OutputAction_TypeDef cmoa;
\r
367 /** Compare/capture channel mode. */
\r
368 TIMER_CCMode_TypeDef mode;
\r
370 /** Enable digital filter. */
\r
373 /** Select TIMERnCCx (false) or PRS input (true). */
\r
377 * Compare output initial state. Only used in Output Compare and PWM mode.
\r
378 * When true, the compare/PWM output is set high when the counter is
\r
379 * disabled. When counting resumes, this value will represent the initial
\r
380 * value for the compare/PWM output. If the bit is cleared, the output
\r
381 * will be cleared when the counter is disabled.
\r
385 /** Invert output from compare/capture channel. */
\r
387 } TIMER_InitCC_TypeDef;
\r
389 /** Default config for TIMER compare/capture init structure. */
\r
390 #define TIMER_INITCC_DEFAULT \
\r
391 { timerEventEveryEdge, /* Event on every capture. */ \
\r
392 timerEdgeRising, /* Input capture edge on rising edge. */ \
\r
393 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
\r
394 timerOutputActionNone, /* No action on underflow. */ \
\r
395 timerOutputActionNone, /* No action on overflow. */ \
\r
396 timerOutputActionNone, /* No action on match. */ \
\r
397 timerCCModeOff, /* Disable compare/capture channel. */ \
\r
398 false, /* Disable filter. */ \
\r
399 false, /* Select TIMERnCCx input. */ \
\r
400 false, /* Clear output when counter disabled. */ \
\r
401 false /* Do not invert output. */ \
\r
404 #ifdef _TIMER_DTCTRL_MASK
\r
405 /** TIMER Dead Time Insertion (DTI) initialization structure. */
\r
408 /** Enable DTI or leave it disabled until @ref TIMER_EnableDTI() is called */
\r
411 /** DTI Output Polarity */
\r
414 /** DTI Complementary Output Invert */
\r
415 bool invertComplementaryOut;
\r
417 /** Enable Automatic Start-up functionality (when debugger exits) */
\r
420 /** Enable/disable PRS as DTI input. */
\r
421 bool enablePrsSource;
\r
423 /** Select which PRS channel as DTI input. Only valid if @p enablePrsSource
\r
425 TIMER_PRSSEL_TypeDef prsSel;
\r
427 /** DTI prescaling factor, if HFPER clock used. */
\r
428 TIMER_Prescale_TypeDef prescale;
\r
430 /** DTI Rise Time */
\r
431 unsigned int riseTime;
\r
433 /** DTI Fall Time */
\r
434 unsigned int fallTime;
\r
436 /** DTI outputs enable bit mask, consisting of one bit per DTI
\r
437 output signal, i.e. CC0, CC1, CC2, CDTI0, CDTI1 and CDTI2.
\r
438 This value should consist of one or more TIMER_DTOGEN_DTOGnnnEN flags
\r
439 (defined in \<part_name\>_timer.h) OR'ed together. */
\r
440 uint32_t outputsEnableMask;
\r
442 /** Enable core lockup as a fault source. */
\r
443 bool enableFaultSourceCoreLockup;
\r
445 /** Enable debugger as a fault source. */
\r
446 bool enableFaultSourceDebugger;
\r
448 /** Enable PRS fault source 0 (@p faultSourcePrsSel0) */
\r
449 bool enableFaultSourcePrsSel0;
\r
451 /** Select which PRS signal to be PRS fault source 0. */
\r
452 TIMER_PRSSEL_TypeDef faultSourcePrsSel0;
\r
454 /** Enable PRS fault source 1 (@p faultSourcePrsSel1) */
\r
455 bool enableFaultSourcePrsSel1;
\r
457 /** Select which PRS signal to be PRS fault source 1. */
\r
458 TIMER_PRSSEL_TypeDef faultSourcePrsSel1;
\r
460 /** Fault Action */
\r
461 TIMER_DtiFaultAction_TypeDef faultAction;
\r
463 } TIMER_InitDTI_TypeDef;
\r
466 /** Default config for TIMER DTI init structure. */
\r
467 #define TIMER_INITDTI_DEFAULT \
\r
468 { true, /* Enable the DTI. */ \
\r
469 false, /* CC[0|1|2] outputs are active high. */ \
\r
470 false, /* CDTI[0|1|2] outputs are not inverted. */ \
\r
471 false, /* No auto restart when debugger exits. */ \
\r
472 false, /* No PRS source selected. */ \
\r
473 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
\r
474 timerPrescale1, /* No prescaling. */ \
\r
475 0, /* No rise time. */ \
\r
476 0, /* No fall time. */ \
\r
477 TIMER_DTOGEN_DTOGCC0EN|TIMER_DTOGEN_DTOGCDTI0EN, /* Enable CC0 and CDTI0 */\
\r
478 true, /* Enable core lockup as fault source */ \
\r
479 true, /* Enable debugger as fault source */ \
\r
480 false, /* Disable PRS fault source 0 */ \
\r
481 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
\r
482 false, /* Disable PRS fault source 1 */ \
\r
483 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
\r
484 timerDtiFaultActionInactive, /* No fault action. */ \
\r
486 #endif /* _TIMER_DTCTRL_MASK */
\r
489 /*******************************************************************************
\r
490 ***************************** PROTOTYPES **********************************
\r
491 ******************************************************************************/
\r
493 /***************************************************************************//**
\r
495 * Get capture value for compare/capture channel when operating in capture
\r
499 * Pointer to TIMER peripheral register block.
\r
502 * Compare/capture channel to access.
\r
505 * Current capture value.
\r
506 ******************************************************************************/
\r
507 __STATIC_INLINE uint32_t TIMER_CaptureGet(TIMER_TypeDef *timer, unsigned int ch)
\r
509 return(timer->CC[ch].CCV);
\r
513 /***************************************************************************//**
\r
515 * Set compare value buffer for compare/capture channel when operating in
\r
516 * compare or PWM mode.
\r
519 * The compare value buffer holds the value which will be written to
\r
520 * TIMERn_CCx_CCV on an update event if the buffer has been updated since
\r
524 * Pointer to TIMER peripheral register block.
\r
527 * Compare/capture channel to access.
\r
530 * Value to set in compare value buffer register.
\r
531 ******************************************************************************/
\r
532 __STATIC_INLINE void TIMER_CompareBufSet(TIMER_TypeDef *timer,
\r
536 timer->CC[ch].CCVB = val;
\r
540 /***************************************************************************//**
\r
542 * Set compare value for compare/capture channel when operating in compare
\r
546 * Pointer to TIMER peripheral register block.
\r
549 * Compare/capture channel to access.
\r
552 * Value to set in compare value register.
\r
553 ******************************************************************************/
\r
554 __STATIC_INLINE void TIMER_CompareSet(TIMER_TypeDef *timer,
\r
558 timer->CC[ch].CCV = val;
\r
562 /***************************************************************************//**
\r
564 * Get TIMER counter value.
\r
567 * Pointer to TIMER peripheral register block.
\r
570 * Current TIMER counter value.
\r
571 ******************************************************************************/
\r
572 __STATIC_INLINE uint32_t TIMER_CounterGet(TIMER_TypeDef *timer)
\r
574 return(timer->CNT);
\r
578 /***************************************************************************//**
\r
580 * Set TIMER counter value.
\r
583 * Pointer to TIMER peripheral register block.
\r
586 * Value to set counter to.
\r
587 ******************************************************************************/
\r
588 __STATIC_INLINE void TIMER_CounterSet(TIMER_TypeDef *timer, uint32_t val)
\r
594 /***************************************************************************//**
\r
596 * Start/stop TIMER.
\r
599 * Pointer to TIMER peripheral register block.
\r
601 * @param[in] enable
\r
602 * true to enable counting, false to disable.
\r
603 ******************************************************************************/
\r
604 __STATIC_INLINE void TIMER_Enable(TIMER_TypeDef *timer, bool enable)
\r
606 EFM_ASSERT(TIMER_REF_VALID(timer));
\r
610 timer->CMD = TIMER_CMD_START;
\r
614 timer->CMD = TIMER_CMD_STOP;
\r
619 void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init);
\r
620 void TIMER_InitCC(TIMER_TypeDef *timer,
\r
622 const TIMER_InitCC_TypeDef *init);
\r
624 #ifdef _TIMER_DTCTRL_MASK
\r
625 void TIMER_InitDTI(TIMER_TypeDef *timer, const TIMER_InitDTI_TypeDef *init);
\r
627 /***************************************************************************//**
\r
629 * Enable or disable DTI unit.
\r
632 * Pointer to TIMER peripheral register block.
\r
634 * @param[in] enable
\r
635 * true to enable DTI unit, false to disable.
\r
636 ******************************************************************************/
\r
637 __STATIC_INLINE void TIMER_EnableDTI(TIMER_TypeDef *timer, bool enable)
\r
639 EFM_ASSERT(TIMER0 == timer);
\r
643 timer->DTCTRL |= TIMER_DTCTRL_DTEN;
\r
647 timer->DTCTRL &= ~TIMER_DTCTRL_DTEN;
\r
652 /***************************************************************************//**
\r
654 * Get DTI fault source flags status.
\r
657 * The event bits are not cleared by the use of this function.
\r
660 * Pointer to TIMER peripheral register block.
\r
663 * Status of the DTI fault source flags. Returns one or more valid
\r
664 * DTI fault source flags (TIMER_DTFAULT_nnn) OR'ed together.
\r
665 ******************************************************************************/
\r
666 __STATIC_INLINE uint32_t TIMER_GetDTIFault(TIMER_TypeDef *timer)
\r
668 EFM_ASSERT(TIMER0 == timer);
\r
669 return(timer->DTFAULT);
\r
673 /***************************************************************************//**
\r
675 * Clear DTI fault source flags.
\r
678 * Pointer to TIMER peripheral register block.
\r
681 * DTI fault source(s) to clear. Use one or more valid DTI fault
\r
682 * source flags (TIMER_DTFAULT_nnn) OR'ed together.
\r
683 ******************************************************************************/
\r
684 __STATIC_INLINE void TIMER_ClearDTIFault(TIMER_TypeDef *timer, uint32_t flags)
\r
687 EFM_ASSERT(TIMER0 == timer);
\r
688 timer->DTFAULTC = flags;
\r
690 #endif /* _TIMER_DTCTRL_MASK */
\r
693 /***************************************************************************//**
\r
695 * Clear one or more pending TIMER interrupts.
\r
698 * Pointer to TIMER peripheral register block.
\r
701 * Pending TIMER interrupt source(s) to clear. Use one or more valid
\r
702 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
\r
703 ******************************************************************************/
\r
704 __STATIC_INLINE void TIMER_IntClear(TIMER_TypeDef *timer, uint32_t flags)
\r
706 timer->IFC = flags;
\r
710 /***************************************************************************//**
\r
712 * Disable one or more TIMER interrupts.
\r
715 * Pointer to TIMER peripheral register block.
\r
718 * TIMER interrupt source(s) to disable. Use one or more valid
\r
719 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
\r
720 ******************************************************************************/
\r
721 __STATIC_INLINE void TIMER_IntDisable(TIMER_TypeDef *timer, uint32_t flags)
\r
723 timer->IEN &= ~(flags);
\r
727 /***************************************************************************//**
\r
729 * Enable one or more TIMER interrupts.
\r
732 * Depending on the use, a pending interrupt may already be set prior to
\r
733 * enabling the interrupt. Consider using TIMER_IntClear() prior to enabling
\r
734 * if such a pending interrupt should be ignored.
\r
737 * Pointer to TIMER peripheral register block.
\r
740 * TIMER interrupt source(s) to enable. Use one or more valid
\r
741 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
\r
742 ******************************************************************************/
\r
743 __STATIC_INLINE void TIMER_IntEnable(TIMER_TypeDef *timer, uint32_t flags)
\r
745 timer->IEN |= flags;
\r
749 /***************************************************************************//**
\r
751 * Get pending TIMER interrupt flags.
\r
754 * The event bits are not cleared by the use of this function.
\r
757 * Pointer to TIMER peripheral register block.
\r
760 * TIMER interrupt source(s) pending. Returns one or more valid
\r
761 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
\r
762 ******************************************************************************/
\r
763 __STATIC_INLINE uint32_t TIMER_IntGet(TIMER_TypeDef *timer)
\r
769 /***************************************************************************//**
\r
771 * Get enabled and pending TIMER interrupt flags.
\r
772 * Useful for handling more interrupt sources in the same interrupt handler.
\r
775 * Pointer to TIMER peripheral register block.
\r
778 * Interrupt flags are not cleared by the use of this function.
\r
781 * Pending and enabled TIMER interrupt sources.
\r
782 * The return value is the bitwise AND combination of
\r
783 * - the OR combination of enabled interrupt sources in TIMERx_IEN_nnn
\r
784 * register (TIMERx_IEN_nnn) and
\r
785 * - the OR combination of valid interrupt flags of the TIMER module
\r
787 ******************************************************************************/
\r
788 __STATIC_INLINE uint32_t TIMER_IntGetEnabled(TIMER_TypeDef *timer)
\r
792 /* Store TIMER->IEN in temporary variable in order to define explicit order
\r
793 * of volatile accesses. */
\r
796 /* Bitwise AND of pending and enabled interrupts */
\r
797 return timer->IF & tmp;
\r
801 /***************************************************************************//**
\r
803 * Set one or more pending TIMER interrupts from SW.
\r
806 * Pointer to TIMER peripheral register block.
\r
809 * TIMER interrupt source(s) to set to pending. Use one or more valid
\r
810 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
\r
811 ******************************************************************************/
\r
812 __STATIC_INLINE void TIMER_IntSet(TIMER_TypeDef *timer, uint32_t flags)
\r
814 timer->IFS = flags;
\r
817 #ifdef TIMER_DTLOCK_LOCKKEY_LOCK
\r
818 /***************************************************************************//**
\r
820 * Lock some of the TIMER registers in order to protect them from being
\r
824 * Please refer to the reference manual for TIMER registers that will be
\r
828 * If locking the TIMER registers, they must be unlocked prior to using any
\r
829 * TIMER API functions modifying TIMER registers protected by the lock.
\r
832 * Pointer to TIMER peripheral register block.
\r
833 ******************************************************************************/
\r
834 __STATIC_INLINE void TIMER_Lock(TIMER_TypeDef *timer)
\r
836 EFM_ASSERT(TIMER0 == timer);
\r
838 timer->DTLOCK = TIMER_DTLOCK_LOCKKEY_LOCK;
\r
842 void TIMER_Reset(TIMER_TypeDef *timer);
\r
844 /***************************************************************************//**
\r
846 * Set top value buffer for timer.
\r
849 * When the top value buffer register is updated, the value is loaded into
\r
850 * the top value register at the next wrap around. This feature is useful
\r
851 * in order to update the top value safely when the timer is running.
\r
854 * Pointer to TIMER peripheral register block.
\r
857 * Value to set in top value buffer register.
\r
858 ******************************************************************************/
\r
859 __STATIC_INLINE void TIMER_TopBufSet(TIMER_TypeDef *timer, uint32_t val)
\r
865 /***************************************************************************//**
\r
867 * Get top value setting for timer.
\r
870 * Pointer to TIMER peripheral register block.
\r
873 * Current top value.
\r
874 ******************************************************************************/
\r
875 __STATIC_INLINE uint32_t TIMER_TopGet(TIMER_TypeDef *timer)
\r
877 return(timer->TOP);
\r
881 /***************************************************************************//**
\r
883 * Set top value for timer.
\r
886 * Pointer to TIMER peripheral register block.
\r
889 * Value to set in top value register.
\r
890 ******************************************************************************/
\r
891 __STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
\r
897 #ifdef TIMER_DTLOCK_LOCKKEY_UNLOCK
\r
898 /***************************************************************************//**
\r
900 * Unlock the TIMER so that writing to locked registers again is possible.
\r
903 * Pointer to TIMER peripheral register block.
\r
904 ******************************************************************************/
\r
905 __STATIC_INLINE void TIMER_Unlock(TIMER_TypeDef *timer)
\r
907 EFM_ASSERT(TIMER0 == timer);
\r
909 timer->DTLOCK = TIMER_DTLOCK_LOCKKEY_UNLOCK;
\r
914 /** @} (end addtogroup TIMER) */
\r
915 /** @} (end addtogroup EM_Library) */
\r
921 #endif /* defined(TIMER_COUNT) && (TIMER_COUNT > 0) */
\r
922 #endif /* __SILICON_LABS_EM_TIMER_H_ */
\r