The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Tue Feb 02 14:43:35 2016 +0000
Revision:
113:f141b2784e32
Parent:
98:8ab26030e058
Child:
128:9bcdf88f62b0
Release 113 of the mbed library

Changes:
- new targets - Silabs Perl Gecko, TY51822
- Silabs - emlib update to 4.1.0, various bugfixes as result
- STM B96B_F446VE - add async serial support
- Freescale KLXX - rtc lock fix
- LPC11U68 and LPC1549 - pwm bugfixes - duty cycle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /***************************************************************************//**
Kojto 98:8ab26030e058 2 * @file em_timer.h
Kojto 98:8ab26030e058 3 * @brief Timer/counter (TIMER) peripheral API
Kojto 113:f141b2784e32 4 * @version 4.2.1
Kojto 98:8ab26030e058 5 *******************************************************************************
Kojto 98:8ab26030e058 6 * @section License
Kojto 113:f141b2784e32 7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
Kojto 98:8ab26030e058 8 *******************************************************************************
Kojto 98:8ab26030e058 9 *
Kojto 98:8ab26030e058 10 * Permission is granted to anyone to use this software for any purpose,
Kojto 98:8ab26030e058 11 * including commercial applications, and to alter it and redistribute it
Kojto 98:8ab26030e058 12 * freely, subject to the following restrictions:
Kojto 98:8ab26030e058 13 *
Kojto 98:8ab26030e058 14 * 1. The origin of this software must not be misrepresented; you must not
Kojto 98:8ab26030e058 15 * claim that you wrote the original software.
Kojto 98:8ab26030e058 16 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 98:8ab26030e058 17 * misrepresented as being the original software.
Kojto 98:8ab26030e058 18 * 3. This notice may not be removed or altered from any source distribution.
Kojto 98:8ab26030e058 19 *
Kojto 98:8ab26030e058 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 98:8ab26030e058 21 * obligation to support this Software. Silicon Labs is providing the
Kojto 98:8ab26030e058 22 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 98:8ab26030e058 23 * including, but not limited to, any implied warranties of merchantability
Kojto 98:8ab26030e058 24 * or fitness for any particular purpose or warranties against infringement
Kojto 98:8ab26030e058 25 * of any proprietary rights of a third party.
Kojto 98:8ab26030e058 26 *
Kojto 98:8ab26030e058 27 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 98:8ab26030e058 28 * special damages, or any other relief, or for any claim by any third party,
Kojto 98:8ab26030e058 29 * arising from your use of this Software.
Kojto 98:8ab26030e058 30 *
Kojto 98:8ab26030e058 31 ******************************************************************************/
Kojto 98:8ab26030e058 32
Kojto 113:f141b2784e32 33 #ifndef __SILICON_LABS_EM_TIMER_H__
Kojto 113:f141b2784e32 34 #define __SILICON_LABS_EM_TIMER_H__
Kojto 98:8ab26030e058 35
Kojto 98:8ab26030e058 36 #include "em_device.h"
Kojto 98:8ab26030e058 37 #if defined(TIMER_COUNT) && (TIMER_COUNT > 0)
Kojto 98:8ab26030e058 38
Kojto 98:8ab26030e058 39 #include <stdbool.h>
Kojto 98:8ab26030e058 40 #include "em_assert.h"
Kojto 98:8ab26030e058 41
Kojto 98:8ab26030e058 42 #ifdef __cplusplus
Kojto 98:8ab26030e058 43 extern "C" {
Kojto 98:8ab26030e058 44 #endif
Kojto 98:8ab26030e058 45
Kojto 98:8ab26030e058 46 /***************************************************************************//**
Kojto 98:8ab26030e058 47 * @addtogroup EM_Library
Kojto 98:8ab26030e058 48 * @{
Kojto 98:8ab26030e058 49 ******************************************************************************/
Kojto 98:8ab26030e058 50
Kojto 98:8ab26030e058 51 /***************************************************************************//**
Kojto 98:8ab26030e058 52 * @addtogroup TIMER
Kojto 98:8ab26030e058 53 * @{
Kojto 98:8ab26030e058 54 ******************************************************************************/
Kojto 98:8ab26030e058 55
Kojto 98:8ab26030e058 56 /*******************************************************************************
Kojto 98:8ab26030e058 57 ******************************* DEFINES ***********************************
Kojto 98:8ab26030e058 58 ******************************************************************************/
Kojto 98:8ab26030e058 59
Kojto 98:8ab26030e058 60 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 98:8ab26030e058 61
Kojto 98:8ab26030e058 62
Kojto 98:8ab26030e058 63 /** Validation of TIMER register block pointer reference for assert statements. */
Kojto 98:8ab26030e058 64 #if (TIMER_COUNT == 1)
Kojto 98:8ab26030e058 65 #define TIMER_REF_VALID(ref) ((ref) == TIMER0)
Kojto 98:8ab26030e058 66 #elif (TIMER_COUNT == 2)
Kojto 98:8ab26030e058 67 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) || ((ref) == TIMER1))
Kojto 98:8ab26030e058 68 #elif (TIMER_COUNT == 3)
Kojto 113:f141b2784e32 69 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) \
Kojto 113:f141b2784e32 70 || ((ref) == TIMER1) \
Kojto 113:f141b2784e32 71 || ((ref) == TIMER2))
Kojto 98:8ab26030e058 72 #elif (TIMER_COUNT == 4)
Kojto 113:f141b2784e32 73 #define TIMER_REF_VALID(ref) (((ref) == TIMER0) \
Kojto 113:f141b2784e32 74 || ((ref) == TIMER1) \
Kojto 113:f141b2784e32 75 || ((ref) == TIMER2) \
Kojto 113:f141b2784e32 76 || ((ref) == TIMER3))
Kojto 98:8ab26030e058 77 #else
Kojto 113:f141b2784e32 78 #error "Undefined number of timers."
Kojto 98:8ab26030e058 79 #endif
Kojto 98:8ab26030e058 80
Kojto 98:8ab26030e058 81 /** Validation of TIMER compare/capture channel number */
Kojto 113:f141b2784e32 82 #if defined(_SILICON_LABS_32B_PLATFORM_1)
Kojto 98:8ab26030e058 83 #define TIMER_CH_VALID(ch) ((ch) < 3)
Kojto 113:f141b2784e32 84 #elif defined(_SILICON_LABS_32B_PLATFORM_2)
Kojto 113:f141b2784e32 85 #define TIMER_CH_VALID(ch) ((ch) < 4)
Kojto 113:f141b2784e32 86 #else
Kojto 113:f141b2784e32 87 #error "Unknown platform. Undefined number of channels."
Kojto 113:f141b2784e32 88 #endif
Kojto 98:8ab26030e058 89
Kojto 98:8ab26030e058 90 /** @endcond */
Kojto 98:8ab26030e058 91
Kojto 98:8ab26030e058 92 /*******************************************************************************
Kojto 98:8ab26030e058 93 ******************************** ENUMS ************************************
Kojto 98:8ab26030e058 94 ******************************************************************************/
Kojto 98:8ab26030e058 95
Kojto 98:8ab26030e058 96 /** Timer compare/capture mode. */
Kojto 98:8ab26030e058 97 typedef enum
Kojto 98:8ab26030e058 98 {
Kojto 98:8ab26030e058 99 timerCCModeOff = _TIMER_CC_CTRL_MODE_OFF, /**< Channel turned off. */
Kojto 98:8ab26030e058 100 timerCCModeCapture = _TIMER_CC_CTRL_MODE_INPUTCAPTURE, /**< Input capture. */
Kojto 98:8ab26030e058 101 timerCCModeCompare = _TIMER_CC_CTRL_MODE_OUTPUTCOMPARE, /**< Output compare. */
Kojto 98:8ab26030e058 102 timerCCModePWM = _TIMER_CC_CTRL_MODE_PWM /**< Pulse-Width modulation. */
Kojto 98:8ab26030e058 103 } TIMER_CCMode_TypeDef;
Kojto 98:8ab26030e058 104
Kojto 98:8ab26030e058 105
Kojto 98:8ab26030e058 106 /** Clock select. */
Kojto 98:8ab26030e058 107 typedef enum
Kojto 98:8ab26030e058 108 {
Kojto 98:8ab26030e058 109 /** Prescaled HFPER clock. */
Kojto 98:8ab26030e058 110 timerClkSelHFPerClk = _TIMER_CTRL_CLKSEL_PRESCHFPERCLK,
Kojto 98:8ab26030e058 111
Kojto 98:8ab26030e058 112 /** Prescaled HFPER clock. */
Kojto 98:8ab26030e058 113 timerClkSelCC1 = _TIMER_CTRL_CLKSEL_CC1,
Kojto 98:8ab26030e058 114
Kojto 98:8ab26030e058 115 /**
Kojto 98:8ab26030e058 116 * Cascaded, clocked by underflow (down-counting) or overflow (up-counting)
Kojto 98:8ab26030e058 117 * by lower numbered timer.
Kojto 98:8ab26030e058 118 */
Kojto 98:8ab26030e058 119 timerClkSelCascade = _TIMER_CTRL_CLKSEL_TIMEROUF
Kojto 98:8ab26030e058 120 } TIMER_ClkSel_TypeDef;
Kojto 98:8ab26030e058 121
Kojto 98:8ab26030e058 122
Kojto 98:8ab26030e058 123 /** Input capture edge select. */
Kojto 98:8ab26030e058 124 typedef enum
Kojto 98:8ab26030e058 125 {
Kojto 98:8ab26030e058 126 /** Rising edges detected. */
Kojto 98:8ab26030e058 127 timerEdgeRising = _TIMER_CC_CTRL_ICEDGE_RISING,
Kojto 98:8ab26030e058 128
Kojto 98:8ab26030e058 129 /** Falling edges detected. */
Kojto 98:8ab26030e058 130 timerEdgeFalling = _TIMER_CC_CTRL_ICEDGE_FALLING,
Kojto 98:8ab26030e058 131
Kojto 98:8ab26030e058 132 /** Both edges detected. */
Kojto 98:8ab26030e058 133 timerEdgeBoth = _TIMER_CC_CTRL_ICEDGE_BOTH,
Kojto 98:8ab26030e058 134
Kojto 98:8ab26030e058 135 /** No edge detection, leave signal as is. */
Kojto 98:8ab26030e058 136 timerEdgeNone = _TIMER_CC_CTRL_ICEDGE_NONE
Kojto 98:8ab26030e058 137 } TIMER_Edge_TypeDef;
Kojto 98:8ab26030e058 138
Kojto 98:8ab26030e058 139
Kojto 98:8ab26030e058 140 /** Input capture event control. */
Kojto 98:8ab26030e058 141 typedef enum
Kojto 98:8ab26030e058 142 {
Kojto 98:8ab26030e058 143 /** PRS output pulse, interrupt flag and DMA request set on every capture. */
Kojto 98:8ab26030e058 144 timerEventEveryEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYEDGE,
Kojto 98:8ab26030e058 145 /** PRS output pulse, interrupt flag and DMA request set on every second capture. */
Kojto 98:8ab26030e058 146 timerEventEvery2ndEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYSECONDEDGE,
Kojto 98:8ab26030e058 147 /**
Kojto 98:8ab26030e058 148 * PRS output pulse, interrupt flag and DMA request set on rising edge (if
Kojto 98:8ab26030e058 149 * input capture edge = BOTH).
Kojto 98:8ab26030e058 150 */
Kojto 98:8ab26030e058 151 timerEventRising = _TIMER_CC_CTRL_ICEVCTRL_RISING,
Kojto 98:8ab26030e058 152 /**
Kojto 98:8ab26030e058 153 * PRS output pulse, interrupt flag and DMA request set on falling edge (if
Kojto 98:8ab26030e058 154 * input capture edge = BOTH).
Kojto 98:8ab26030e058 155 */
Kojto 98:8ab26030e058 156 timerEventFalling = _TIMER_CC_CTRL_ICEVCTRL_FALLING
Kojto 98:8ab26030e058 157 } TIMER_Event_TypeDef;
Kojto 98:8ab26030e058 158
Kojto 98:8ab26030e058 159
Kojto 98:8ab26030e058 160 /** Input edge action. */
Kojto 98:8ab26030e058 161 typedef enum
Kojto 98:8ab26030e058 162 {
Kojto 98:8ab26030e058 163 /** No action taken. */
Kojto 98:8ab26030e058 164 timerInputActionNone = _TIMER_CTRL_FALLA_NONE,
Kojto 98:8ab26030e058 165
Kojto 98:8ab26030e058 166 /** Start counter without reload. */
Kojto 98:8ab26030e058 167 timerInputActionStart = _TIMER_CTRL_FALLA_START,
Kojto 98:8ab26030e058 168
Kojto 98:8ab26030e058 169 /** Stop counter without reload. */
Kojto 98:8ab26030e058 170 timerInputActionStop = _TIMER_CTRL_FALLA_STOP,
Kojto 98:8ab26030e058 171
Kojto 98:8ab26030e058 172 /** Reload and start counter. */
Kojto 98:8ab26030e058 173 timerInputActionReloadStart = _TIMER_CTRL_FALLA_RELOADSTART
Kojto 98:8ab26030e058 174 } TIMER_InputAction_TypeDef;
Kojto 98:8ab26030e058 175
Kojto 98:8ab26030e058 176
Kojto 98:8ab26030e058 177 /** Timer mode. */
Kojto 98:8ab26030e058 178 typedef enum
Kojto 98:8ab26030e058 179 {
Kojto 98:8ab26030e058 180 timerModeUp = _TIMER_CTRL_MODE_UP, /**< Up-counting. */
Kojto 98:8ab26030e058 181 timerModeDown = _TIMER_CTRL_MODE_DOWN, /**< Down-counting. */
Kojto 98:8ab26030e058 182 timerModeUpDown = _TIMER_CTRL_MODE_UPDOWN, /**< Up/down-counting. */
Kojto 98:8ab26030e058 183 timerModeQDec = _TIMER_CTRL_MODE_QDEC /**< Quadrature decoder. */
Kojto 98:8ab26030e058 184 } TIMER_Mode_TypeDef;
Kojto 98:8ab26030e058 185
Kojto 98:8ab26030e058 186
Kojto 98:8ab26030e058 187 /** Compare/capture output action. */
Kojto 98:8ab26030e058 188 typedef enum
Kojto 98:8ab26030e058 189 {
Kojto 98:8ab26030e058 190 /** No action. */
Kojto 98:8ab26030e058 191 timerOutputActionNone = _TIMER_CC_CTRL_CUFOA_NONE,
Kojto 98:8ab26030e058 192
Kojto 98:8ab26030e058 193 /** Toggle on event. */
Kojto 98:8ab26030e058 194 timerOutputActionToggle = _TIMER_CC_CTRL_CUFOA_TOGGLE,
Kojto 98:8ab26030e058 195
Kojto 98:8ab26030e058 196 /** Clear on event. */
Kojto 98:8ab26030e058 197 timerOutputActionClear = _TIMER_CC_CTRL_CUFOA_CLEAR,
Kojto 98:8ab26030e058 198
Kojto 98:8ab26030e058 199 /** Set on event. */
Kojto 98:8ab26030e058 200 timerOutputActionSet = _TIMER_CC_CTRL_CUFOA_SET
Kojto 98:8ab26030e058 201 } TIMER_OutputAction_TypeDef;
Kojto 98:8ab26030e058 202
Kojto 98:8ab26030e058 203
Kojto 98:8ab26030e058 204 /** Prescaler. */
Kojto 98:8ab26030e058 205 typedef enum
Kojto 98:8ab26030e058 206 {
Kojto 98:8ab26030e058 207 timerPrescale1 = _TIMER_CTRL_PRESC_DIV1, /**< Divide by 1. */
Kojto 98:8ab26030e058 208 timerPrescale2 = _TIMER_CTRL_PRESC_DIV2, /**< Divide by 2. */
Kojto 98:8ab26030e058 209 timerPrescale4 = _TIMER_CTRL_PRESC_DIV4, /**< Divide by 4. */
Kojto 98:8ab26030e058 210 timerPrescale8 = _TIMER_CTRL_PRESC_DIV8, /**< Divide by 8. */
Kojto 98:8ab26030e058 211 timerPrescale16 = _TIMER_CTRL_PRESC_DIV16, /**< Divide by 16. */
Kojto 98:8ab26030e058 212 timerPrescale32 = _TIMER_CTRL_PRESC_DIV32, /**< Divide by 32. */
Kojto 98:8ab26030e058 213 timerPrescale64 = _TIMER_CTRL_PRESC_DIV64, /**< Divide by 64. */
Kojto 98:8ab26030e058 214 timerPrescale128 = _TIMER_CTRL_PRESC_DIV128, /**< Divide by 128. */
Kojto 98:8ab26030e058 215 timerPrescale256 = _TIMER_CTRL_PRESC_DIV256, /**< Divide by 256. */
Kojto 98:8ab26030e058 216 timerPrescale512 = _TIMER_CTRL_PRESC_DIV512, /**< Divide by 512. */
Kojto 98:8ab26030e058 217 timerPrescale1024 = _TIMER_CTRL_PRESC_DIV1024 /**< Divide by 1024. */
Kojto 98:8ab26030e058 218 } TIMER_Prescale_TypeDef;
Kojto 98:8ab26030e058 219
Kojto 98:8ab26030e058 220
Kojto 98:8ab26030e058 221 /** Peripheral Reflex System signal. */
Kojto 98:8ab26030e058 222 typedef enum
Kojto 98:8ab26030e058 223 {
Kojto 98:8ab26030e058 224 timerPRSSELCh0 = _TIMER_CC_CTRL_PRSSEL_PRSCH0, /**< PRS channel 0. */
Kojto 98:8ab26030e058 225 timerPRSSELCh1 = _TIMER_CC_CTRL_PRSSEL_PRSCH1, /**< PRS channel 1. */
Kojto 98:8ab26030e058 226 timerPRSSELCh2 = _TIMER_CC_CTRL_PRSSEL_PRSCH2, /**< PRS channel 2. */
Kojto 98:8ab26030e058 227 timerPRSSELCh3 = _TIMER_CC_CTRL_PRSSEL_PRSCH3, /**< PRS channel 3. */
Kojto 113:f141b2784e32 228 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH4)
Kojto 98:8ab26030e058 229 timerPRSSELCh4 = _TIMER_CC_CTRL_PRSSEL_PRSCH4, /**< PRS channel 4. */
Kojto 98:8ab26030e058 230 #endif
Kojto 113:f141b2784e32 231 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH5)
Kojto 98:8ab26030e058 232 timerPRSSELCh5 = _TIMER_CC_CTRL_PRSSEL_PRSCH5, /**< PRS channel 5. */
Kojto 98:8ab26030e058 233 #endif
Kojto 113:f141b2784e32 234 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH6)
Kojto 98:8ab26030e058 235 timerPRSSELCh6 = _TIMER_CC_CTRL_PRSSEL_PRSCH6, /**< PRS channel 6. */
Kojto 98:8ab26030e058 236 #endif
Kojto 113:f141b2784e32 237 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH7)
Kojto 98:8ab26030e058 238 timerPRSSELCh7 = _TIMER_CC_CTRL_PRSSEL_PRSCH7, /**< PRS channel 7. */
Kojto 98:8ab26030e058 239 #endif
Kojto 113:f141b2784e32 240 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH8)
Kojto 98:8ab26030e058 241 timerPRSSELCh8 = _TIMER_CC_CTRL_PRSSEL_PRSCH8, /**< PRS channel 8. */
Kojto 98:8ab26030e058 242 #endif
Kojto 113:f141b2784e32 243 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH9)
Kojto 98:8ab26030e058 244 timerPRSSELCh9 = _TIMER_CC_CTRL_PRSSEL_PRSCH9, /**< PRS channel 9. */
Kojto 98:8ab26030e058 245 #endif
Kojto 113:f141b2784e32 246 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH10)
Kojto 98:8ab26030e058 247 timerPRSSELCh10 = _TIMER_CC_CTRL_PRSSEL_PRSCH10, /**< PRS channel 10. */
Kojto 98:8ab26030e058 248 #endif
Kojto 113:f141b2784e32 249 #if defined(_TIMER_CC_CTRL_PRSSEL_PRSCH11)
Kojto 98:8ab26030e058 250 timerPRSSELCh11 = _TIMER_CC_CTRL_PRSSEL_PRSCH11, /**< PRS channel 11. */
Kojto 98:8ab26030e058 251 #endif
Kojto 98:8ab26030e058 252 } TIMER_PRSSEL_TypeDef;
Kojto 98:8ab26030e058 253
Kojto 113:f141b2784e32 254 #if defined(_TIMER_DTFC_DTFA_NONE)
Kojto 98:8ab26030e058 255 /** DT (Dead Time) Fault Actions. */
Kojto 98:8ab26030e058 256 typedef enum
Kojto 98:8ab26030e058 257 {
Kojto 98:8ab26030e058 258 timerDtiFaultActionNone = _TIMER_DTFC_DTFA_NONE, /**< No action on fault. */
Kojto 98:8ab26030e058 259 timerDtiFaultActionInactive = _TIMER_DTFC_DTFA_INACTIVE, /**< Set outputs inactive. */
Kojto 98:8ab26030e058 260 timerDtiFaultActionClear = _TIMER_DTFC_DTFA_CLEAR, /**< Clear outputs. */
Kojto 98:8ab26030e058 261 timerDtiFaultActionTristate = _TIMER_DTFC_DTFA_TRISTATE /**< Tristate outputs. */
Kojto 98:8ab26030e058 262 } TIMER_DtiFaultAction_TypeDef;
Kojto 98:8ab26030e058 263 #endif
Kojto 98:8ab26030e058 264
Kojto 98:8ab26030e058 265 /*******************************************************************************
Kojto 98:8ab26030e058 266 ******************************* STRUCTS ***********************************
Kojto 98:8ab26030e058 267 ******************************************************************************/
Kojto 98:8ab26030e058 268
Kojto 98:8ab26030e058 269 /** TIMER initialization structure. */
Kojto 98:8ab26030e058 270 typedef struct
Kojto 98:8ab26030e058 271 {
Kojto 98:8ab26030e058 272 /** Start counting when init completed. */
Kojto 98:8ab26030e058 273 bool enable;
Kojto 98:8ab26030e058 274
Kojto 98:8ab26030e058 275 /** Counter shall keep running during debug halt. */
Kojto 98:8ab26030e058 276 bool debugRun;
Kojto 98:8ab26030e058 277
Kojto 98:8ab26030e058 278 /** Prescaling factor, if HFPER clock used. */
Kojto 98:8ab26030e058 279 TIMER_Prescale_TypeDef prescale;
Kojto 98:8ab26030e058 280
Kojto 98:8ab26030e058 281 /** Clock selection. */
Kojto 98:8ab26030e058 282 TIMER_ClkSel_TypeDef clkSel;
Kojto 98:8ab26030e058 283
Kojto 113:f141b2784e32 284 #if defined(TIMER_CTRL_X2CNT) && defined(TIMER_CTRL_ATI)
Kojto 98:8ab26030e058 285 /** 2x Count mode, counter increments/decrements by 2, meant for PWN mode. */
Kojto 98:8ab26030e058 286 bool count2x;
Kojto 98:8ab26030e058 287
Kojto 98:8ab26030e058 288 /** ATI (Always Track Inputs) makes CCPOL always track
Kojto 98:8ab26030e058 289 * the polarity of the inputs. */
Kojto 98:8ab26030e058 290 bool ati;
Kojto 98:8ab26030e058 291 #endif
Kojto 98:8ab26030e058 292
Kojto 98:8ab26030e058 293 /** Action on falling input edge. */
Kojto 98:8ab26030e058 294 TIMER_InputAction_TypeDef fallAction;
Kojto 98:8ab26030e058 295
Kojto 98:8ab26030e058 296 /** Action on rising input edge. */
Kojto 98:8ab26030e058 297 TIMER_InputAction_TypeDef riseAction;
Kojto 98:8ab26030e058 298
Kojto 98:8ab26030e058 299 /** Counting mode. */
Kojto 98:8ab26030e058 300 TIMER_Mode_TypeDef mode;
Kojto 98:8ab26030e058 301
Kojto 98:8ab26030e058 302 /** DMA request clear on active. */
Kojto 98:8ab26030e058 303 bool dmaClrAct;
Kojto 98:8ab26030e058 304
Kojto 98:8ab26030e058 305 /** Select X2 or X4 quadrature decode mode (if used). */
Kojto 98:8ab26030e058 306 bool quadModeX4;
Kojto 98:8ab26030e058 307
Kojto 98:8ab26030e058 308 /** Determines if only counting up or down once. */
Kojto 98:8ab26030e058 309 bool oneShot;
Kojto 98:8ab26030e058 310
Kojto 98:8ab26030e058 311 /** Timer start/stop/reload by other timers. */
Kojto 98:8ab26030e058 312 bool sync;
Kojto 98:8ab26030e058 313 } TIMER_Init_TypeDef;
Kojto 98:8ab26030e058 314
Kojto 98:8ab26030e058 315 /** Default config for TIMER init structure. */
Kojto 113:f141b2784e32 316 #if defined(TIMER_CTRL_X2CNT) && defined(TIMER_CTRL_ATI)
Kojto 113:f141b2784e32 317 #define TIMER_INIT_DEFAULT \
Kojto 113:f141b2784e32 318 { \
Kojto 113:f141b2784e32 319 true, /* Enable timer when init complete. */ \
Kojto 113:f141b2784e32 320 false, /* Stop counter during debug halt. */ \
Kojto 113:f141b2784e32 321 timerPrescale1, /* No prescaling. */ \
Kojto 113:f141b2784e32 322 timerClkSelHFPerClk, /* Select HFPER clock. */ \
Kojto 113:f141b2784e32 323 false, /* Not 2x count mode. */ \
Kojto 113:f141b2784e32 324 false, /* No ATI. */ \
Kojto 113:f141b2784e32 325 timerInputActionNone, /* No action on falling input edge. */ \
Kojto 113:f141b2784e32 326 timerInputActionNone, /* No action on rising input edge. */ \
Kojto 113:f141b2784e32 327 timerModeUp, /* Up-counting. */ \
Kojto 113:f141b2784e32 328 false, /* Do not clear DMA requests when DMA channel is active. */ \
Kojto 113:f141b2784e32 329 false, /* Select X2 quadrature decode mode (if used). */ \
Kojto 113:f141b2784e32 330 false, /* Disable one shot. */ \
Kojto 113:f141b2784e32 331 false /* Not started/stopped/reloaded by other timers. */ \
Kojto 113:f141b2784e32 332 }
Kojto 98:8ab26030e058 333 #else
Kojto 113:f141b2784e32 334 #define TIMER_INIT_DEFAULT \
Kojto 113:f141b2784e32 335 { \
Kojto 113:f141b2784e32 336 true, /* Enable timer when init complete. */ \
Kojto 113:f141b2784e32 337 false, /* Stop counter during debug halt. */ \
Kojto 113:f141b2784e32 338 timerPrescale1, /* No prescaling. */ \
Kojto 113:f141b2784e32 339 timerClkSelHFPerClk, /* Select HFPER clock. */ \
Kojto 113:f141b2784e32 340 timerInputActionNone, /* No action on falling input edge. */ \
Kojto 113:f141b2784e32 341 timerInputActionNone, /* No action on rising input edge. */ \
Kojto 113:f141b2784e32 342 timerModeUp, /* Up-counting. */ \
Kojto 113:f141b2784e32 343 false, /* Do not clear DMA requests when DMA channel is active. */ \
Kojto 113:f141b2784e32 344 false, /* Select X2 quadrature decode mode (if used). */ \
Kojto 113:f141b2784e32 345 false, /* Disable one shot. */ \
Kojto 113:f141b2784e32 346 false /* Not started/stopped/reloaded by other timers. */ \
Kojto 113:f141b2784e32 347 }
Kojto 98:8ab26030e058 348 #endif
Kojto 98:8ab26030e058 349
Kojto 98:8ab26030e058 350 /** TIMER compare/capture initialization structure. */
Kojto 98:8ab26030e058 351 typedef struct
Kojto 98:8ab26030e058 352 {
Kojto 98:8ab26030e058 353 /** Input capture event control. */
Kojto 98:8ab26030e058 354 TIMER_Event_TypeDef eventCtrl;
Kojto 98:8ab26030e058 355
Kojto 98:8ab26030e058 356 /** Input capture edge select. */
Kojto 98:8ab26030e058 357 TIMER_Edge_TypeDef edge;
Kojto 98:8ab26030e058 358
Kojto 98:8ab26030e058 359 /**
Kojto 98:8ab26030e058 360 * Peripheral reflex system trigger selection. Only applicable if @p prsInput
Kojto 98:8ab26030e058 361 * is enabled.
Kojto 98:8ab26030e058 362 */
Kojto 98:8ab26030e058 363 TIMER_PRSSEL_TypeDef prsSel;
Kojto 98:8ab26030e058 364
Kojto 98:8ab26030e058 365 /** Counter underflow output action. */
Kojto 98:8ab26030e058 366 TIMER_OutputAction_TypeDef cufoa;
Kojto 98:8ab26030e058 367
Kojto 98:8ab26030e058 368 /** Counter overflow output action. */
Kojto 98:8ab26030e058 369 TIMER_OutputAction_TypeDef cofoa;
Kojto 98:8ab26030e058 370
Kojto 98:8ab26030e058 371 /** Counter match output action. */
Kojto 98:8ab26030e058 372 TIMER_OutputAction_TypeDef cmoa;
Kojto 98:8ab26030e058 373
Kojto 98:8ab26030e058 374 /** Compare/capture channel mode. */
Kojto 98:8ab26030e058 375 TIMER_CCMode_TypeDef mode;
Kojto 98:8ab26030e058 376
Kojto 98:8ab26030e058 377 /** Enable digital filter. */
Kojto 98:8ab26030e058 378 bool filter;
Kojto 98:8ab26030e058 379
Kojto 98:8ab26030e058 380 /** Select TIMERnCCx (false) or PRS input (true). */
Kojto 98:8ab26030e058 381 bool prsInput;
Kojto 98:8ab26030e058 382
Kojto 98:8ab26030e058 383 /**
Kojto 98:8ab26030e058 384 * Compare output initial state. Only used in Output Compare and PWM mode.
Kojto 98:8ab26030e058 385 * When true, the compare/PWM output is set high when the counter is
Kojto 98:8ab26030e058 386 * disabled. When counting resumes, this value will represent the initial
Kojto 98:8ab26030e058 387 * value for the compare/PWM output. If the bit is cleared, the output
Kojto 98:8ab26030e058 388 * will be cleared when the counter is disabled.
Kojto 98:8ab26030e058 389 */
Kojto 98:8ab26030e058 390 bool coist;
Kojto 98:8ab26030e058 391
Kojto 98:8ab26030e058 392 /** Invert output from compare/capture channel. */
Kojto 98:8ab26030e058 393 bool outInvert;
Kojto 98:8ab26030e058 394 } TIMER_InitCC_TypeDef;
Kojto 98:8ab26030e058 395
Kojto 98:8ab26030e058 396 /** Default config for TIMER compare/capture init structure. */
Kojto 113:f141b2784e32 397 #define TIMER_INITCC_DEFAULT \
Kojto 113:f141b2784e32 398 { \
Kojto 113:f141b2784e32 399 timerEventEveryEdge, /* Event on every capture. */ \
Kojto 113:f141b2784e32 400 timerEdgeRising, /* Input capture edge on rising edge. */ \
Kojto 113:f141b2784e32 401 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
Kojto 113:f141b2784e32 402 timerOutputActionNone, /* No action on underflow. */ \
Kojto 113:f141b2784e32 403 timerOutputActionNone, /* No action on overflow. */ \
Kojto 113:f141b2784e32 404 timerOutputActionNone, /* No action on match. */ \
Kojto 113:f141b2784e32 405 timerCCModeOff, /* Disable compare/capture channel. */ \
Kojto 113:f141b2784e32 406 false, /* Disable filter. */ \
Kojto 113:f141b2784e32 407 false, /* Select TIMERnCCx input. */ \
Kojto 113:f141b2784e32 408 false, /* Clear output when counter disabled. */ \
Kojto 113:f141b2784e32 409 false /* Do not invert output. */ \
Kojto 113:f141b2784e32 410 }
Kojto 98:8ab26030e058 411
Kojto 113:f141b2784e32 412 #if defined(_TIMER_DTCTRL_MASK)
Kojto 98:8ab26030e058 413 /** TIMER Dead Time Insertion (DTI) initialization structure. */
Kojto 98:8ab26030e058 414 typedef struct
Kojto 98:8ab26030e058 415 {
Kojto 98:8ab26030e058 416 /** Enable DTI or leave it disabled until @ref TIMER_EnableDTI() is called */
Kojto 98:8ab26030e058 417 bool enable;
Kojto 98:8ab26030e058 418
Kojto 98:8ab26030e058 419 /** DTI Output Polarity */
Kojto 98:8ab26030e058 420 bool activeLowOut;
Kojto 98:8ab26030e058 421
Kojto 98:8ab26030e058 422 /** DTI Complementary Output Invert */
Kojto 98:8ab26030e058 423 bool invertComplementaryOut;
Kojto 98:8ab26030e058 424
Kojto 98:8ab26030e058 425 /** Enable Automatic Start-up functionality (when debugger exits) */
Kojto 98:8ab26030e058 426 bool autoRestart;
Kojto 98:8ab26030e058 427
Kojto 98:8ab26030e058 428 /** Enable/disable PRS as DTI input. */
Kojto 98:8ab26030e058 429 bool enablePrsSource;
Kojto 98:8ab26030e058 430
Kojto 98:8ab26030e058 431 /** Select which PRS channel as DTI input. Only valid if @p enablePrsSource
Kojto 98:8ab26030e058 432 is enabled. */
Kojto 98:8ab26030e058 433 TIMER_PRSSEL_TypeDef prsSel;
Kojto 98:8ab26030e058 434
Kojto 98:8ab26030e058 435 /** DTI prescaling factor, if HFPER clock used. */
Kojto 98:8ab26030e058 436 TIMER_Prescale_TypeDef prescale;
Kojto 98:8ab26030e058 437
Kojto 98:8ab26030e058 438 /** DTI Rise Time */
Kojto 98:8ab26030e058 439 unsigned int riseTime;
Kojto 98:8ab26030e058 440
Kojto 98:8ab26030e058 441 /** DTI Fall Time */
Kojto 98:8ab26030e058 442 unsigned int fallTime;
Kojto 98:8ab26030e058 443
Kojto 98:8ab26030e058 444 /** DTI outputs enable bit mask, consisting of one bit per DTI
Kojto 98:8ab26030e058 445 output signal, i.e. CC0, CC1, CC2, CDTI0, CDTI1 and CDTI2.
Kojto 98:8ab26030e058 446 This value should consist of one or more TIMER_DTOGEN_DTOGnnnEN flags
Kojto 98:8ab26030e058 447 (defined in \<part_name\>_timer.h) OR'ed together. */
Kojto 98:8ab26030e058 448 uint32_t outputsEnableMask;
Kojto 98:8ab26030e058 449
Kojto 98:8ab26030e058 450 /** Enable core lockup as a fault source. */
Kojto 98:8ab26030e058 451 bool enableFaultSourceCoreLockup;
Kojto 98:8ab26030e058 452
Kojto 98:8ab26030e058 453 /** Enable debugger as a fault source. */
Kojto 98:8ab26030e058 454 bool enableFaultSourceDebugger;
Kojto 98:8ab26030e058 455
Kojto 98:8ab26030e058 456 /** Enable PRS fault source 0 (@p faultSourcePrsSel0) */
Kojto 98:8ab26030e058 457 bool enableFaultSourcePrsSel0;
Kojto 98:8ab26030e058 458
Kojto 98:8ab26030e058 459 /** Select which PRS signal to be PRS fault source 0. */
Kojto 98:8ab26030e058 460 TIMER_PRSSEL_TypeDef faultSourcePrsSel0;
Kojto 98:8ab26030e058 461
Kojto 98:8ab26030e058 462 /** Enable PRS fault source 1 (@p faultSourcePrsSel1) */
Kojto 98:8ab26030e058 463 bool enableFaultSourcePrsSel1;
Kojto 98:8ab26030e058 464
Kojto 98:8ab26030e058 465 /** Select which PRS signal to be PRS fault source 1. */
Kojto 98:8ab26030e058 466 TIMER_PRSSEL_TypeDef faultSourcePrsSel1;
Kojto 98:8ab26030e058 467
Kojto 98:8ab26030e058 468 /** Fault Action */
Kojto 98:8ab26030e058 469 TIMER_DtiFaultAction_TypeDef faultAction;
Kojto 98:8ab26030e058 470
Kojto 98:8ab26030e058 471 } TIMER_InitDTI_TypeDef;
Kojto 98:8ab26030e058 472
Kojto 98:8ab26030e058 473
Kojto 98:8ab26030e058 474 /** Default config for TIMER DTI init structure. */
Kojto 113:f141b2784e32 475 #define TIMER_INITDTI_DEFAULT \
Kojto 113:f141b2784e32 476 { \
Kojto 113:f141b2784e32 477 true, /* Enable the DTI. */ \
Kojto 113:f141b2784e32 478 false, /* CC[0|1|2] outputs are active high. */ \
Kojto 113:f141b2784e32 479 false, /* CDTI[0|1|2] outputs are not inverted. */ \
Kojto 113:f141b2784e32 480 false, /* No auto restart when debugger exits. */ \
Kojto 113:f141b2784e32 481 false, /* No PRS source selected. */ \
Kojto 113:f141b2784e32 482 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
Kojto 113:f141b2784e32 483 timerPrescale1, /* No prescaling. */ \
Kojto 113:f141b2784e32 484 0, /* No rise time. */ \
Kojto 113:f141b2784e32 485 0, /* No fall time. */ \
Kojto 113:f141b2784e32 486 TIMER_DTOGEN_DTOGCC0EN|TIMER_DTOGEN_DTOGCDTI0EN, /* Enable CC0 and CDTI0 */\
Kojto 113:f141b2784e32 487 true, /* Enable core lockup as fault source */ \
Kojto 113:f141b2784e32 488 true, /* Enable debugger as fault source */ \
Kojto 113:f141b2784e32 489 false, /* Disable PRS fault source 0 */ \
Kojto 113:f141b2784e32 490 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
Kojto 113:f141b2784e32 491 false, /* Disable PRS fault source 1 */ \
Kojto 113:f141b2784e32 492 timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
Kojto 113:f141b2784e32 493 timerDtiFaultActionInactive, /* No fault action. */ \
Kojto 113:f141b2784e32 494 }
Kojto 98:8ab26030e058 495 #endif /* _TIMER_DTCTRL_MASK */
Kojto 98:8ab26030e058 496
Kojto 98:8ab26030e058 497
Kojto 98:8ab26030e058 498 /*******************************************************************************
Kojto 98:8ab26030e058 499 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 500 ******************************************************************************/
Kojto 98:8ab26030e058 501
Kojto 98:8ab26030e058 502 /***************************************************************************//**
Kojto 98:8ab26030e058 503 * @brief
Kojto 98:8ab26030e058 504 * Get capture value for compare/capture channel when operating in capture
Kojto 98:8ab26030e058 505 * mode.
Kojto 98:8ab26030e058 506 *
Kojto 98:8ab26030e058 507 * @param[in] timer
Kojto 98:8ab26030e058 508 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 509 *
Kojto 98:8ab26030e058 510 * @param[in] ch
Kojto 98:8ab26030e058 511 * Compare/capture channel to access.
Kojto 98:8ab26030e058 512 *
Kojto 98:8ab26030e058 513 * @return
Kojto 98:8ab26030e058 514 * Current capture value.
Kojto 98:8ab26030e058 515 ******************************************************************************/
Kojto 98:8ab26030e058 516 __STATIC_INLINE uint32_t TIMER_CaptureGet(TIMER_TypeDef *timer, unsigned int ch)
Kojto 98:8ab26030e058 517 {
Kojto 113:f141b2784e32 518 return timer->CC[ch].CCV;
Kojto 98:8ab26030e058 519 }
Kojto 98:8ab26030e058 520
Kojto 98:8ab26030e058 521
Kojto 98:8ab26030e058 522 /***************************************************************************//**
Kojto 98:8ab26030e058 523 * @brief
Kojto 98:8ab26030e058 524 * Set compare value buffer for compare/capture channel when operating in
Kojto 98:8ab26030e058 525 * compare or PWM mode.
Kojto 98:8ab26030e058 526 *
Kojto 98:8ab26030e058 527 * @details
Kojto 98:8ab26030e058 528 * The compare value buffer holds the value which will be written to
Kojto 98:8ab26030e058 529 * TIMERn_CCx_CCV on an update event if the buffer has been updated since
Kojto 98:8ab26030e058 530 * the last event.
Kojto 98:8ab26030e058 531 *
Kojto 98:8ab26030e058 532 * @param[in] timer
Kojto 98:8ab26030e058 533 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 534 *
Kojto 98:8ab26030e058 535 * @param[in] ch
Kojto 98:8ab26030e058 536 * Compare/capture channel to access.
Kojto 98:8ab26030e058 537 *
Kojto 98:8ab26030e058 538 * @param[in] val
Kojto 98:8ab26030e058 539 * Value to set in compare value buffer register.
Kojto 98:8ab26030e058 540 ******************************************************************************/
Kojto 98:8ab26030e058 541 __STATIC_INLINE void TIMER_CompareBufSet(TIMER_TypeDef *timer,
Kojto 98:8ab26030e058 542 unsigned int ch,
Kojto 98:8ab26030e058 543 uint32_t val)
Kojto 98:8ab26030e058 544 {
Kojto 98:8ab26030e058 545 timer->CC[ch].CCVB = val;
Kojto 98:8ab26030e058 546 }
Kojto 98:8ab26030e058 547
Kojto 98:8ab26030e058 548
Kojto 98:8ab26030e058 549 /***************************************************************************//**
Kojto 98:8ab26030e058 550 * @brief
Kojto 98:8ab26030e058 551 * Set compare value for compare/capture channel when operating in compare
Kojto 98:8ab26030e058 552 * or PWM mode.
Kojto 98:8ab26030e058 553 *
Kojto 98:8ab26030e058 554 * @param[in] timer
Kojto 98:8ab26030e058 555 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 556 *
Kojto 98:8ab26030e058 557 * @param[in] ch
Kojto 98:8ab26030e058 558 * Compare/capture channel to access.
Kojto 98:8ab26030e058 559 *
Kojto 98:8ab26030e058 560 * @param[in] val
Kojto 98:8ab26030e058 561 * Value to set in compare value register.
Kojto 98:8ab26030e058 562 ******************************************************************************/
Kojto 98:8ab26030e058 563 __STATIC_INLINE void TIMER_CompareSet(TIMER_TypeDef *timer,
Kojto 98:8ab26030e058 564 unsigned int ch,
Kojto 98:8ab26030e058 565 uint32_t val)
Kojto 98:8ab26030e058 566 {
Kojto 98:8ab26030e058 567 timer->CC[ch].CCV = val;
Kojto 98:8ab26030e058 568 }
Kojto 98:8ab26030e058 569
Kojto 98:8ab26030e058 570
Kojto 98:8ab26030e058 571 /***************************************************************************//**
Kojto 98:8ab26030e058 572 * @brief
Kojto 98:8ab26030e058 573 * Get TIMER counter value.
Kojto 98:8ab26030e058 574 *
Kojto 98:8ab26030e058 575 * @param[in] timer
Kojto 98:8ab26030e058 576 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 577 *
Kojto 98:8ab26030e058 578 * @return
Kojto 98:8ab26030e058 579 * Current TIMER counter value.
Kojto 98:8ab26030e058 580 ******************************************************************************/
Kojto 98:8ab26030e058 581 __STATIC_INLINE uint32_t TIMER_CounterGet(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 582 {
Kojto 113:f141b2784e32 583 return timer->CNT;
Kojto 98:8ab26030e058 584 }
Kojto 98:8ab26030e058 585
Kojto 98:8ab26030e058 586
Kojto 98:8ab26030e058 587 /***************************************************************************//**
Kojto 98:8ab26030e058 588 * @brief
Kojto 98:8ab26030e058 589 * Set TIMER counter value.
Kojto 98:8ab26030e058 590 *
Kojto 98:8ab26030e058 591 * @param[in] timer
Kojto 98:8ab26030e058 592 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 593 *
Kojto 98:8ab26030e058 594 * @param[in] val
Kojto 98:8ab26030e058 595 * Value to set counter to.
Kojto 98:8ab26030e058 596 ******************************************************************************/
Kojto 98:8ab26030e058 597 __STATIC_INLINE void TIMER_CounterSet(TIMER_TypeDef *timer, uint32_t val)
Kojto 98:8ab26030e058 598 {
Kojto 98:8ab26030e058 599 timer->CNT = val;
Kojto 98:8ab26030e058 600 }
Kojto 98:8ab26030e058 601
Kojto 98:8ab26030e058 602
Kojto 98:8ab26030e058 603 /***************************************************************************//**
Kojto 98:8ab26030e058 604 * @brief
Kojto 98:8ab26030e058 605 * Start/stop TIMER.
Kojto 98:8ab26030e058 606 *
Kojto 98:8ab26030e058 607 * @param[in] timer
Kojto 98:8ab26030e058 608 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 609 *
Kojto 98:8ab26030e058 610 * @param[in] enable
Kojto 98:8ab26030e058 611 * true to enable counting, false to disable.
Kojto 98:8ab26030e058 612 ******************************************************************************/
Kojto 98:8ab26030e058 613 __STATIC_INLINE void TIMER_Enable(TIMER_TypeDef *timer, bool enable)
Kojto 98:8ab26030e058 614 {
Kojto 98:8ab26030e058 615 EFM_ASSERT(TIMER_REF_VALID(timer));
Kojto 98:8ab26030e058 616
Kojto 98:8ab26030e058 617 if (enable)
Kojto 98:8ab26030e058 618 {
Kojto 98:8ab26030e058 619 timer->CMD = TIMER_CMD_START;
Kojto 98:8ab26030e058 620 }
Kojto 98:8ab26030e058 621 else
Kojto 98:8ab26030e058 622 {
Kojto 98:8ab26030e058 623 timer->CMD = TIMER_CMD_STOP;
Kojto 98:8ab26030e058 624 }
Kojto 98:8ab26030e058 625 }
Kojto 98:8ab26030e058 626
Kojto 98:8ab26030e058 627
Kojto 98:8ab26030e058 628 void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init);
Kojto 98:8ab26030e058 629 void TIMER_InitCC(TIMER_TypeDef *timer,
Kojto 98:8ab26030e058 630 unsigned int ch,
Kojto 98:8ab26030e058 631 const TIMER_InitCC_TypeDef *init);
Kojto 98:8ab26030e058 632
Kojto 113:f141b2784e32 633 #if defined(_TIMER_DTCTRL_MASK)
Kojto 98:8ab26030e058 634 void TIMER_InitDTI(TIMER_TypeDef *timer, const TIMER_InitDTI_TypeDef *init);
Kojto 98:8ab26030e058 635
Kojto 98:8ab26030e058 636 /***************************************************************************//**
Kojto 98:8ab26030e058 637 * @brief
Kojto 98:8ab26030e058 638 * Enable or disable DTI unit.
Kojto 98:8ab26030e058 639 *
Kojto 98:8ab26030e058 640 * @param[in] timer
Kojto 98:8ab26030e058 641 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 642 *
Kojto 98:8ab26030e058 643 * @param[in] enable
Kojto 98:8ab26030e058 644 * true to enable DTI unit, false to disable.
Kojto 98:8ab26030e058 645 ******************************************************************************/
Kojto 98:8ab26030e058 646 __STATIC_INLINE void TIMER_EnableDTI(TIMER_TypeDef *timer, bool enable)
Kojto 98:8ab26030e058 647 {
Kojto 98:8ab26030e058 648 EFM_ASSERT(TIMER0 == timer);
Kojto 98:8ab26030e058 649
Kojto 98:8ab26030e058 650 if (enable)
Kojto 98:8ab26030e058 651 {
Kojto 98:8ab26030e058 652 timer->DTCTRL |= TIMER_DTCTRL_DTEN;
Kojto 98:8ab26030e058 653 }
Kojto 98:8ab26030e058 654 else
Kojto 98:8ab26030e058 655 {
Kojto 98:8ab26030e058 656 timer->DTCTRL &= ~TIMER_DTCTRL_DTEN;
Kojto 98:8ab26030e058 657 }
Kojto 98:8ab26030e058 658 }
Kojto 98:8ab26030e058 659
Kojto 98:8ab26030e058 660
Kojto 98:8ab26030e058 661 /***************************************************************************//**
Kojto 98:8ab26030e058 662 * @brief
Kojto 98:8ab26030e058 663 * Get DTI fault source flags status.
Kojto 98:8ab26030e058 664 *
Kojto 98:8ab26030e058 665 * @note
Kojto 98:8ab26030e058 666 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 667 *
Kojto 98:8ab26030e058 668 * @param[in] timer
Kojto 98:8ab26030e058 669 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 670 *
Kojto 98:8ab26030e058 671 * @return
Kojto 98:8ab26030e058 672 * Status of the DTI fault source flags. Returns one or more valid
Kojto 98:8ab26030e058 673 * DTI fault source flags (TIMER_DTFAULT_nnn) OR'ed together.
Kojto 98:8ab26030e058 674 ******************************************************************************/
Kojto 98:8ab26030e058 675 __STATIC_INLINE uint32_t TIMER_GetDTIFault(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 676 {
Kojto 98:8ab26030e058 677 EFM_ASSERT(TIMER0 == timer);
Kojto 113:f141b2784e32 678 return timer->DTFAULT;
Kojto 98:8ab26030e058 679 }
Kojto 98:8ab26030e058 680
Kojto 98:8ab26030e058 681
Kojto 98:8ab26030e058 682 /***************************************************************************//**
Kojto 98:8ab26030e058 683 * @brief
Kojto 98:8ab26030e058 684 * Clear DTI fault source flags.
Kojto 98:8ab26030e058 685 *
Kojto 98:8ab26030e058 686 * @param[in] timer
Kojto 98:8ab26030e058 687 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 688 *
Kojto 98:8ab26030e058 689 * @param[in] flags
Kojto 98:8ab26030e058 690 * DTI fault source(s) to clear. Use one or more valid DTI fault
Kojto 98:8ab26030e058 691 * source flags (TIMER_DTFAULT_nnn) OR'ed together.
Kojto 98:8ab26030e058 692 ******************************************************************************/
Kojto 98:8ab26030e058 693 __STATIC_INLINE void TIMER_ClearDTIFault(TIMER_TypeDef *timer, uint32_t flags)
Kojto 98:8ab26030e058 694
Kojto 98:8ab26030e058 695 {
Kojto 98:8ab26030e058 696 EFM_ASSERT(TIMER0 == timer);
Kojto 98:8ab26030e058 697 timer->DTFAULTC = flags;
Kojto 98:8ab26030e058 698 }
Kojto 98:8ab26030e058 699 #endif /* _TIMER_DTCTRL_MASK */
Kojto 98:8ab26030e058 700
Kojto 98:8ab26030e058 701
Kojto 98:8ab26030e058 702 /***************************************************************************//**
Kojto 98:8ab26030e058 703 * @brief
Kojto 98:8ab26030e058 704 * Clear one or more pending TIMER interrupts.
Kojto 98:8ab26030e058 705 *
Kojto 98:8ab26030e058 706 * @param[in] timer
Kojto 98:8ab26030e058 707 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 708 *
Kojto 98:8ab26030e058 709 * @param[in] flags
Kojto 98:8ab26030e058 710 * Pending TIMER interrupt source(s) to clear. Use one or more valid
Kojto 98:8ab26030e058 711 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 712 ******************************************************************************/
Kojto 98:8ab26030e058 713 __STATIC_INLINE void TIMER_IntClear(TIMER_TypeDef *timer, uint32_t flags)
Kojto 98:8ab26030e058 714 {
Kojto 98:8ab26030e058 715 timer->IFC = flags;
Kojto 98:8ab26030e058 716 }
Kojto 98:8ab26030e058 717
Kojto 98:8ab26030e058 718
Kojto 98:8ab26030e058 719 /***************************************************************************//**
Kojto 98:8ab26030e058 720 * @brief
Kojto 98:8ab26030e058 721 * Disable one or more TIMER interrupts.
Kojto 98:8ab26030e058 722 *
Kojto 98:8ab26030e058 723 * @param[in] timer
Kojto 98:8ab26030e058 724 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 725 *
Kojto 98:8ab26030e058 726 * @param[in] flags
Kojto 98:8ab26030e058 727 * TIMER interrupt source(s) to disable. Use one or more valid
Kojto 98:8ab26030e058 728 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 729 ******************************************************************************/
Kojto 98:8ab26030e058 730 __STATIC_INLINE void TIMER_IntDisable(TIMER_TypeDef *timer, uint32_t flags)
Kojto 98:8ab26030e058 731 {
Kojto 113:f141b2784e32 732 timer->IEN &= ~flags;
Kojto 98:8ab26030e058 733 }
Kojto 98:8ab26030e058 734
Kojto 98:8ab26030e058 735
Kojto 98:8ab26030e058 736 /***************************************************************************//**
Kojto 98:8ab26030e058 737 * @brief
Kojto 98:8ab26030e058 738 * Enable one or more TIMER interrupts.
Kojto 98:8ab26030e058 739 *
Kojto 98:8ab26030e058 740 * @note
Kojto 98:8ab26030e058 741 * Depending on the use, a pending interrupt may already be set prior to
Kojto 98:8ab26030e058 742 * enabling the interrupt. Consider using TIMER_IntClear() prior to enabling
Kojto 98:8ab26030e058 743 * if such a pending interrupt should be ignored.
Kojto 98:8ab26030e058 744 *
Kojto 98:8ab26030e058 745 * @param[in] timer
Kojto 98:8ab26030e058 746 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 747 *
Kojto 98:8ab26030e058 748 * @param[in] flags
Kojto 98:8ab26030e058 749 * TIMER interrupt source(s) to enable. Use one or more valid
Kojto 98:8ab26030e058 750 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 751 ******************************************************************************/
Kojto 98:8ab26030e058 752 __STATIC_INLINE void TIMER_IntEnable(TIMER_TypeDef *timer, uint32_t flags)
Kojto 98:8ab26030e058 753 {
Kojto 98:8ab26030e058 754 timer->IEN |= flags;
Kojto 98:8ab26030e058 755 }
Kojto 98:8ab26030e058 756
Kojto 98:8ab26030e058 757
Kojto 98:8ab26030e058 758 /***************************************************************************//**
Kojto 98:8ab26030e058 759 * @brief
Kojto 98:8ab26030e058 760 * Get pending TIMER interrupt flags.
Kojto 98:8ab26030e058 761 *
Kojto 98:8ab26030e058 762 * @note
Kojto 98:8ab26030e058 763 * The event bits are not cleared by the use of this function.
Kojto 98:8ab26030e058 764 *
Kojto 98:8ab26030e058 765 * @param[in] timer
Kojto 98:8ab26030e058 766 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 767 *
Kojto 98:8ab26030e058 768 * @return
Kojto 98:8ab26030e058 769 * TIMER interrupt source(s) pending. Returns one or more valid
Kojto 98:8ab26030e058 770 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 771 ******************************************************************************/
Kojto 98:8ab26030e058 772 __STATIC_INLINE uint32_t TIMER_IntGet(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 773 {
Kojto 113:f141b2784e32 774 return timer->IF;
Kojto 98:8ab26030e058 775 }
Kojto 98:8ab26030e058 776
Kojto 98:8ab26030e058 777
Kojto 98:8ab26030e058 778 /***************************************************************************//**
Kojto 98:8ab26030e058 779 * @brief
Kojto 98:8ab26030e058 780 * Get enabled and pending TIMER interrupt flags.
Kojto 98:8ab26030e058 781 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 98:8ab26030e058 782 *
Kojto 98:8ab26030e058 783 * @param[in] timer
Kojto 98:8ab26030e058 784 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 785 *
Kojto 98:8ab26030e058 786 * @note
Kojto 98:8ab26030e058 787 * Interrupt flags are not cleared by the use of this function.
Kojto 98:8ab26030e058 788 *
Kojto 98:8ab26030e058 789 * @return
Kojto 98:8ab26030e058 790 * Pending and enabled TIMER interrupt sources.
Kojto 98:8ab26030e058 791 * The return value is the bitwise AND combination of
Kojto 98:8ab26030e058 792 * - the OR combination of enabled interrupt sources in TIMERx_IEN_nnn
Kojto 98:8ab26030e058 793 * register (TIMERx_IEN_nnn) and
Kojto 98:8ab26030e058 794 * - the OR combination of valid interrupt flags of the TIMER module
Kojto 98:8ab26030e058 795 * (TIMERx_IF_nnn).
Kojto 98:8ab26030e058 796 ******************************************************************************/
Kojto 98:8ab26030e058 797 __STATIC_INLINE uint32_t TIMER_IntGetEnabled(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 798 {
Kojto 113:f141b2784e32 799 uint32_t ien;
Kojto 98:8ab26030e058 800
Kojto 98:8ab26030e058 801 /* Store TIMER->IEN in temporary variable in order to define explicit order
Kojto 98:8ab26030e058 802 * of volatile accesses. */
Kojto 113:f141b2784e32 803 ien = timer->IEN;
Kojto 98:8ab26030e058 804
Kojto 98:8ab26030e058 805 /* Bitwise AND of pending and enabled interrupts */
Kojto 113:f141b2784e32 806 return timer->IF & ien;
Kojto 98:8ab26030e058 807 }
Kojto 98:8ab26030e058 808
Kojto 98:8ab26030e058 809
Kojto 98:8ab26030e058 810 /***************************************************************************//**
Kojto 98:8ab26030e058 811 * @brief
Kojto 98:8ab26030e058 812 * Set one or more pending TIMER interrupts from SW.
Kojto 98:8ab26030e058 813 *
Kojto 98:8ab26030e058 814 * @param[in] timer
Kojto 98:8ab26030e058 815 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 816 *
Kojto 98:8ab26030e058 817 * @param[in] flags
Kojto 98:8ab26030e058 818 * TIMER interrupt source(s) to set to pending. Use one or more valid
Kojto 98:8ab26030e058 819 * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
Kojto 98:8ab26030e058 820 ******************************************************************************/
Kojto 98:8ab26030e058 821 __STATIC_INLINE void TIMER_IntSet(TIMER_TypeDef *timer, uint32_t flags)
Kojto 98:8ab26030e058 822 {
Kojto 98:8ab26030e058 823 timer->IFS = flags;
Kojto 98:8ab26030e058 824 }
Kojto 98:8ab26030e058 825
Kojto 113:f141b2784e32 826 #if defined(_TIMER_DTLOCK_LOCKKEY_LOCK)
Kojto 98:8ab26030e058 827 /***************************************************************************//**
Kojto 98:8ab26030e058 828 * @brief
Kojto 98:8ab26030e058 829 * Lock some of the TIMER registers in order to protect them from being
Kojto 98:8ab26030e058 830 * modified.
Kojto 98:8ab26030e058 831 *
Kojto 98:8ab26030e058 832 * @details
Kojto 98:8ab26030e058 833 * Please refer to the reference manual for TIMER registers that will be
Kojto 98:8ab26030e058 834 * locked.
Kojto 98:8ab26030e058 835 *
Kojto 98:8ab26030e058 836 * @note
Kojto 98:8ab26030e058 837 * If locking the TIMER registers, they must be unlocked prior to using any
Kojto 98:8ab26030e058 838 * TIMER API functions modifying TIMER registers protected by the lock.
Kojto 98:8ab26030e058 839 *
Kojto 98:8ab26030e058 840 * @param[in] timer
Kojto 98:8ab26030e058 841 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 842 ******************************************************************************/
Kojto 98:8ab26030e058 843 __STATIC_INLINE void TIMER_Lock(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 844 {
Kojto 98:8ab26030e058 845 EFM_ASSERT(TIMER0 == timer);
Kojto 98:8ab26030e058 846
Kojto 98:8ab26030e058 847 timer->DTLOCK = TIMER_DTLOCK_LOCKKEY_LOCK;
Kojto 98:8ab26030e058 848 }
Kojto 98:8ab26030e058 849 #endif
Kojto 98:8ab26030e058 850
Kojto 98:8ab26030e058 851 void TIMER_Reset(TIMER_TypeDef *timer);
Kojto 98:8ab26030e058 852
Kojto 98:8ab26030e058 853 /***************************************************************************//**
Kojto 98:8ab26030e058 854 * @brief
Kojto 98:8ab26030e058 855 * Set top value buffer for timer.
Kojto 98:8ab26030e058 856 *
Kojto 98:8ab26030e058 857 * @details
Kojto 98:8ab26030e058 858 * When the top value buffer register is updated, the value is loaded into
Kojto 98:8ab26030e058 859 * the top value register at the next wrap around. This feature is useful
Kojto 98:8ab26030e058 860 * in order to update the top value safely when the timer is running.
Kojto 98:8ab26030e058 861 *
Kojto 98:8ab26030e058 862 * @param[in] timer
Kojto 98:8ab26030e058 863 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 864 *
Kojto 98:8ab26030e058 865 * @param[in] val
Kojto 98:8ab26030e058 866 * Value to set in top value buffer register.
Kojto 98:8ab26030e058 867 ******************************************************************************/
Kojto 98:8ab26030e058 868 __STATIC_INLINE void TIMER_TopBufSet(TIMER_TypeDef *timer, uint32_t val)
Kojto 98:8ab26030e058 869 {
Kojto 98:8ab26030e058 870 timer->TOPB = val;
Kojto 98:8ab26030e058 871 }
Kojto 98:8ab26030e058 872
Kojto 98:8ab26030e058 873
Kojto 98:8ab26030e058 874 /***************************************************************************//**
Kojto 98:8ab26030e058 875 * @brief
Kojto 98:8ab26030e058 876 * Get top value setting for timer.
Kojto 98:8ab26030e058 877 *
Kojto 98:8ab26030e058 878 * @param[in] timer
Kojto 98:8ab26030e058 879 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 880 *
Kojto 98:8ab26030e058 881 * @return
Kojto 98:8ab26030e058 882 * Current top value.
Kojto 98:8ab26030e058 883 ******************************************************************************/
Kojto 98:8ab26030e058 884 __STATIC_INLINE uint32_t TIMER_TopGet(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 885 {
Kojto 113:f141b2784e32 886 return timer->TOP;
Kojto 98:8ab26030e058 887 }
Kojto 98:8ab26030e058 888
Kojto 98:8ab26030e058 889
Kojto 98:8ab26030e058 890 /***************************************************************************//**
Kojto 98:8ab26030e058 891 * @brief
Kojto 98:8ab26030e058 892 * Set top value for timer.
Kojto 98:8ab26030e058 893 *
Kojto 98:8ab26030e058 894 * @param[in] timer
Kojto 98:8ab26030e058 895 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 896 *
Kojto 98:8ab26030e058 897 * @param[in] val
Kojto 98:8ab26030e058 898 * Value to set in top value register.
Kojto 98:8ab26030e058 899 ******************************************************************************/
Kojto 98:8ab26030e058 900 __STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
Kojto 98:8ab26030e058 901 {
Kojto 98:8ab26030e058 902 timer->TOP = val;
Kojto 98:8ab26030e058 903 }
Kojto 98:8ab26030e058 904
Kojto 98:8ab26030e058 905
Kojto 113:f141b2784e32 906 #if defined(TIMER_DTLOCK_LOCKKEY_UNLOCK)
Kojto 98:8ab26030e058 907 /***************************************************************************//**
Kojto 98:8ab26030e058 908 * @brief
Kojto 98:8ab26030e058 909 * Unlock the TIMER so that writing to locked registers again is possible.
Kojto 98:8ab26030e058 910 *
Kojto 98:8ab26030e058 911 * @param[in] timer
Kojto 98:8ab26030e058 912 * Pointer to TIMER peripheral register block.
Kojto 98:8ab26030e058 913 ******************************************************************************/
Kojto 98:8ab26030e058 914 __STATIC_INLINE void TIMER_Unlock(TIMER_TypeDef *timer)
Kojto 98:8ab26030e058 915 {
Kojto 98:8ab26030e058 916 EFM_ASSERT(TIMER0 == timer);
Kojto 98:8ab26030e058 917
Kojto 98:8ab26030e058 918 timer->DTLOCK = TIMER_DTLOCK_LOCKKEY_UNLOCK;
Kojto 98:8ab26030e058 919 }
Kojto 98:8ab26030e058 920 #endif
Kojto 98:8ab26030e058 921
Kojto 98:8ab26030e058 922
Kojto 98:8ab26030e058 923 /** @} (end addtogroup TIMER) */
Kojto 98:8ab26030e058 924 /** @} (end addtogroup EM_Library) */
Kojto 98:8ab26030e058 925
Kojto 98:8ab26030e058 926 #ifdef __cplusplus
Kojto 98:8ab26030e058 927 }
Kojto 98:8ab26030e058 928 #endif
Kojto 98:8ab26030e058 929
Kojto 98:8ab26030e058 930 #endif /* defined(TIMER_COUNT) && (TIMER_COUNT > 0) */
Kojto 113:f141b2784e32 931 #endif /* __SILICON_LABS_EM_TIMER_H__ */