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:
<>
Date:
Thu Mar 30 13:26:47 2017 +0100
Revision:
139:856d2700e60b
Parent:
128:9bcdf88f62b0
Release 139 of the mbed library

Ports for Upcoming Targets

3934: [Silicon Labs] Update to HAL and devices https://github.com/ARMmbed/mbed-os/pull/3934

Known Issues

There is an issue with LPC1768 failing the 'Semihost file system' test with this release.

Fixes and Changes

3691: [TLS / hw acceleration] AES ECB for NUCLEO_F439ZI https://github.com/ARMmbed/mbed-os/pull/3691
3869: NCS36510: Default range changed from 0 to 950mV - ADC https://github.com/ARMmbed/mbed-os/pull/3869
3893: [STM32F7] Update STM32 Cube version v1.6.0 https://github.com/ARMmbed/mbed-os/pull/3893
3917: Fix mistake register setting in serial_format() https://github.com/ARMmbed/mbed-os/pull/3917
3927: [DELTA_DFBM_NQ620] Add RC calibration setting and revise mbed_overrides.c https://github.com/ARMmbed/mbed-os/pull/3927
3918: [NUC472/M453] Support unique locally administered MAC address and other driver updates https://github.com/ARMmbed/mbed-os/pull/3918
3920: Heap size adjusted to work for both tls-client and mbed-client https://github.com/ARMmbed/mbed-os/pull/3920
3969: NUCLEO_F302R8: Add missing PB_8/PB_9 CAN pins https://github.com/ARMmbed/mbed-os/pull/3969

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