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.
TARGET_EFM32HG_STK3400/TARGET_Silicon_Labs/TARGET_EFM32/emlib/inc/em_pcnt.h@128:9bcdf88f62b0, 2016-10-27 (annotated)
- Committer:
- <>
- Date:
- Thu Oct 27 16:45:56 2016 +0100
- Revision:
- 128:9bcdf88f62b0
- Parent:
- 113:f141b2784e32
- Child:
- 139:856d2700e60b
Release 128 of the mbed library
Ports for Upcoming Targets
Fixes and Changes
2966: Add kw24 support https://github.com/ARMmbed/mbed-os/pull/2966
3068: MultiTech mDot - clean up PeripheralPins.c and add new pin names https://github.com/ARMmbed/mbed-os/pull/3068
3089: Kinetis HAL: Remove clock initialization code from serial and ticker https://github.com/ARMmbed/mbed-os/pull/3089
2943: [NRF5] NVIC_SetVector functionality https://github.com/ARMmbed/mbed-os/pull/2943
2938: InterruptIn changes in NCS36510 HAL. https://github.com/ARMmbed/mbed-os/pull/2938
3108: Fix sleep function for NRF52. https://github.com/ARMmbed/mbed-os/pull/3108
3076: STM32F1: Correct timer master value reading https://github.com/ARMmbed/mbed-os/pull/3076
3085: Add LOWPOWERTIMER capability for NUCLEO_F303ZE https://github.com/ARMmbed/mbed-os/pull/3085
3046: [BEETLE] Update BLE stack on Beetle board https://github.com/ARMmbed/mbed-os/pull/3046
3122: [Silicon Labs] Update of Silicon Labs HAL https://github.com/ARMmbed/mbed-os/pull/3122
3022: OnSemi RAM usage fix https://github.com/ARMmbed/mbed-os/pull/3022
3121: STM32F3: Correct UART4 and UART5 defines when using DEVICE_SERIAL_ASYNCH https://github.com/ARMmbed/mbed-os/pull/3121
3142: Targets- NUMAKER_PFM_NUC47216 remove mbed 2 https://github.com/ARMmbed/mbed-os/pull/3142
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 98:8ab26030e058 | 1 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 2 | * @file em_pcnt.h |
Kojto | 98:8ab26030e058 | 3 | * @brief Pulse Counter (PCNT) peripheral API |
<> | 128:9bcdf88f62b0 | 4 | * @version 5.0.0 |
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_PCNT_H |
<> | 128:9bcdf88f62b0 | 34 | #define EM_PCNT_H |
Kojto | 98:8ab26030e058 | 35 | |
Kojto | 98:8ab26030e058 | 36 | #include "em_device.h" |
Kojto | 98:8ab26030e058 | 37 | #if defined(PCNT_COUNT) && (PCNT_COUNT > 0) |
Kojto | 98:8ab26030e058 | 38 | |
Kojto | 98:8ab26030e058 | 39 | #include <stdbool.h> |
Kojto | 98:8ab26030e058 | 40 | |
Kojto | 98:8ab26030e058 | 41 | #ifdef __cplusplus |
Kojto | 98:8ab26030e058 | 42 | extern "C" { |
Kojto | 98:8ab26030e058 | 43 | #endif |
Kojto | 98:8ab26030e058 | 44 | |
Kojto | 98:8ab26030e058 | 45 | /***************************************************************************//** |
<> | 128:9bcdf88f62b0 | 46 | * @addtogroup emlib |
Kojto | 98:8ab26030e058 | 47 | * @{ |
Kojto | 98:8ab26030e058 | 48 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 49 | |
Kojto | 98:8ab26030e058 | 50 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 51 | * @addtogroup PCNT |
Kojto | 98:8ab26030e058 | 52 | * @{ |
Kojto | 98:8ab26030e058 | 53 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 54 | |
Kojto | 98:8ab26030e058 | 55 | /******************************************************************************* |
Kojto | 98:8ab26030e058 | 56 | ******************************* DEFINES *********************************** |
Kojto | 98:8ab26030e058 | 57 | ******************************************************************************/ |
Kojto | 113:f141b2784e32 | 58 | /** PCNT0 Counter register size. */ |
Kojto | 113:f141b2784e32 | 59 | #if defined(_EFM32_GECKO_FAMILY) |
Kojto | 113:f141b2784e32 | 60 | #define PCNT0_CNT_SIZE (8) /* PCNT0 counter is 8 bits. */ |
Kojto | 98:8ab26030e058 | 61 | #else |
Kojto | 113:f141b2784e32 | 62 | #define PCNT0_CNT_SIZE (16) /* PCNT0 counter is 16 bits. */ |
Kojto | 98:8ab26030e058 | 63 | #endif |
Kojto | 113:f141b2784e32 | 64 | |
Kojto | 98:8ab26030e058 | 65 | #ifdef PCNT1 |
Kojto | 113:f141b2784e32 | 66 | /** PCNT1 Counter register size. */ |
Kojto | 113:f141b2784e32 | 67 | #define PCNT1_CNT_SIZE (8) /* PCNT1 counter is 8 bits. */ |
Kojto | 98:8ab26030e058 | 68 | #endif |
Kojto | 113:f141b2784e32 | 69 | |
Kojto | 98:8ab26030e058 | 70 | #ifdef PCNT2 |
Kojto | 113:f141b2784e32 | 71 | /** PCNT2 Counter register size. */ |
Kojto | 113:f141b2784e32 | 72 | #define PCNT2_CNT_SIZE (8) /* PCNT2 counter is 8 bits. */ |
Kojto | 98:8ab26030e058 | 73 | #endif |
Kojto | 98:8ab26030e058 | 74 | |
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 | /** Mode selection. */ |
Kojto | 98:8ab26030e058 | 81 | typedef enum |
Kojto | 98:8ab26030e058 | 82 | { |
Kojto | 98:8ab26030e058 | 83 | /** Disable pulse counter. */ |
Kojto | 98:8ab26030e058 | 84 | pcntModeDisable = _PCNT_CTRL_MODE_DISABLE, |
Kojto | 98:8ab26030e058 | 85 | |
Kojto | 98:8ab26030e058 | 86 | /** Single input LFACLK oversampling mode (available in EM0-EM2). */ |
Kojto | 98:8ab26030e058 | 87 | pcntModeOvsSingle = _PCNT_CTRL_MODE_OVSSINGLE, |
Kojto | 98:8ab26030e058 | 88 | |
Kojto | 98:8ab26030e058 | 89 | /** Externally clocked single input counter mode (available in EM0-EM3). */ |
Kojto | 98:8ab26030e058 | 90 | pcntModeExtSingle = _PCNT_CTRL_MODE_EXTCLKSINGLE, |
Kojto | 98:8ab26030e058 | 91 | |
Kojto | 98:8ab26030e058 | 92 | /** Externally clocked quadrature decoder mode (available in EM0-EM3). */ |
Kojto | 113:f141b2784e32 | 93 | pcntModeExtQuad = _PCNT_CTRL_MODE_EXTCLKQUAD, |
<> | 128:9bcdf88f62b0 | 94 | |
Kojto | 113:f141b2784e32 | 95 | #if defined(_PCNT_CTRL_MODE_OVSQUAD1X) |
Kojto | 113:f141b2784e32 | 96 | /** LFACLK oversampling quadrature decoder 1X mode (available in EM0-EM2). */ |
Kojto | 113:f141b2784e32 | 97 | pcntModeOvsQuad1 = _PCNT_CTRL_MODE_OVSQUAD1X, |
<> | 128:9bcdf88f62b0 | 98 | |
Kojto | 113:f141b2784e32 | 99 | /** LFACLK oversampling quadrature decoder 2X mode (available in EM0-EM2). */ |
Kojto | 113:f141b2784e32 | 100 | pcntModeOvsQuad2 = _PCNT_CTRL_MODE_OVSQUAD2X, |
<> | 128:9bcdf88f62b0 | 101 | |
Kojto | 113:f141b2784e32 | 102 | /** LFACLK oversampling quadrature decoder 4X mode (available in EM0-EM2). */ |
Kojto | 113:f141b2784e32 | 103 | pcntModeOvsQuad4 = _PCNT_CTRL_MODE_OVSQUAD4X, |
Kojto | 113:f141b2784e32 | 104 | #endif |
Kojto | 98:8ab26030e058 | 105 | } PCNT_Mode_TypeDef; |
Kojto | 98:8ab26030e058 | 106 | |
Kojto | 98:8ab26030e058 | 107 | |
Kojto | 113:f141b2784e32 | 108 | #if defined(_PCNT_CTRL_CNTEV_MASK) |
Kojto | 98:8ab26030e058 | 109 | /** Counter event selection. |
Kojto | 98:8ab26030e058 | 110 | * Note: unshifted values are being used for enumeration because multiple |
Kojto | 98:8ab26030e058 | 111 | * configuration structure members use this type definition. */ |
Kojto | 98:8ab26030e058 | 112 | typedef enum |
Kojto | 98:8ab26030e058 | 113 | { |
Kojto | 98:8ab26030e058 | 114 | /** Counts up on up-count and down on down-count events. */ |
Kojto | 98:8ab26030e058 | 115 | pcntCntEventBoth = _PCNT_CTRL_CNTEV_BOTH, |
Kojto | 98:8ab26030e058 | 116 | |
Kojto | 98:8ab26030e058 | 117 | /** Only counts up on up-count events. */ |
Kojto | 98:8ab26030e058 | 118 | pcntCntEventUp = _PCNT_CTRL_CNTEV_UP, |
Kojto | 98:8ab26030e058 | 119 | |
Kojto | 98:8ab26030e058 | 120 | /** Only counts down on down-count events. */ |
Kojto | 98:8ab26030e058 | 121 | pcntCntEventDown = _PCNT_CTRL_CNTEV_DOWN, |
Kojto | 98:8ab26030e058 | 122 | |
Kojto | 98:8ab26030e058 | 123 | /** Never counts. */ |
Kojto | 98:8ab26030e058 | 124 | pcntCntEventNone = _PCNT_CTRL_CNTEV_NONE |
Kojto | 98:8ab26030e058 | 125 | } PCNT_CntEvent_TypeDef; |
Kojto | 98:8ab26030e058 | 126 | #endif |
Kojto | 98:8ab26030e058 | 127 | |
Kojto | 98:8ab26030e058 | 128 | |
Kojto | 113:f141b2784e32 | 129 | #if defined(_PCNT_INPUT_MASK) |
Kojto | 98:8ab26030e058 | 130 | /** PRS sources for @p s0PRS and @p s1PRS. */ |
Kojto | 98:8ab26030e058 | 131 | typedef enum |
Kojto | 98:8ab26030e058 | 132 | { |
Kojto | 98:8ab26030e058 | 133 | pcntPRSCh0 = 0, /**< PRS channel 0. */ |
Kojto | 98:8ab26030e058 | 134 | pcntPRSCh1 = 1, /**< PRS channel 1. */ |
Kojto | 98:8ab26030e058 | 135 | pcntPRSCh2 = 2, /**< PRS channel 2. */ |
Kojto | 98:8ab26030e058 | 136 | pcntPRSCh3 = 3, /**< PRS channel 3. */ |
Kojto | 113:f141b2784e32 | 137 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH4) |
Kojto | 98:8ab26030e058 | 138 | pcntPRSCh4 = 4, /**< PRS channel 4. */ |
Kojto | 98:8ab26030e058 | 139 | #endif |
Kojto | 113:f141b2784e32 | 140 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH5) |
Kojto | 98:8ab26030e058 | 141 | pcntPRSCh5 = 5, /**< PRS channel 5. */ |
Kojto | 98:8ab26030e058 | 142 | #endif |
Kojto | 113:f141b2784e32 | 143 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH6) |
Kojto | 98:8ab26030e058 | 144 | pcntPRSCh6 = 6, /**< PRS channel 6. */ |
Kojto | 98:8ab26030e058 | 145 | #endif |
Kojto | 113:f141b2784e32 | 146 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH7) |
Kojto | 98:8ab26030e058 | 147 | pcntPRSCh7 = 7, /**< PRS channel 7. */ |
Kojto | 98:8ab26030e058 | 148 | #endif |
Kojto | 113:f141b2784e32 | 149 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH8) |
Kojto | 98:8ab26030e058 | 150 | pcntPRSCh8 = 8, /**< PRS channel 8. */ |
Kojto | 98:8ab26030e058 | 151 | #endif |
Kojto | 113:f141b2784e32 | 152 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH9) |
Kojto | 98:8ab26030e058 | 153 | pcntPRSCh9 = 9, /**< PRS channel 9. */ |
Kojto | 98:8ab26030e058 | 154 | #endif |
Kojto | 113:f141b2784e32 | 155 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH10) |
Kojto | 98:8ab26030e058 | 156 | pcntPRSCh10 = 10, /**< PRS channel 10. */ |
Kojto | 98:8ab26030e058 | 157 | #endif |
Kojto | 113:f141b2784e32 | 158 | #if defined(PCNT_INPUT_S0PRSSEL_PRSCH11) |
Kojto | 98:8ab26030e058 | 159 | pcntPRSCh11 = 11 /**< PRS channel 11. */ |
Kojto | 98:8ab26030e058 | 160 | #endif |
Kojto | 98:8ab26030e058 | 161 | } PCNT_PRSSel_TypeDef; |
Kojto | 98:8ab26030e058 | 162 | |
Kojto | 98:8ab26030e058 | 163 | |
Kojto | 98:8ab26030e058 | 164 | /** PRS inputs of PCNT. */ |
Kojto | 98:8ab26030e058 | 165 | typedef enum |
Kojto | 98:8ab26030e058 | 166 | { |
Kojto | 98:8ab26030e058 | 167 | pcntPRSInputS0 = 0, /** PRS input 0. */ |
Kojto | 98:8ab26030e058 | 168 | pcntPRSInputS1 = 1 /** PRS input 1. */ |
Kojto | 98:8ab26030e058 | 169 | } PCNT_PRSInput_TypeDef; |
Kojto | 98:8ab26030e058 | 170 | #endif |
Kojto | 98:8ab26030e058 | 171 | |
Kojto | 98:8ab26030e058 | 172 | |
Kojto | 98:8ab26030e058 | 173 | /******************************************************************************* |
Kojto | 98:8ab26030e058 | 174 | ******************************* STRUCTS *********************************** |
Kojto | 98:8ab26030e058 | 175 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 176 | |
Kojto | 98:8ab26030e058 | 177 | /** Init structure. */ |
Kojto | 98:8ab26030e058 | 178 | typedef struct |
Kojto | 98:8ab26030e058 | 179 | { |
Kojto | 98:8ab26030e058 | 180 | /** Mode to operate in. */ |
Kojto | 98:8ab26030e058 | 181 | PCNT_Mode_TypeDef mode; |
Kojto | 98:8ab26030e058 | 182 | |
Kojto | 98:8ab26030e058 | 183 | /** Initial counter value (refer to reference manual for max value allowed). |
Kojto | 98:8ab26030e058 | 184 | * Only used for #pcntModeOvsSingle (and possibly #pcntModeDisable) modes. |
Kojto | 98:8ab26030e058 | 185 | * If using #pcntModeExtSingle or #pcntModeExtQuad modes, the counter |
Kojto | 98:8ab26030e058 | 186 | * value is reset to HW reset value. */ |
Kojto | 98:8ab26030e058 | 187 | uint32_t counter; |
Kojto | 98:8ab26030e058 | 188 | |
Kojto | 98:8ab26030e058 | 189 | /** Initial top value (refer to reference manual for max value allowed). |
Kojto | 98:8ab26030e058 | 190 | * Only used for #pcntModeOvsSingle (and possibly #pcntModeDisable) modes. |
Kojto | 98:8ab26030e058 | 191 | * If using #pcntModeExtSingle or #pcntModeExtQuad modes, the top |
Kojto | 98:8ab26030e058 | 192 | * value is reset to HW reset value. */ |
Kojto | 98:8ab26030e058 | 193 | uint32_t top; |
Kojto | 98:8ab26030e058 | 194 | |
Kojto | 98:8ab26030e058 | 195 | /** Polarity of incoming edge. |
Kojto | 98:8ab26030e058 | 196 | * @li #pcntModeExtSingle mode - if false, positive edges are counted, |
Kojto | 98:8ab26030e058 | 197 | * otherwise negative edges. |
Kojto | 98:8ab26030e058 | 198 | * @li #pcntModeExtQuad mode - if true, counting direction is inverted. */ |
Kojto | 98:8ab26030e058 | 199 | bool negEdge; |
Kojto | 98:8ab26030e058 | 200 | |
Kojto | 98:8ab26030e058 | 201 | /** Counting direction, only applicable for #pcntModeOvsSingle and |
Kojto | 98:8ab26030e058 | 202 | * #pcntModeExtSingle modes. */ |
Kojto | 98:8ab26030e058 | 203 | bool countDown; |
<> | 128:9bcdf88f62b0 | 204 | |
Kojto | 113:f141b2784e32 | 205 | /** Enable filter, only available in #pcntModeOvs* modes. */ |
Kojto | 98:8ab26030e058 | 206 | bool filter; |
Kojto | 98:8ab26030e058 | 207 | |
Kojto | 113:f141b2784e32 | 208 | #if defined(PCNT_CTRL_HYST) |
Kojto | 98:8ab26030e058 | 209 | /** Set to true to enable hysteresis. When its enabled, the PCNT will always |
Kojto | 98:8ab26030e058 | 210 | * overflow and underflow to TOP/2. */ |
Kojto | 98:8ab26030e058 | 211 | bool hyst; |
Kojto | 98:8ab26030e058 | 212 | |
Kojto | 98:8ab26030e058 | 213 | /** Set to true to enable S1 to determine the direction of counting in |
Kojto | 113:f141b2784e32 | 214 | * OVSSINGLE or EXTCLKSINGLE modes. @n |
Kojto | 98:8ab26030e058 | 215 | * When S1 is high, the count direction is given by CNTDIR, and when S1 is |
Kojto | 98:8ab26030e058 | 216 | * low, the count direction is the opposite. */ |
Kojto | 98:8ab26030e058 | 217 | bool s1CntDir; |
Kojto | 98:8ab26030e058 | 218 | |
Kojto | 98:8ab26030e058 | 219 | /** Selects whether the regular counter responds to up-count events, |
Kojto | 98:8ab26030e058 | 220 | * down-count events, both or none. */ |
Kojto | 98:8ab26030e058 | 221 | PCNT_CntEvent_TypeDef cntEvent; |
Kojto | 98:8ab26030e058 | 222 | |
Kojto | 98:8ab26030e058 | 223 | /** Selects whether the auxiliary counter responds to up-count events, |
Kojto | 98:8ab26030e058 | 224 | * down-count events, both or none. */ |
Kojto | 98:8ab26030e058 | 225 | PCNT_CntEvent_TypeDef auxCntEvent; |
Kojto | 98:8ab26030e058 | 226 | |
Kojto | 98:8ab26030e058 | 227 | /** Select PRS channel as input to S0IN in PCNTx_INPUT register. */ |
Kojto | 98:8ab26030e058 | 228 | PCNT_PRSSel_TypeDef s0PRS; |
Kojto | 98:8ab26030e058 | 229 | |
Kojto | 98:8ab26030e058 | 230 | /** Select PRS channel as input to S1IN in PCNTx_INPUT register. */ |
Kojto | 98:8ab26030e058 | 231 | PCNT_PRSSel_TypeDef s1PRS; |
Kojto | 98:8ab26030e058 | 232 | #endif |
Kojto | 98:8ab26030e058 | 233 | } PCNT_Init_TypeDef; |
Kojto | 98:8ab26030e058 | 234 | |
Kojto | 113:f141b2784e32 | 235 | #if !defined(PCNT_CTRL_HYST) |
Kojto | 98:8ab26030e058 | 236 | /** Default config for PCNT init structure. */ |
Kojto | 113:f141b2784e32 | 237 | #define PCNT_INIT_DEFAULT \ |
Kojto | 113:f141b2784e32 | 238 | { \ |
Kojto | 113:f141b2784e32 | 239 | pcntModeDisable, /* Disabled by default. */ \ |
Kojto | 113:f141b2784e32 | 240 | _PCNT_CNT_RESETVALUE, /* Default counter HW reset value. */ \ |
Kojto | 113:f141b2784e32 | 241 | _PCNT_TOP_RESETVALUE, /* Default counter HW reset value. */ \ |
Kojto | 113:f141b2784e32 | 242 | false, /* Use positive edge. */ \ |
Kojto | 113:f141b2784e32 | 243 | false, /* Up-counting. */ \ |
Kojto | 113:f141b2784e32 | 244 | false /* Filter disabled. */ \ |
Kojto | 113:f141b2784e32 | 245 | } |
Kojto | 98:8ab26030e058 | 246 | #else |
Kojto | 98:8ab26030e058 | 247 | /** Default config for PCNT init structure. */ |
Kojto | 113:f141b2784e32 | 248 | #define PCNT_INIT_DEFAULT \ |
Kojto | 113:f141b2784e32 | 249 | { \ |
Kojto | 113:f141b2784e32 | 250 | pcntModeDisable, /* Disabled by default. */ \ |
Kojto | 113:f141b2784e32 | 251 | _PCNT_CNT_RESETVALUE, /* Default counter HW reset value. */ \ |
Kojto | 113:f141b2784e32 | 252 | _PCNT_TOP_RESETVALUE, /* Default counter HW reset value. */ \ |
Kojto | 113:f141b2784e32 | 253 | false, /* Use positive edge. */ \ |
Kojto | 113:f141b2784e32 | 254 | false, /* Up-counting. */ \ |
Kojto | 113:f141b2784e32 | 255 | false, /* Filter disabled. */ \ |
Kojto | 113:f141b2784e32 | 256 | false, /* Hysteresis disabled. */ \ |
Kojto | 113:f141b2784e32 | 257 | true, /* Counter direction is given by CNTDIR. */ \ |
Kojto | 113:f141b2784e32 | 258 | pcntCntEventUp, /* Regular counter counts up on upcount events. */ \ |
Kojto | 113:f141b2784e32 | 259 | pcntCntEventNone, /* Auxiliary counter doesn't respond to events. */ \ |
Kojto | 113:f141b2784e32 | 260 | pcntPRSCh0, /* PRS channel 0 selected as S0IN. */ \ |
Kojto | 113:f141b2784e32 | 261 | pcntPRSCh0 /* PRS channel 0 selected as S1IN. */ \ |
Kojto | 113:f141b2784e32 | 262 | } |
Kojto | 113:f141b2784e32 | 263 | #endif |
Kojto | 113:f141b2784e32 | 264 | |
Kojto | 113:f141b2784e32 | 265 | #if defined(PCNT_OVSCFG_FILTLEN_DEFAULT) |
Kojto | 113:f141b2784e32 | 266 | /** Filter initialization structure */ |
<> | 128:9bcdf88f62b0 | 267 | typedef struct |
Kojto | 113:f141b2784e32 | 268 | { |
Kojto | 113:f141b2784e32 | 269 | /** Used only in OVSINGLE and OVSQUAD1X-4X modes. To use this, enable the filter through |
Kojto | 113:f141b2784e32 | 270 | * setting filter to true during PCNT_Init(). Filter length = (filtLen + 5) LFACLK cycles. */ |
Kojto | 113:f141b2784e32 | 271 | uint8_t filtLen; |
<> | 128:9bcdf88f62b0 | 272 | |
<> | 128:9bcdf88f62b0 | 273 | /** When set, removes flutter from Quaddecoder inputs S0IN and S1IN. |
Kojto | 113:f141b2784e32 | 274 | * Available only in OVSQUAD1X-4X modes. */ |
Kojto | 113:f141b2784e32 | 275 | bool flutterrm; |
Kojto | 113:f141b2784e32 | 276 | } PCNT_Filter_TypeDef; |
Kojto | 113:f141b2784e32 | 277 | #endif |
Kojto | 113:f141b2784e32 | 278 | |
Kojto | 113:f141b2784e32 | 279 | /** Default config for PCNT init structure. */ |
Kojto | 113:f141b2784e32 | 280 | #if defined(PCNT_OVSCFG_FILTLEN_DEFAULT) |
Kojto | 113:f141b2784e32 | 281 | #define PCNT_FILTER_DEFAULT \ |
Kojto | 113:f141b2784e32 | 282 | { \ |
Kojto | 113:f141b2784e32 | 283 | 0, /* Default length is 5 LFACLK cycles */ \ |
Kojto | 113:f141b2784e32 | 284 | false /* No flutter removal */ \ |
<> | 128:9bcdf88f62b0 | 285 | } |
Kojto | 98:8ab26030e058 | 286 | #endif |
Kojto | 98:8ab26030e058 | 287 | |
Kojto | 113:f141b2784e32 | 288 | #if defined(PCNT_CTRL_TCCMODE_DEFAULT) |
Kojto | 113:f141b2784e32 | 289 | |
Kojto | 113:f141b2784e32 | 290 | /** Modes for Triggered Compare and Clear module */ |
<> | 128:9bcdf88f62b0 | 291 | typedef enum |
Kojto | 113:f141b2784e32 | 292 | { |
Kojto | 113:f141b2784e32 | 293 | /** Triggered compare and clear not enabled. */ |
Kojto | 113:f141b2784e32 | 294 | tccModeDisabled = _PCNT_CTRL_TCCMODE_DISABLED, |
<> | 128:9bcdf88f62b0 | 295 | |
Kojto | 113:f141b2784e32 | 296 | /** Compare and clear performed on each (optionally prescaled) LFA clock cycle. */ |
Kojto | 113:f141b2784e32 | 297 | tccModeLFA = _PCNT_CTRL_TCCMODE_LFA, |
<> | 128:9bcdf88f62b0 | 298 | |
Kojto | 113:f141b2784e32 | 299 | /** Compare and clear performed on PRS edges. Polarity defined by prsPolarity. */ |
Kojto | 113:f141b2784e32 | 300 | tccModePRS = _PCNT_CTRL_TCCMODE_PRS |
Kojto | 113:f141b2784e32 | 301 | } PCNT_TCCMode_TypeDef; |
Kojto | 113:f141b2784e32 | 302 | |
Kojto | 113:f141b2784e32 | 303 | /** Prescaler values for LFA compare and clear events. Only has effect when TCC mode is LFA. */ |
<> | 128:9bcdf88f62b0 | 304 | typedef enum |
Kojto | 113:f141b2784e32 | 305 | { |
Kojto | 113:f141b2784e32 | 306 | /** Compare and clear event each LFA cycle. */ |
Kojto | 113:f141b2784e32 | 307 | tccPrescDiv1 = _PCNT_CTRL_TCCPRESC_DIV1, |
<> | 128:9bcdf88f62b0 | 308 | |
Kojto | 113:f141b2784e32 | 309 | /** Compare and clear event every other LFA cycle. */ |
Kojto | 113:f141b2784e32 | 310 | tccPrescDiv2 = _PCNT_CTRL_TCCPRESC_DIV2, |
<> | 128:9bcdf88f62b0 | 311 | |
Kojto | 113:f141b2784e32 | 312 | /** Compare and clear event every 4th LFA cycle. */ |
Kojto | 113:f141b2784e32 | 313 | tccPrescDiv4 = _PCNT_CTRL_TCCPRESC_DIV4, |
<> | 128:9bcdf88f62b0 | 314 | |
Kojto | 113:f141b2784e32 | 315 | /** Compare and clear event every 8th LFA cycle. */ |
Kojto | 113:f141b2784e32 | 316 | tccPrescDiv8 = _PCNT_CTRL_TCCPRESC_DIV8 |
Kojto | 113:f141b2784e32 | 317 | } PCNT_TCCPresc_Typedef; |
Kojto | 113:f141b2784e32 | 318 | |
Kojto | 113:f141b2784e32 | 319 | /** Compare modes for TCC module */ |
<> | 128:9bcdf88f62b0 | 320 | typedef enum |
Kojto | 113:f141b2784e32 | 321 | { |
Kojto | 113:f141b2784e32 | 322 | /** Compare match if PCNT_CNT is less than, or equal to PCNT_TOP. */ |
Kojto | 113:f141b2784e32 | 323 | tccCompLTOE = _PCNT_CTRL_TCCCOMP_LTOE, |
<> | 128:9bcdf88f62b0 | 324 | |
Kojto | 113:f141b2784e32 | 325 | /** Compare match if PCNT_CNT is greater than or equal to PCNT_TOP. */ |
Kojto | 113:f141b2784e32 | 326 | tccCompGTOE = _PCNT_CTRL_TCCCOMP_GTOE, |
<> | 128:9bcdf88f62b0 | 327 | |
Kojto | 113:f141b2784e32 | 328 | /** Compare match if PCNT_CNT is less than, or equal to PCNT_TOP[15:8]], and greater |
Kojto | 113:f141b2784e32 | 329 | * than, or equal to PCNT_TOP[7:0]. */ |
Kojto | 113:f141b2784e32 | 330 | tccCompRange = _PCNT_CTRL_TCCCOMP_RANGE |
Kojto | 113:f141b2784e32 | 331 | } PCNT_TCCComp_Typedef; |
Kojto | 113:f141b2784e32 | 332 | |
Kojto | 113:f141b2784e32 | 333 | /** TCC initialization structure */ |
<> | 128:9bcdf88f62b0 | 334 | typedef struct |
Kojto | 113:f141b2784e32 | 335 | { |
Kojto | 113:f141b2784e32 | 336 | /** Mode to operate in. */ |
Kojto | 113:f141b2784e32 | 337 | PCNT_TCCMode_TypeDef mode; |
<> | 128:9bcdf88f62b0 | 338 | |
Kojto | 113:f141b2784e32 | 339 | /** Prescaler value for LFACLK in LFA mode */ |
Kojto | 113:f141b2784e32 | 340 | PCNT_TCCPresc_Typedef prescaler; |
<> | 128:9bcdf88f62b0 | 341 | |
Kojto | 113:f141b2784e32 | 342 | /** Choose the event that will trigger a clear */ |
Kojto | 113:f141b2784e32 | 343 | PCNT_TCCComp_Typedef compare; |
<> | 128:9bcdf88f62b0 | 344 | |
Kojto | 113:f141b2784e32 | 345 | /** PRS input to TCC module, either for gating the PCNT clock, triggering the TCC comparison, or both. */ |
Kojto | 113:f141b2784e32 | 346 | PCNT_PRSSel_TypeDef tccPRS; |
Kojto | 113:f141b2784e32 | 347 | |
Kojto | 113:f141b2784e32 | 348 | /** TCC PRS input polarity. @n |
Kojto | 113:f141b2784e32 | 349 | * False = Rising edge for comparison trigger, and PCNT clock gated when the PRS signal is high. @n |
Kojto | 113:f141b2784e32 | 350 | * True = Falling edge for comparison trigger, and PCNT clock gated when the PRS signal is low. */ |
Kojto | 113:f141b2784e32 | 351 | bool prsPolarity; |
<> | 128:9bcdf88f62b0 | 352 | |
<> | 128:9bcdf88f62b0 | 353 | /** Enable gating PCNT input clock through TCC PRS signal. |
Kojto | 113:f141b2784e32 | 354 | * Polarity selection is done through prsPolarity. */ |
Kojto | 113:f141b2784e32 | 355 | bool prsGateEnable; |
Kojto | 113:f141b2784e32 | 356 | } PCNT_TCC_TypeDef; |
Kojto | 113:f141b2784e32 | 357 | |
Kojto | 113:f141b2784e32 | 358 | #define PCNT_TCC_DEFAULT \ |
Kojto | 113:f141b2784e32 | 359 | { \ |
Kojto | 113:f141b2784e32 | 360 | tccModeDisabled, /* Disabled by default */ \ |
Kojto | 113:f141b2784e32 | 361 | tccPrescDiv1, /* Do not prescale LFA clock in LFA mode */ \ |
Kojto | 113:f141b2784e32 | 362 | tccCompLTOE, /* Clear when CNT <= TOP */ \ |
Kojto | 113:f141b2784e32 | 363 | pcntPRSCh0, /* Select PRS channel 0 as input to TCC */ \ |
Kojto | 113:f141b2784e32 | 364 | false, /* PRS polarity is rising edge, and gate when 1 */ \ |
Kojto | 113:f141b2784e32 | 365 | false /* Do not gate the PCNT counter input */ \ |
Kojto | 113:f141b2784e32 | 366 | } |
Kojto | 113:f141b2784e32 | 367 | |
<> | 128:9bcdf88f62b0 | 368 | #endif |
Kojto | 113:f141b2784e32 | 369 | /* defined(PCNT_CTRL_TCCMODE_DEFAULT) */ |
Kojto | 98:8ab26030e058 | 370 | |
Kojto | 98:8ab26030e058 | 371 | /******************************************************************************* |
Kojto | 98:8ab26030e058 | 372 | ***************************** PROTOTYPES ********************************** |
Kojto | 98:8ab26030e058 | 373 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 374 | |
Kojto | 98:8ab26030e058 | 375 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 376 | * @brief |
Kojto | 98:8ab26030e058 | 377 | * Get pulse counter value. |
Kojto | 98:8ab26030e058 | 378 | * |
Kojto | 98:8ab26030e058 | 379 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 380 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 381 | * |
Kojto | 98:8ab26030e058 | 382 | * @return |
Kojto | 98:8ab26030e058 | 383 | * Current pulse counter value. |
Kojto | 98:8ab26030e058 | 384 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 385 | __STATIC_INLINE uint32_t PCNT_CounterGet(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 386 | { |
Kojto | 98:8ab26030e058 | 387 | return pcnt->CNT; |
Kojto | 98:8ab26030e058 | 388 | } |
Kojto | 98:8ab26030e058 | 389 | |
Kojto | 113:f141b2784e32 | 390 | #if defined(_PCNT_AUXCNT_MASK) |
Kojto | 98:8ab26030e058 | 391 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 392 | * @brief |
Kojto | 98:8ab26030e058 | 393 | * Get auxiliary counter value. |
Kojto | 98:8ab26030e058 | 394 | * |
Kojto | 98:8ab26030e058 | 395 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 396 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 397 | * |
Kojto | 98:8ab26030e058 | 398 | * @return |
Kojto | 98:8ab26030e058 | 399 | * Current auxiliary counter value. |
Kojto | 98:8ab26030e058 | 400 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 401 | __STATIC_INLINE uint32_t PCNT_AuxCounterGet(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 402 | { |
Kojto | 98:8ab26030e058 | 403 | return pcnt->AUXCNT; |
Kojto | 98:8ab26030e058 | 404 | } |
Kojto | 98:8ab26030e058 | 405 | #endif |
Kojto | 98:8ab26030e058 | 406 | |
Kojto | 98:8ab26030e058 | 407 | void PCNT_CounterReset(PCNT_TypeDef *pcnt); |
Kojto | 98:8ab26030e058 | 408 | void PCNT_CounterTopSet(PCNT_TypeDef *pcnt, uint32_t count, uint32_t top); |
Kojto | 98:8ab26030e058 | 409 | |
Kojto | 98:8ab26030e058 | 410 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 411 | * @brief |
Kojto | 98:8ab26030e058 | 412 | * Set counter value. |
Kojto | 98:8ab26030e058 | 413 | * |
Kojto | 98:8ab26030e058 | 414 | * @details |
Kojto | 98:8ab26030e058 | 415 | * The pulse counter is disabled while changing counter value, and reenabled |
Kojto | 98:8ab26030e058 | 416 | * (if originally enabled) when counter value has been set. |
Kojto | 98:8ab26030e058 | 417 | * |
Kojto | 98:8ab26030e058 | 418 | * @note |
Kojto | 98:8ab26030e058 | 419 | * This function will stall until synchronization to low frequency domain is |
Kojto | 98:8ab26030e058 | 420 | * completed. For that reason, it should normally not be used when using |
Kojto | 98:8ab26030e058 | 421 | * an external clock to clock the PCNT module, since stall time may be |
Kojto | 98:8ab26030e058 | 422 | * undefined in that case. The counter should normally only be set when |
Kojto | 98:8ab26030e058 | 423 | * operating in (or about to enable) #pcntModeOvsSingle mode. |
Kojto | 98:8ab26030e058 | 424 | * |
Kojto | 98:8ab26030e058 | 425 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 426 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 427 | * |
Kojto | 98:8ab26030e058 | 428 | * @param[in] count |
Kojto | 98:8ab26030e058 | 429 | * Value to set in counter register. |
Kojto | 98:8ab26030e058 | 430 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 431 | __STATIC_INLINE void PCNT_CounterSet(PCNT_TypeDef *pcnt, uint32_t count) |
Kojto | 98:8ab26030e058 | 432 | { |
Kojto | 98:8ab26030e058 | 433 | PCNT_CounterTopSet(pcnt, count, pcnt->TOP); |
Kojto | 98:8ab26030e058 | 434 | } |
Kojto | 98:8ab26030e058 | 435 | |
Kojto | 98:8ab26030e058 | 436 | void PCNT_Enable(PCNT_TypeDef *pcnt, PCNT_Mode_TypeDef mode); |
Kojto | 98:8ab26030e058 | 437 | void PCNT_FreezeEnable(PCNT_TypeDef *pcnt, bool enable); |
Kojto | 98:8ab26030e058 | 438 | void PCNT_Init(PCNT_TypeDef *pcnt, const PCNT_Init_TypeDef *init); |
Kojto | 98:8ab26030e058 | 439 | |
Kojto | 113:f141b2784e32 | 440 | #if defined(PCNT_OVSCFG_FILTLEN_DEFAULT) |
Kojto | 113:f141b2784e32 | 441 | void PCNT_FilterConfiguration(PCNT_TypeDef *pcnt, const PCNT_Filter_TypeDef *config, bool enable); |
Kojto | 113:f141b2784e32 | 442 | #endif |
Kojto | 113:f141b2784e32 | 443 | |
Kojto | 113:f141b2784e32 | 444 | #if defined(_PCNT_INPUT_MASK) |
Kojto | 98:8ab26030e058 | 445 | void PCNT_PRSInputEnable(PCNT_TypeDef *pcnt, |
Kojto | 98:8ab26030e058 | 446 | PCNT_PRSInput_TypeDef prsInput, |
Kojto | 98:8ab26030e058 | 447 | bool enable); |
Kojto | 98:8ab26030e058 | 448 | #endif |
Kojto | 98:8ab26030e058 | 449 | |
Kojto | 113:f141b2784e32 | 450 | #if defined(PCNT_CTRL_TCCMODE_DEFAULT) |
Kojto | 113:f141b2784e32 | 451 | void PCNT_TCCConfiguration(PCNT_TypeDef *pcnt, const PCNT_TCC_TypeDef *config); |
Kojto | 113:f141b2784e32 | 452 | #endif |
Kojto | 98:8ab26030e058 | 453 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 454 | * @brief |
Kojto | 98:8ab26030e058 | 455 | * Clear one or more pending PCNT interrupts. |
Kojto | 98:8ab26030e058 | 456 | * |
Kojto | 98:8ab26030e058 | 457 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 458 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 459 | * |
Kojto | 98:8ab26030e058 | 460 | * @param[in] flags |
Kojto | 98:8ab26030e058 | 461 | * Pending PCNT interrupt source to clear. Use a bitwise logic OR combination |
Kojto | 98:8ab26030e058 | 462 | * of valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 463 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 464 | __STATIC_INLINE void PCNT_IntClear(PCNT_TypeDef *pcnt, uint32_t flags) |
Kojto | 98:8ab26030e058 | 465 | { |
Kojto | 98:8ab26030e058 | 466 | pcnt->IFC = flags; |
Kojto | 98:8ab26030e058 | 467 | } |
Kojto | 98:8ab26030e058 | 468 | |
Kojto | 98:8ab26030e058 | 469 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 470 | * @brief |
Kojto | 98:8ab26030e058 | 471 | * Disable one or more PCNT interrupts. |
Kojto | 98:8ab26030e058 | 472 | * |
Kojto | 98:8ab26030e058 | 473 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 474 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 475 | * |
Kojto | 98:8ab26030e058 | 476 | * @param[in] flags |
Kojto | 98:8ab26030e058 | 477 | * PCNT interrupt sources to disable. Use a bitwise logic OR combination of |
Kojto | 98:8ab26030e058 | 478 | * valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 479 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 480 | __STATIC_INLINE void PCNT_IntDisable(PCNT_TypeDef *pcnt, uint32_t flags) |
Kojto | 98:8ab26030e058 | 481 | { |
Kojto | 113:f141b2784e32 | 482 | pcnt->IEN &= ~flags; |
Kojto | 98:8ab26030e058 | 483 | } |
Kojto | 98:8ab26030e058 | 484 | |
Kojto | 98:8ab26030e058 | 485 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 486 | * @brief |
Kojto | 98:8ab26030e058 | 487 | * Enable one or more PCNT interrupts. |
Kojto | 98:8ab26030e058 | 488 | * |
Kojto | 98:8ab26030e058 | 489 | * @note |
Kojto | 98:8ab26030e058 | 490 | * Depending on the use, a pending interrupt may already be set prior to |
Kojto | 98:8ab26030e058 | 491 | * enabling the interrupt. Consider using PCNT_IntClear() prior to enabling |
Kojto | 98:8ab26030e058 | 492 | * if such a pending interrupt should be ignored. |
Kojto | 98:8ab26030e058 | 493 | * |
Kojto | 98:8ab26030e058 | 494 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 495 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 496 | * |
Kojto | 98:8ab26030e058 | 497 | * @param[in] flags |
Kojto | 98:8ab26030e058 | 498 | * PCNT interrupt sources to enable. Use a bitwise logic OR combination of |
Kojto | 98:8ab26030e058 | 499 | * valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 500 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 501 | __STATIC_INLINE void PCNT_IntEnable(PCNT_TypeDef *pcnt, uint32_t flags) |
Kojto | 98:8ab26030e058 | 502 | { |
Kojto | 98:8ab26030e058 | 503 | pcnt->IEN |= flags; |
Kojto | 98:8ab26030e058 | 504 | } |
Kojto | 98:8ab26030e058 | 505 | |
Kojto | 98:8ab26030e058 | 506 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 507 | * @brief |
Kojto | 98:8ab26030e058 | 508 | * Get pending PCNT interrupt flags. |
Kojto | 98:8ab26030e058 | 509 | * |
Kojto | 98:8ab26030e058 | 510 | * @note |
Kojto | 98:8ab26030e058 | 511 | * The event bits are not cleared by the use of this function. |
Kojto | 98:8ab26030e058 | 512 | * |
Kojto | 98:8ab26030e058 | 513 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 514 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 515 | * |
Kojto | 98:8ab26030e058 | 516 | * @return |
Kojto | 98:8ab26030e058 | 517 | * PCNT interrupt sources pending. A bitwise logic OR combination of valid |
Kojto | 98:8ab26030e058 | 518 | * interrupt flags for the PCNT module (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 519 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 520 | __STATIC_INLINE uint32_t PCNT_IntGet(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 521 | { |
Kojto | 98:8ab26030e058 | 522 | return pcnt->IF; |
Kojto | 98:8ab26030e058 | 523 | } |
Kojto | 98:8ab26030e058 | 524 | |
Kojto | 98:8ab26030e058 | 525 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 526 | * @brief |
Kojto | 98:8ab26030e058 | 527 | * Get enabled and pending PCNT interrupt flags. |
Kojto | 98:8ab26030e058 | 528 | * |
Kojto | 98:8ab26030e058 | 529 | * @details |
Kojto | 98:8ab26030e058 | 530 | * Useful for handling more interrupt sources in the same interrupt handler. |
Kojto | 98:8ab26030e058 | 531 | * |
Kojto | 98:8ab26030e058 | 532 | * @note |
Kojto | 98:8ab26030e058 | 533 | * The event bits are not cleared by the use of this function. |
Kojto | 98:8ab26030e058 | 534 | * |
Kojto | 98:8ab26030e058 | 535 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 536 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 537 | * |
Kojto | 98:8ab26030e058 | 538 | * @return |
Kojto | 98:8ab26030e058 | 539 | * Pending and enabled PCNT interrupt sources. |
Kojto | 98:8ab26030e058 | 540 | * The return value is the bitwise AND combination of |
Kojto | 98:8ab26030e058 | 541 | * - the OR combination of enabled interrupt sources in PCNT_IEN_nnn |
Kojto | 98:8ab26030e058 | 542 | * register (PCNT_IEN_nnn) and |
Kojto | 98:8ab26030e058 | 543 | * - the OR combination of valid interrupt flags of the PCNT module |
Kojto | 98:8ab26030e058 | 544 | * (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 545 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 546 | __STATIC_INLINE uint32_t PCNT_IntGetEnabled(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 547 | { |
Kojto | 113:f141b2784e32 | 548 | uint32_t ien; |
Kojto | 98:8ab26030e058 | 549 | |
Kojto | 98:8ab26030e058 | 550 | |
Kojto | 98:8ab26030e058 | 551 | /* Store pcnt->IEN in temporary variable in order to define explicit order |
Kojto | 98:8ab26030e058 | 552 | * of volatile accesses. */ |
Kojto | 113:f141b2784e32 | 553 | ien = pcnt->IEN; |
Kojto | 98:8ab26030e058 | 554 | |
Kojto | 98:8ab26030e058 | 555 | /* Bitwise AND of pending and enabled interrupts */ |
Kojto | 113:f141b2784e32 | 556 | return pcnt->IF & ien; |
Kojto | 98:8ab26030e058 | 557 | } |
Kojto | 98:8ab26030e058 | 558 | |
Kojto | 98:8ab26030e058 | 559 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 560 | * @brief |
Kojto | 98:8ab26030e058 | 561 | * Set one or more pending PCNT interrupts from SW. |
Kojto | 98:8ab26030e058 | 562 | * |
Kojto | 98:8ab26030e058 | 563 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 564 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 565 | * |
Kojto | 98:8ab26030e058 | 566 | * @param[in] flags |
Kojto | 98:8ab26030e058 | 567 | * PCNT interrupt sources to set to pending. Use a bitwise logic OR combination |
Kojto | 98:8ab26030e058 | 568 | * of valid interrupt flags for the PCNT module (PCNT_IF_nnn). |
Kojto | 98:8ab26030e058 | 569 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 570 | __STATIC_INLINE void PCNT_IntSet(PCNT_TypeDef *pcnt, uint32_t flags) |
Kojto | 98:8ab26030e058 | 571 | { |
Kojto | 98:8ab26030e058 | 572 | pcnt->IFS = flags; |
Kojto | 98:8ab26030e058 | 573 | } |
Kojto | 98:8ab26030e058 | 574 | |
Kojto | 98:8ab26030e058 | 575 | void PCNT_Reset(PCNT_TypeDef *pcnt); |
Kojto | 98:8ab26030e058 | 576 | |
Kojto | 98:8ab26030e058 | 577 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 578 | * @brief |
Kojto | 98:8ab26030e058 | 579 | * Get pulse counter top buffer value. |
Kojto | 98:8ab26030e058 | 580 | * |
Kojto | 98:8ab26030e058 | 581 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 582 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 583 | * |
Kojto | 98:8ab26030e058 | 584 | * @return |
Kojto | 98:8ab26030e058 | 585 | * Current pulse counter top buffer value. |
Kojto | 98:8ab26030e058 | 586 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 587 | __STATIC_INLINE uint32_t PCNT_TopBufferGet(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 588 | { |
Kojto | 98:8ab26030e058 | 589 | return pcnt->TOPB; |
Kojto | 98:8ab26030e058 | 590 | } |
Kojto | 98:8ab26030e058 | 591 | |
Kojto | 98:8ab26030e058 | 592 | void PCNT_TopBufferSet(PCNT_TypeDef *pcnt, uint32_t val); |
Kojto | 98:8ab26030e058 | 593 | |
Kojto | 98:8ab26030e058 | 594 | /***************************************************************************//** |
Kojto | 98:8ab26030e058 | 595 | * @brief |
Kojto | 98:8ab26030e058 | 596 | * Get pulse counter top value. |
Kojto | 98:8ab26030e058 | 597 | * |
Kojto | 98:8ab26030e058 | 598 | * @param[in] pcnt |
Kojto | 98:8ab26030e058 | 599 | * Pointer to PCNT peripheral register block. |
Kojto | 98:8ab26030e058 | 600 | * |
Kojto | 98:8ab26030e058 | 601 | * @return |
Kojto | 98:8ab26030e058 | 602 | * Current pulse counter top value. |
Kojto | 98:8ab26030e058 | 603 | ******************************************************************************/ |
Kojto | 98:8ab26030e058 | 604 | __STATIC_INLINE uint32_t PCNT_TopGet(PCNT_TypeDef *pcnt) |
Kojto | 98:8ab26030e058 | 605 | { |
Kojto | 98:8ab26030e058 | 606 | return pcnt->TOP; |
Kojto | 98:8ab26030e058 | 607 | } |
Kojto | 98:8ab26030e058 | 608 | |
Kojto | 98:8ab26030e058 | 609 | void PCNT_TopSet(PCNT_TypeDef *pcnt, uint32_t val); |
Kojto | 98:8ab26030e058 | 610 | |
Kojto | 98:8ab26030e058 | 611 | /** @} (end addtogroup PCNT) */ |
<> | 128:9bcdf88f62b0 | 612 | /** @} (end addtogroup emlib) */ |
Kojto | 98:8ab26030e058 | 613 | |
Kojto | 98:8ab26030e058 | 614 | #ifdef __cplusplus |
Kojto | 98:8ab26030e058 | 615 | } |
Kojto | 98:8ab26030e058 | 616 | #endif |
Kojto | 98:8ab26030e058 | 617 | |
Kojto | 98:8ab26030e058 | 618 | #endif /* defined(PCNT_COUNT) && (PCNT_COUNT > 0) */ |
<> | 128:9bcdf88f62b0 | 619 | #endif /* EM_PCNT_H */ |