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:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30 #ifndef _FSL_FTM_H_
AnnaBridge 143:86740a56073b 31 #define _FSL_FTM_H_
AnnaBridge 143:86740a56073b 32
AnnaBridge 143:86740a56073b 33 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 34
AnnaBridge 143:86740a56073b 35 /*!
AnnaBridge 143:86740a56073b 36 * @addtogroup ftm
AnnaBridge 143:86740a56073b 37 * @{
AnnaBridge 143:86740a56073b 38 */
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 /*******************************************************************************
AnnaBridge 143:86740a56073b 42 * Definitions
AnnaBridge 143:86740a56073b 43 ******************************************************************************/
AnnaBridge 143:86740a56073b 44
AnnaBridge 143:86740a56073b 45 /*! @name Driver version */
AnnaBridge 143:86740a56073b 46 /*@{*/
AnnaBridge 143:86740a56073b 47 #define FSL_FTM_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) /*!< Version 2.0.2 */
AnnaBridge 143:86740a56073b 48 /*@}*/
AnnaBridge 143:86740a56073b 49
AnnaBridge 143:86740a56073b 50 /*!
AnnaBridge 143:86740a56073b 51 * @brief List of FTM channels
AnnaBridge 143:86740a56073b 52 * @note Actual number of available channels is SoC dependent
AnnaBridge 143:86740a56073b 53 */
AnnaBridge 143:86740a56073b 54 typedef enum _ftm_chnl
AnnaBridge 143:86740a56073b 55 {
AnnaBridge 143:86740a56073b 56 kFTM_Chnl_0 = 0U, /*!< FTM channel number 0*/
AnnaBridge 143:86740a56073b 57 kFTM_Chnl_1, /*!< FTM channel number 1 */
AnnaBridge 143:86740a56073b 58 kFTM_Chnl_2, /*!< FTM channel number 2 */
AnnaBridge 143:86740a56073b 59 kFTM_Chnl_3, /*!< FTM channel number 3 */
AnnaBridge 143:86740a56073b 60 kFTM_Chnl_4, /*!< FTM channel number 4 */
AnnaBridge 143:86740a56073b 61 kFTM_Chnl_5, /*!< FTM channel number 5 */
AnnaBridge 143:86740a56073b 62 kFTM_Chnl_6, /*!< FTM channel number 6 */
AnnaBridge 143:86740a56073b 63 kFTM_Chnl_7 /*!< FTM channel number 7 */
AnnaBridge 143:86740a56073b 64 } ftm_chnl_t;
AnnaBridge 143:86740a56073b 65
AnnaBridge 143:86740a56073b 66 /*! @brief List of FTM faults */
AnnaBridge 143:86740a56073b 67 typedef enum _ftm_fault_input
AnnaBridge 143:86740a56073b 68 {
AnnaBridge 143:86740a56073b 69 kFTM_Fault_0 = 0U, /*!< FTM fault 0 input pin */
AnnaBridge 143:86740a56073b 70 kFTM_Fault_1, /*!< FTM fault 1 input pin */
AnnaBridge 143:86740a56073b 71 kFTM_Fault_2, /*!< FTM fault 2 input pin */
AnnaBridge 143:86740a56073b 72 kFTM_Fault_3 /*!< FTM fault 3 input pin */
AnnaBridge 143:86740a56073b 73 } ftm_fault_input_t;
AnnaBridge 143:86740a56073b 74
AnnaBridge 143:86740a56073b 75 /*! @brief FTM PWM operation modes */
AnnaBridge 143:86740a56073b 76 typedef enum _ftm_pwm_mode
AnnaBridge 143:86740a56073b 77 {
AnnaBridge 143:86740a56073b 78 kFTM_EdgeAlignedPwm = 0U, /*!< Edge-aligned PWM */
AnnaBridge 143:86740a56073b 79 kFTM_CenterAlignedPwm, /*!< Center-aligned PWM */
AnnaBridge 143:86740a56073b 80 kFTM_CombinedPwm /*!< Combined PWM */
AnnaBridge 143:86740a56073b 81 } ftm_pwm_mode_t;
AnnaBridge 143:86740a56073b 82
AnnaBridge 143:86740a56073b 83 /*! @brief FTM PWM output pulse mode: high-true, low-true or no output */
AnnaBridge 143:86740a56073b 84 typedef enum _ftm_pwm_level_select
AnnaBridge 143:86740a56073b 85 {
AnnaBridge 143:86740a56073b 86 kFTM_NoPwmSignal = 0U, /*!< No PWM output on pin */
AnnaBridge 143:86740a56073b 87 kFTM_LowTrue, /*!< Low true pulses */
AnnaBridge 143:86740a56073b 88 kFTM_HighTrue /*!< High true pulses */
AnnaBridge 143:86740a56073b 89 } ftm_pwm_level_select_t;
AnnaBridge 143:86740a56073b 90
AnnaBridge 143:86740a56073b 91 /*! @brief Options to configure a FTM channel's PWM signal */
AnnaBridge 143:86740a56073b 92 typedef struct _ftm_chnl_pwm_signal_param
AnnaBridge 143:86740a56073b 93 {
AnnaBridge 143:86740a56073b 94 ftm_chnl_t chnlNumber; /*!< The channel/channel pair number.
AnnaBridge 143:86740a56073b 95 In combined mode, this represents the channel pair number. */
AnnaBridge 143:86740a56073b 96 ftm_pwm_level_select_t level; /*!< PWM output active level select. */
AnnaBridge 143:86740a56073b 97 uint8_t dutyCyclePercent; /*!< PWM pulse width, value should be between 0 to 100
AnnaBridge 143:86740a56073b 98 0 = inactive signal(0% duty cycle)...
AnnaBridge 143:86740a56073b 99 100 = always active signal (100% duty cycle).*/
AnnaBridge 143:86740a56073b 100 uint8_t firstEdgeDelayPercent; /*!< Used only in combined PWM mode to generate an asymmetrical PWM.
AnnaBridge 143:86740a56073b 101 Specifies the delay to the first edge in a PWM period.
AnnaBridge 143:86740a56073b 102 If unsure leave as 0; Should be specified as a
AnnaBridge 143:86740a56073b 103 percentage of the PWM period */
AnnaBridge 143:86740a56073b 104 } ftm_chnl_pwm_signal_param_t;
AnnaBridge 143:86740a56073b 105
AnnaBridge 143:86740a56073b 106 /*! @brief FlexTimer output compare mode */
AnnaBridge 143:86740a56073b 107 typedef enum _ftm_output_compare_mode
AnnaBridge 143:86740a56073b 108 {
AnnaBridge 143:86740a56073b 109 kFTM_NoOutputSignal = (1U << FTM_CnSC_MSA_SHIFT), /*!< No channel output when counter reaches CnV */
AnnaBridge 143:86740a56073b 110 kFTM_ToggleOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (1U << FTM_CnSC_ELSA_SHIFT)), /*!< Toggle output */
AnnaBridge 143:86740a56073b 111 kFTM_ClearOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (2U << FTM_CnSC_ELSA_SHIFT)), /*!< Clear output */
AnnaBridge 143:86740a56073b 112 kFTM_SetOnMatch = ((1U << FTM_CnSC_MSA_SHIFT) | (3U << FTM_CnSC_ELSA_SHIFT)) /*!< Set output */
AnnaBridge 143:86740a56073b 113 } ftm_output_compare_mode_t;
AnnaBridge 143:86740a56073b 114
AnnaBridge 143:86740a56073b 115 /*! @brief FlexTimer input capture edge */
AnnaBridge 143:86740a56073b 116 typedef enum _ftm_input_capture_edge
AnnaBridge 143:86740a56073b 117 {
AnnaBridge 143:86740a56073b 118 kFTM_RisingEdge = (1U << FTM_CnSC_ELSA_SHIFT), /*!< Capture on rising edge only*/
AnnaBridge 143:86740a56073b 119 kFTM_FallingEdge = (2U << FTM_CnSC_ELSA_SHIFT), /*!< Capture on falling edge only*/
AnnaBridge 143:86740a56073b 120 kFTM_RiseAndFallEdge = (3U << FTM_CnSC_ELSA_SHIFT) /*!< Capture on rising or falling edge */
AnnaBridge 143:86740a56073b 121 } ftm_input_capture_edge_t;
AnnaBridge 143:86740a56073b 122
AnnaBridge 143:86740a56073b 123 /*! @brief FlexTimer dual edge capture modes */
AnnaBridge 143:86740a56073b 124 typedef enum _ftm_dual_edge_capture_mode
AnnaBridge 143:86740a56073b 125 {
AnnaBridge 143:86740a56073b 126 kFTM_OneShot = 0U, /*!< One-shot capture mode */
AnnaBridge 143:86740a56073b 127 kFTM_Continuous = (1U << FTM_CnSC_MSA_SHIFT) /*!< Continuous capture mode */
AnnaBridge 143:86740a56073b 128 } ftm_dual_edge_capture_mode_t;
AnnaBridge 143:86740a56073b 129
AnnaBridge 143:86740a56073b 130 /*! @brief FlexTimer dual edge capture parameters */
AnnaBridge 143:86740a56073b 131 typedef struct _ftm_dual_edge_capture_param
AnnaBridge 143:86740a56073b 132 {
AnnaBridge 143:86740a56073b 133 ftm_dual_edge_capture_mode_t mode; /*!< Dual Edge Capture mode */
AnnaBridge 143:86740a56073b 134 ftm_input_capture_edge_t currChanEdgeMode; /*!< Input capture edge select for channel n */
AnnaBridge 143:86740a56073b 135 ftm_input_capture_edge_t nextChanEdgeMode; /*!< Input capture edge select for channel n+1 */
AnnaBridge 143:86740a56073b 136 } ftm_dual_edge_capture_param_t;
AnnaBridge 143:86740a56073b 137
AnnaBridge 143:86740a56073b 138 /*! @brief FlexTimer quadrature decode modes */
AnnaBridge 143:86740a56073b 139 typedef enum _ftm_quad_decode_mode
AnnaBridge 143:86740a56073b 140 {
AnnaBridge 143:86740a56073b 141 kFTM_QuadPhaseEncode = 0U, /*!< Phase A and Phase B encoding mode */
AnnaBridge 143:86740a56073b 142 kFTM_QuadCountAndDir /*!< Count and direction encoding mode */
AnnaBridge 143:86740a56073b 143 } ftm_quad_decode_mode_t;
AnnaBridge 143:86740a56073b 144
AnnaBridge 143:86740a56073b 145 /*! @brief FlexTimer quadrature phase polarities */
AnnaBridge 143:86740a56073b 146 typedef enum _ftm_phase_polarity
AnnaBridge 143:86740a56073b 147 {
AnnaBridge 143:86740a56073b 148 kFTM_QuadPhaseNormal = 0U, /*!< Phase input signal is not inverted */
AnnaBridge 143:86740a56073b 149 kFTM_QuadPhaseInvert /*!< Phase input signal is inverted */
AnnaBridge 143:86740a56073b 150 } ftm_phase_polarity_t;
AnnaBridge 143:86740a56073b 151
AnnaBridge 143:86740a56073b 152 /*! @brief FlexTimer quadrature decode phase parameters */
AnnaBridge 143:86740a56073b 153 typedef struct _ftm_phase_param
AnnaBridge 143:86740a56073b 154 {
AnnaBridge 143:86740a56073b 155 bool enablePhaseFilter; /*!< True: enable phase filter; false: disable filter */
AnnaBridge 143:86740a56073b 156 uint32_t phaseFilterVal; /*!< Filter value, used only if phase filter is enabled */
AnnaBridge 143:86740a56073b 157 ftm_phase_polarity_t phasePolarity; /*!< Phase polarity */
AnnaBridge 143:86740a56073b 158 } ftm_phase_params_t;
AnnaBridge 143:86740a56073b 159
AnnaBridge 143:86740a56073b 160 /*! @brief Structure is used to hold the parameters to configure a FTM fault */
AnnaBridge 143:86740a56073b 161 typedef struct _ftm_fault_param
AnnaBridge 143:86740a56073b 162 {
AnnaBridge 143:86740a56073b 163 bool enableFaultInput; /*!< True: Fault input is enabled; false: Fault input is disabled */
AnnaBridge 143:86740a56073b 164 bool faultLevel; /*!< True: Fault polarity is active low; in other words, '0' indicates a fault;
AnnaBridge 143:86740a56073b 165 False: Fault polarity is active high */
AnnaBridge 143:86740a56073b 166 bool useFaultFilter; /*!< True: Use the filtered fault signal;
AnnaBridge 143:86740a56073b 167 False: Use the direct path from fault input */
AnnaBridge 143:86740a56073b 168 } ftm_fault_param_t;
AnnaBridge 143:86740a56073b 169
AnnaBridge 143:86740a56073b 170 /*! @brief FlexTimer pre-scaler factor for the dead time insertion*/
AnnaBridge 143:86740a56073b 171 typedef enum _ftm_deadtime_prescale
AnnaBridge 143:86740a56073b 172 {
AnnaBridge 143:86740a56073b 173 kFTM_Deadtime_Prescale_1 = 1U, /*!< Divide by 1 */
AnnaBridge 143:86740a56073b 174 kFTM_Deadtime_Prescale_4, /*!< Divide by 4 */
AnnaBridge 143:86740a56073b 175 kFTM_Deadtime_Prescale_16 /*!< Divide by 16 */
AnnaBridge 143:86740a56073b 176 } ftm_deadtime_prescale_t;
AnnaBridge 143:86740a56073b 177
AnnaBridge 143:86740a56073b 178 /*! @brief FlexTimer clock source selection*/
AnnaBridge 143:86740a56073b 179 typedef enum _ftm_clock_source
AnnaBridge 143:86740a56073b 180 {
AnnaBridge 143:86740a56073b 181 kFTM_SystemClock = 1U, /*!< System clock selected */
AnnaBridge 143:86740a56073b 182 kFTM_FixedClock, /*!< Fixed frequency clock */
AnnaBridge 143:86740a56073b 183 kFTM_ExternalClock /*!< External clock */
AnnaBridge 143:86740a56073b 184 } ftm_clock_source_t;
AnnaBridge 143:86740a56073b 185
AnnaBridge 143:86740a56073b 186 /*! @brief FlexTimer pre-scaler factor selection for the clock source*/
AnnaBridge 143:86740a56073b 187 typedef enum _ftm_clock_prescale
AnnaBridge 143:86740a56073b 188 {
AnnaBridge 143:86740a56073b 189 kFTM_Prescale_Divide_1 = 0U, /*!< Divide by 1 */
AnnaBridge 143:86740a56073b 190 kFTM_Prescale_Divide_2, /*!< Divide by 2 */
AnnaBridge 143:86740a56073b 191 kFTM_Prescale_Divide_4, /*!< Divide by 4 */
AnnaBridge 143:86740a56073b 192 kFTM_Prescale_Divide_8, /*!< Divide by 8 */
AnnaBridge 143:86740a56073b 193 kFTM_Prescale_Divide_16, /*!< Divide by 16 */
AnnaBridge 143:86740a56073b 194 kFTM_Prescale_Divide_32, /*!< Divide by 32 */
AnnaBridge 143:86740a56073b 195 kFTM_Prescale_Divide_64, /*!< Divide by 64 */
AnnaBridge 143:86740a56073b 196 kFTM_Prescale_Divide_128 /*!< Divide by 128 */
AnnaBridge 143:86740a56073b 197 } ftm_clock_prescale_t;
AnnaBridge 143:86740a56073b 198
AnnaBridge 143:86740a56073b 199 /*! @brief Options for the FlexTimer behaviour in BDM Mode */
AnnaBridge 143:86740a56073b 200 typedef enum _ftm_bdm_mode
AnnaBridge 143:86740a56073b 201 {
AnnaBridge 143:86740a56073b 202 kFTM_BdmMode_0 = 0U,
AnnaBridge 143:86740a56073b 203 /*!< FTM counter stopped, CH(n)F bit can be set, FTM channels in functional mode, writes to MOD,CNTIN and C(n)V
AnnaBridge 143:86740a56073b 204 registers bypass the register buffers */
AnnaBridge 143:86740a56073b 205 kFTM_BdmMode_1,
AnnaBridge 143:86740a56073b 206 /*!< FTM counter stopped, CH(n)F bit is not set, FTM channels outputs are forced to their safe value , writes to
AnnaBridge 143:86740a56073b 207 MOD,CNTIN and C(n)V registers bypass the register buffers */
AnnaBridge 143:86740a56073b 208 kFTM_BdmMode_2,
AnnaBridge 143:86740a56073b 209 /*!< FTM counter stopped, CH(n)F bit is not set, FTM channels outputs are frozen when chip enters in BDM mode,
AnnaBridge 143:86740a56073b 210 writes to MOD,CNTIN and C(n)V registers bypass the register buffers */
AnnaBridge 143:86740a56073b 211 kFTM_BdmMode_3
AnnaBridge 143:86740a56073b 212 /*!< FTM counter in functional mode, CH(n)F bit can be set, FTM channels in functional mode, writes to MOD,CNTIN and
AnnaBridge 143:86740a56073b 213 C(n)V registers is in fully functional mode */
AnnaBridge 143:86740a56073b 214 } ftm_bdm_mode_t;
AnnaBridge 143:86740a56073b 215
AnnaBridge 143:86740a56073b 216 /*! @brief Options for the FTM fault control mode */
AnnaBridge 143:86740a56073b 217 typedef enum _ftm_fault_mode
AnnaBridge 143:86740a56073b 218 {
AnnaBridge 143:86740a56073b 219 kFTM_Fault_Disable = 0U, /*!< Fault control is disabled for all channels */
AnnaBridge 143:86740a56073b 220 kFTM_Fault_EvenChnls, /*!< Enabled for even channels only(0,2,4,6) with manual fault clearing */
AnnaBridge 143:86740a56073b 221 kFTM_Fault_AllChnlsMan, /*!< Enabled for all channels with manual fault clearing */
AnnaBridge 143:86740a56073b 222 kFTM_Fault_AllChnlsAuto /*!< Enabled for all channels with automatic fault clearing */
AnnaBridge 143:86740a56073b 223 } ftm_fault_mode_t;
AnnaBridge 143:86740a56073b 224
AnnaBridge 143:86740a56073b 225 /*!
AnnaBridge 143:86740a56073b 226 * @brief FTM external trigger options
AnnaBridge 143:86740a56073b 227 * @note Actual available external trigger sources are SoC-specific
AnnaBridge 143:86740a56073b 228 */
AnnaBridge 143:86740a56073b 229 typedef enum _ftm_external_trigger
AnnaBridge 143:86740a56073b 230 {
AnnaBridge 143:86740a56073b 231 kFTM_Chnl0Trigger = (1U << 4), /*!< Generate trigger when counter equals chnl 0 CnV reg */
AnnaBridge 143:86740a56073b 232 kFTM_Chnl1Trigger = (1U << 5), /*!< Generate trigger when counter equals chnl 1 CnV reg */
AnnaBridge 143:86740a56073b 233 kFTM_Chnl2Trigger = (1U << 0), /*!< Generate trigger when counter equals chnl 2 CnV reg */
AnnaBridge 143:86740a56073b 234 kFTM_Chnl3Trigger = (1U << 1), /*!< Generate trigger when counter equals chnl 3 CnV reg */
AnnaBridge 143:86740a56073b 235 kFTM_Chnl4Trigger = (1U << 2), /*!< Generate trigger when counter equals chnl 4 CnV reg */
AnnaBridge 143:86740a56073b 236 kFTM_Chnl5Trigger = (1U << 3), /*!< Generate trigger when counter equals chnl 5 CnV reg */
AnnaBridge 143:86740a56073b 237 kFTM_Chnl6Trigger =
AnnaBridge 143:86740a56073b 238 (1U << 8), /*!< Available on certain SoC's, generate trigger when counter equals chnl 6 CnV reg */
AnnaBridge 143:86740a56073b 239 kFTM_Chnl7Trigger =
AnnaBridge 143:86740a56073b 240 (1U << 9), /*!< Available on certain SoC's, generate trigger when counter equals chnl 7 CnV reg */
AnnaBridge 143:86740a56073b 241 kFTM_InitTrigger = (1U << 6), /*!< Generate Trigger when counter is updated with CNTIN */
AnnaBridge 143:86740a56073b 242 kFTM_ReloadInitTrigger = (1U << 7) /*!< Available on certain SoC's, trigger on reload point */
AnnaBridge 143:86740a56073b 243 } ftm_external_trigger_t;
AnnaBridge 143:86740a56073b 244
AnnaBridge 143:86740a56073b 245 /*! @brief FlexTimer PWM sync options to update registers with buffer */
AnnaBridge 143:86740a56073b 246 typedef enum _ftm_pwm_sync_method
AnnaBridge 143:86740a56073b 247 {
AnnaBridge 143:86740a56073b 248 kFTM_SoftwareTrigger = FTM_SYNC_SWSYNC_MASK, /*!< Software triggers PWM sync */
AnnaBridge 143:86740a56073b 249 kFTM_HardwareTrigger_0 = FTM_SYNC_TRIG0_MASK, /*!< Hardware trigger 0 causes PWM sync */
AnnaBridge 143:86740a56073b 250 kFTM_HardwareTrigger_1 = FTM_SYNC_TRIG1_MASK, /*!< Hardware trigger 1 causes PWM sync */
AnnaBridge 143:86740a56073b 251 kFTM_HardwareTrigger_2 = FTM_SYNC_TRIG2_MASK /*!< Hardware trigger 2 causes PWM sync */
AnnaBridge 143:86740a56073b 252 } ftm_pwm_sync_method_t;
AnnaBridge 143:86740a56073b 253
AnnaBridge 143:86740a56073b 254 /*!
AnnaBridge 143:86740a56073b 255 * @brief FTM options available as loading point for register reload
AnnaBridge 143:86740a56073b 256 * @note Actual available reload points are SoC-specific
AnnaBridge 143:86740a56073b 257 */
AnnaBridge 143:86740a56073b 258 typedef enum _ftm_reload_point
AnnaBridge 143:86740a56073b 259 {
AnnaBridge 143:86740a56073b 260 kFTM_Chnl0Match = (1U << 0), /*!< Channel 0 match included as a reload point */
AnnaBridge 143:86740a56073b 261 kFTM_Chnl1Match = (1U << 1), /*!< Channel 1 match included as a reload point */
AnnaBridge 143:86740a56073b 262 kFTM_Chnl2Match = (1U << 2), /*!< Channel 2 match included as a reload point */
AnnaBridge 143:86740a56073b 263 kFTM_Chnl3Match = (1U << 3), /*!< Channel 3 match included as a reload point */
AnnaBridge 143:86740a56073b 264 kFTM_Chnl4Match = (1U << 4), /*!< Channel 4 match included as a reload point */
AnnaBridge 143:86740a56073b 265 kFTM_Chnl5Match = (1U << 5), /*!< Channel 5 match included as a reload point */
AnnaBridge 143:86740a56073b 266 kFTM_Chnl6Match = (1U << 6), /*!< Channel 6 match included as a reload point */
AnnaBridge 143:86740a56073b 267 kFTM_Chnl7Match = (1U << 7), /*!< Channel 7 match included as a reload point */
AnnaBridge 143:86740a56073b 268 kFTM_CntMax = (1U << 8), /*!< Use in up-down count mode only, reload when counter reaches the maximum value */
AnnaBridge 143:86740a56073b 269 kFTM_CntMin = (1U << 9), /*!< Use in up-down count mode only, reload when counter reaches the minimum value */
AnnaBridge 143:86740a56073b 270 kFTM_HalfCycMatch = (1U << 10) /*!< Available on certain SoC's, half cycle match reload point */
AnnaBridge 143:86740a56073b 271 } ftm_reload_point_t;
AnnaBridge 143:86740a56073b 272
AnnaBridge 143:86740a56073b 273 /*!
AnnaBridge 143:86740a56073b 274 * @brief List of FTM interrupts
AnnaBridge 143:86740a56073b 275 * @note Actual available interrupts are SoC-specific
AnnaBridge 143:86740a56073b 276 */
AnnaBridge 143:86740a56073b 277 typedef enum _ftm_interrupt_enable
AnnaBridge 143:86740a56073b 278 {
AnnaBridge 143:86740a56073b 279 kFTM_Chnl0InterruptEnable = (1U << 0), /*!< Channel 0 interrupt */
AnnaBridge 143:86740a56073b 280 kFTM_Chnl1InterruptEnable = (1U << 1), /*!< Channel 1 interrupt */
AnnaBridge 143:86740a56073b 281 kFTM_Chnl2InterruptEnable = (1U << 2), /*!< Channel 2 interrupt */
AnnaBridge 143:86740a56073b 282 kFTM_Chnl3InterruptEnable = (1U << 3), /*!< Channel 3 interrupt */
AnnaBridge 143:86740a56073b 283 kFTM_Chnl4InterruptEnable = (1U << 4), /*!< Channel 4 interrupt */
AnnaBridge 143:86740a56073b 284 kFTM_Chnl5InterruptEnable = (1U << 5), /*!< Channel 5 interrupt */
AnnaBridge 143:86740a56073b 285 kFTM_Chnl6InterruptEnable = (1U << 6), /*!< Channel 6 interrupt */
AnnaBridge 143:86740a56073b 286 kFTM_Chnl7InterruptEnable = (1U << 7), /*!< Channel 7 interrupt */
AnnaBridge 143:86740a56073b 287 kFTM_FaultInterruptEnable = (1U << 8), /*!< Fault interrupt */
AnnaBridge 143:86740a56073b 288 kFTM_TimeOverflowInterruptEnable = (1U << 9), /*!< Time overflow interrupt */
AnnaBridge 143:86740a56073b 289 kFTM_ReloadInterruptEnable = (1U << 10) /*!< Reload interrupt; Available only on certain SoC's */
AnnaBridge 143:86740a56073b 290 } ftm_interrupt_enable_t;
AnnaBridge 143:86740a56073b 291
AnnaBridge 143:86740a56073b 292 /*!
AnnaBridge 143:86740a56073b 293 * @brief List of FTM flags
AnnaBridge 143:86740a56073b 294 * @note Actual available flags are SoC-specific
AnnaBridge 143:86740a56073b 295 */
AnnaBridge 143:86740a56073b 296 typedef enum _ftm_status_flags
AnnaBridge 143:86740a56073b 297 {
AnnaBridge 143:86740a56073b 298 kFTM_Chnl0Flag = (1U << 0), /*!< Channel 0 Flag */
AnnaBridge 143:86740a56073b 299 kFTM_Chnl1Flag = (1U << 1), /*!< Channel 1 Flag */
AnnaBridge 143:86740a56073b 300 kFTM_Chnl2Flag = (1U << 2), /*!< Channel 2 Flag */
AnnaBridge 143:86740a56073b 301 kFTM_Chnl3Flag = (1U << 3), /*!< Channel 3 Flag */
AnnaBridge 143:86740a56073b 302 kFTM_Chnl4Flag = (1U << 4), /*!< Channel 4 Flag */
AnnaBridge 143:86740a56073b 303 kFTM_Chnl5Flag = (1U << 5), /*!< Channel 5 Flag */
AnnaBridge 143:86740a56073b 304 kFTM_Chnl6Flag = (1U << 6), /*!< Channel 6 Flag */
AnnaBridge 143:86740a56073b 305 kFTM_Chnl7Flag = (1U << 7), /*!< Channel 7 Flag */
AnnaBridge 143:86740a56073b 306 kFTM_FaultFlag = (1U << 8), /*!< Fault Flag */
AnnaBridge 143:86740a56073b 307 kFTM_TimeOverflowFlag = (1U << 9), /*!< Time overflow Flag */
AnnaBridge 143:86740a56073b 308 kFTM_ChnlTriggerFlag = (1U << 10), /*!< Channel trigger Flag */
AnnaBridge 143:86740a56073b 309 kFTM_ReloadFlag = (1U << 11) /*!< Reload Flag; Available only on certain SoC's */
AnnaBridge 143:86740a56073b 310 } ftm_status_flags_t;
AnnaBridge 143:86740a56073b 311
AnnaBridge 143:86740a56073b 312 /*!
AnnaBridge 143:86740a56073b 313 * @brief List of FTM Quad Decoder flags.
AnnaBridge 143:86740a56073b 314 */
AnnaBridge 143:86740a56073b 315 enum _ftm_quad_decoder_flags
AnnaBridge 143:86740a56073b 316 {
AnnaBridge 143:86740a56073b 317 kFTM_QuadDecoderCountingIncreaseFlag = FTM_QDCTRL_QUADIR_MASK, /*!< Counting direction is increasing (FTM counter
AnnaBridge 143:86740a56073b 318 increment), or the direction is decreasing. */
AnnaBridge 143:86740a56073b 319 kFTM_QuadDecoderCountingOverflowOnTopFlag = FTM_QDCTRL_TOFDIR_MASK, /*!< Indicates if the TOF bit was set on the top
AnnaBridge 143:86740a56073b 320 or the bottom of counting. */
AnnaBridge 143:86740a56073b 321 };
AnnaBridge 143:86740a56073b 322
AnnaBridge 143:86740a56073b 323 /*!
AnnaBridge 143:86740a56073b 324 * @brief FTM configuration structure
AnnaBridge 143:86740a56073b 325 *
AnnaBridge 143:86740a56073b 326 * This structure holds the configuration settings for the FTM peripheral. To initialize this
AnnaBridge 143:86740a56073b 327 * structure to reasonable defaults, call the FTM_GetDefaultConfig() function and pass a
AnnaBridge 143:86740a56073b 328 * pointer to the configuration structure instance.
AnnaBridge 143:86740a56073b 329 *
AnnaBridge 143:86740a56073b 330 * The configuration structure can be made constant so as to reside in flash.
AnnaBridge 143:86740a56073b 331 */
AnnaBridge 143:86740a56073b 332 typedef struct _ftm_config
AnnaBridge 143:86740a56073b 333 {
AnnaBridge 143:86740a56073b 334 ftm_clock_prescale_t prescale; /*!< FTM clock prescale value */
AnnaBridge 143:86740a56073b 335 ftm_bdm_mode_t bdmMode; /*!< FTM behavior in BDM mode */
AnnaBridge 143:86740a56073b 336 uint32_t pwmSyncMode; /*!< Synchronization methods to use to update buffered registers; Multiple
AnnaBridge 143:86740a56073b 337 update modes can be used by providing an OR'ed list of options
AnnaBridge 143:86740a56073b 338 available in enumeration ::ftm_pwm_sync_method_t. */
AnnaBridge 143:86740a56073b 339 uint32_t reloadPoints; /*!< FTM reload points; When using this, the PWM
AnnaBridge 143:86740a56073b 340 synchronization is not required. Multiple reload points can be used by providing
AnnaBridge 143:86740a56073b 341 an OR'ed list of options available in
AnnaBridge 143:86740a56073b 342 enumeration ::ftm_reload_point_t. */
AnnaBridge 143:86740a56073b 343 ftm_fault_mode_t faultMode; /*!< FTM fault control mode */
AnnaBridge 143:86740a56073b 344 uint8_t faultFilterValue; /*!< Fault input filter value */
AnnaBridge 143:86740a56073b 345 ftm_deadtime_prescale_t deadTimePrescale; /*!< The dead time prescalar value */
AnnaBridge 143:86740a56073b 346 uint32_t deadTimeValue; /*!< The dead time value
AnnaBridge 143:86740a56073b 347 deadTimeValue's available range is 0-1023 when register has DTVALEX,
AnnaBridge 143:86740a56073b 348 otherwise its available range is 0-63. */
AnnaBridge 143:86740a56073b 349 uint32_t extTriggers; /*!< External triggers to enable. Multiple trigger sources can be
AnnaBridge 143:86740a56073b 350 enabled by providing an OR'ed list of options available in
AnnaBridge 143:86740a56073b 351 enumeration ::ftm_external_trigger_t. */
AnnaBridge 143:86740a56073b 352 uint8_t chnlInitState; /*!< Defines the initialization value of the channels in OUTINT register */
AnnaBridge 143:86740a56073b 353 uint8_t chnlPolarity; /*!< Defines the output polarity of the channels in POL register */
AnnaBridge 143:86740a56073b 354 bool useGlobalTimeBase; /*!< True: Use of an external global time base is enabled;
AnnaBridge 143:86740a56073b 355 False: disabled */
AnnaBridge 143:86740a56073b 356 } ftm_config_t;
AnnaBridge 143:86740a56073b 357
AnnaBridge 143:86740a56073b 358 /*******************************************************************************
AnnaBridge 143:86740a56073b 359 * API
AnnaBridge 143:86740a56073b 360 ******************************************************************************/
AnnaBridge 143:86740a56073b 361
AnnaBridge 143:86740a56073b 362 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 363 extern "C" {
AnnaBridge 143:86740a56073b 364 #endif
AnnaBridge 143:86740a56073b 365
AnnaBridge 143:86740a56073b 366 /*!
AnnaBridge 143:86740a56073b 367 * @name Initialization and deinitialization
AnnaBridge 143:86740a56073b 368 * @{
AnnaBridge 143:86740a56073b 369 */
AnnaBridge 143:86740a56073b 370
AnnaBridge 143:86740a56073b 371 /*!
AnnaBridge 143:86740a56073b 372 * @brief Ungates the FTM clock and configures the peripheral for basic operation.
AnnaBridge 143:86740a56073b 373 *
AnnaBridge 143:86740a56073b 374 * @note This API should be called at the beginning of the application which is using the FTM driver.
AnnaBridge 143:86740a56073b 375 *
AnnaBridge 143:86740a56073b 376 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 377 * @param config Pointer to the user configuration structure.
AnnaBridge 143:86740a56073b 378 *
AnnaBridge 143:86740a56073b 379 * @return kStatus_Success indicates success; Else indicates failure.
AnnaBridge 143:86740a56073b 380 */
AnnaBridge 143:86740a56073b 381 status_t FTM_Init(FTM_Type *base, const ftm_config_t *config);
AnnaBridge 143:86740a56073b 382
AnnaBridge 143:86740a56073b 383 /*!
AnnaBridge 143:86740a56073b 384 * @brief Gates the FTM clock.
AnnaBridge 143:86740a56073b 385 *
AnnaBridge 143:86740a56073b 386 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 387 */
AnnaBridge 143:86740a56073b 388 void FTM_Deinit(FTM_Type *base);
AnnaBridge 143:86740a56073b 389
AnnaBridge 143:86740a56073b 390 /*!
AnnaBridge 143:86740a56073b 391 * @brief Fills in the FTM configuration structure with the default settings.
AnnaBridge 143:86740a56073b 392 *
AnnaBridge 143:86740a56073b 393 * The default values are:
AnnaBridge 143:86740a56073b 394 * @code
AnnaBridge 143:86740a56073b 395 * config->prescale = kFTM_Prescale_Divide_1;
AnnaBridge 143:86740a56073b 396 * config->bdmMode = kFTM_BdmMode_0;
AnnaBridge 143:86740a56073b 397 * config->pwmSyncMode = kFTM_SoftwareTrigger;
AnnaBridge 143:86740a56073b 398 * config->reloadPoints = 0;
AnnaBridge 143:86740a56073b 399 * config->faultMode = kFTM_Fault_Disable;
AnnaBridge 143:86740a56073b 400 * config->faultFilterValue = 0;
AnnaBridge 143:86740a56073b 401 * config->deadTimePrescale = kFTM_Deadtime_Prescale_1;
AnnaBridge 143:86740a56073b 402 * config->deadTimeValue = 0;
AnnaBridge 143:86740a56073b 403 * config->extTriggers = 0;
AnnaBridge 143:86740a56073b 404 * config->chnlInitState = 0;
AnnaBridge 143:86740a56073b 405 * config->chnlPolarity = 0;
AnnaBridge 143:86740a56073b 406 * config->useGlobalTimeBase = false;
AnnaBridge 143:86740a56073b 407 * @endcode
AnnaBridge 143:86740a56073b 408 * @param config Pointer to the user configuration structure.
AnnaBridge 143:86740a56073b 409 */
AnnaBridge 143:86740a56073b 410 void FTM_GetDefaultConfig(ftm_config_t *config);
AnnaBridge 143:86740a56073b 411
AnnaBridge 143:86740a56073b 412 /*! @}*/
AnnaBridge 143:86740a56073b 413
AnnaBridge 143:86740a56073b 414 /*!
AnnaBridge 143:86740a56073b 415 * @name Channel mode operations
AnnaBridge 143:86740a56073b 416 * @{
AnnaBridge 143:86740a56073b 417 */
AnnaBridge 143:86740a56073b 418
AnnaBridge 143:86740a56073b 419 /*!
AnnaBridge 143:86740a56073b 420 * @brief Configures the PWM signal parameters.
AnnaBridge 143:86740a56073b 421 *
AnnaBridge 143:86740a56073b 422 * Call this function to configure the PWM signal period, mode, duty cycle, and edge. Use this
AnnaBridge 143:86740a56073b 423 * function to configure all FTM channels that are used to output a PWM signal.
AnnaBridge 143:86740a56073b 424 *
AnnaBridge 143:86740a56073b 425 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 426 * @param chnlParams Array of PWM channel parameters to configure the channel(s)
AnnaBridge 143:86740a56073b 427 * @param numOfChnls Number of channels to configure; This should be the size of the array passed in
AnnaBridge 143:86740a56073b 428 * @param mode PWM operation mode, options available in enumeration ::ftm_pwm_mode_t
AnnaBridge 143:86740a56073b 429 * @param pwmFreq_Hz PWM signal frequency in Hz
AnnaBridge 143:86740a56073b 430 * @param srcClock_Hz FTM counter clock in Hz
AnnaBridge 143:86740a56073b 431 *
AnnaBridge 143:86740a56073b 432 * @return kStatus_Success if the PWM setup was successful
AnnaBridge 143:86740a56073b 433 * kStatus_Error on failure
AnnaBridge 143:86740a56073b 434 */
AnnaBridge 143:86740a56073b 435 status_t FTM_SetupPwm(FTM_Type *base,
AnnaBridge 143:86740a56073b 436 const ftm_chnl_pwm_signal_param_t *chnlParams,
AnnaBridge 143:86740a56073b 437 uint8_t numOfChnls,
AnnaBridge 143:86740a56073b 438 ftm_pwm_mode_t mode,
AnnaBridge 143:86740a56073b 439 uint32_t pwmFreq_Hz,
AnnaBridge 143:86740a56073b 440 uint32_t srcClock_Hz);
AnnaBridge 143:86740a56073b 441
AnnaBridge 143:86740a56073b 442 /*!
AnnaBridge 143:86740a56073b 443 * @brief Updates the duty cycle of an active PWM signal.
AnnaBridge 143:86740a56073b 444 *
AnnaBridge 143:86740a56073b 445 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 446 * @param chnlNumber The channel/channel pair number. In combined mode, this represents
AnnaBridge 143:86740a56073b 447 * the channel pair number
AnnaBridge 143:86740a56073b 448 * @param currentPwmMode The current PWM mode set during PWM setup
AnnaBridge 143:86740a56073b 449 * @param dutyCyclePercent New PWM pulse width; The value should be between 0 to 100
AnnaBridge 143:86740a56073b 450 * 0=inactive signal(0% duty cycle)...
AnnaBridge 143:86740a56073b 451 * 100=active signal (100% duty cycle)
AnnaBridge 143:86740a56073b 452 */
AnnaBridge 143:86740a56073b 453 void FTM_UpdatePwmDutycycle(FTM_Type *base,
AnnaBridge 143:86740a56073b 454 ftm_chnl_t chnlNumber,
AnnaBridge 143:86740a56073b 455 ftm_pwm_mode_t currentPwmMode,
AnnaBridge 143:86740a56073b 456 uint8_t dutyCyclePercent);
AnnaBridge 143:86740a56073b 457
AnnaBridge 143:86740a56073b 458 /*!
AnnaBridge 143:86740a56073b 459 * @brief Updates the edge level selection for a channel.
AnnaBridge 143:86740a56073b 460 *
AnnaBridge 143:86740a56073b 461 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 462 * @param chnlNumber The channel number
AnnaBridge 143:86740a56073b 463 * @param level The level to be set to the ELSnB:ELSnA field; Valid values are 00, 01, 10, 11.
AnnaBridge 143:86740a56073b 464 * See the Kinetis SoC reference manual for details about this field.
AnnaBridge 143:86740a56073b 465 */
AnnaBridge 143:86740a56073b 466 void FTM_UpdateChnlEdgeLevelSelect(FTM_Type *base, ftm_chnl_t chnlNumber, uint8_t level);
AnnaBridge 143:86740a56073b 467
AnnaBridge 143:86740a56073b 468 /*!
AnnaBridge 143:86740a56073b 469 * @brief Enables capturing an input signal on the channel using the function parameters.
AnnaBridge 143:86740a56073b 470 *
AnnaBridge 143:86740a56073b 471 * When the edge specified in the captureMode argument occurs on the channel, the FTM counter is
AnnaBridge 143:86740a56073b 472 * captured into the CnV register. The user has to read the CnV register separately to get this
AnnaBridge 143:86740a56073b 473 * value. The filter function is disabled if the filterVal argument passed in is 0. The filter
AnnaBridge 143:86740a56073b 474 * function is available only for channels 0, 1, 2, 3.
AnnaBridge 143:86740a56073b 475 *
AnnaBridge 143:86740a56073b 476 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 477 * @param chnlNumber The channel number
AnnaBridge 143:86740a56073b 478 * @param captureMode Specifies which edge to capture
AnnaBridge 143:86740a56073b 479 * @param filterValue Filter value, specify 0 to disable filter. Available only for channels 0-3.
AnnaBridge 143:86740a56073b 480 */
AnnaBridge 143:86740a56073b 481 void FTM_SetupInputCapture(FTM_Type *base,
AnnaBridge 143:86740a56073b 482 ftm_chnl_t chnlNumber,
AnnaBridge 143:86740a56073b 483 ftm_input_capture_edge_t captureMode,
AnnaBridge 143:86740a56073b 484 uint32_t filterValue);
AnnaBridge 143:86740a56073b 485
AnnaBridge 143:86740a56073b 486 /*!
AnnaBridge 143:86740a56073b 487 * @brief Configures the FTM to generate timed pulses.
AnnaBridge 143:86740a56073b 488 *
AnnaBridge 143:86740a56073b 489 * When the FTM counter matches the value of compareVal argument (this is written into CnV reg),
AnnaBridge 143:86740a56073b 490 * the channel output is changed based on what is specified in the compareMode argument.
AnnaBridge 143:86740a56073b 491 *
AnnaBridge 143:86740a56073b 492 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 493 * @param chnlNumber The channel number
AnnaBridge 143:86740a56073b 494 * @param compareMode Action to take on the channel output when the compare condition is met
AnnaBridge 143:86740a56073b 495 * @param compareValue Value to be programmed in the CnV register.
AnnaBridge 143:86740a56073b 496 */
AnnaBridge 143:86740a56073b 497 void FTM_SetupOutputCompare(FTM_Type *base,
AnnaBridge 143:86740a56073b 498 ftm_chnl_t chnlNumber,
AnnaBridge 143:86740a56073b 499 ftm_output_compare_mode_t compareMode,
AnnaBridge 143:86740a56073b 500 uint32_t compareValue);
AnnaBridge 143:86740a56073b 501
AnnaBridge 143:86740a56073b 502 /*!
AnnaBridge 143:86740a56073b 503 * @brief Configures the dual edge capture mode of the FTM.
AnnaBridge 143:86740a56073b 504 *
AnnaBridge 143:86740a56073b 505 * This function sets up the dual edge capture mode on a channel pair. The capture edge for the
AnnaBridge 143:86740a56073b 506 * channel pair and the capture mode (one-shot or continuous) is specified in the parameter
AnnaBridge 143:86740a56073b 507 * argument. The filter function is disabled if the filterVal argument passed is zero. The filter
AnnaBridge 143:86740a56073b 508 * function is available only on channels 0 and 2. The user has to read the channel CnV registers
AnnaBridge 143:86740a56073b 509 * separately to get the capture values.
AnnaBridge 143:86740a56073b 510 *
AnnaBridge 143:86740a56073b 511 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 512 * @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
AnnaBridge 143:86740a56073b 513 * @param edgeParam Sets up the dual edge capture function
AnnaBridge 143:86740a56073b 514 * @param filterValue Filter value, specify 0 to disable filter. Available only for channel pair 0 and 1.
AnnaBridge 143:86740a56073b 515 */
AnnaBridge 143:86740a56073b 516 void FTM_SetupDualEdgeCapture(FTM_Type *base,
AnnaBridge 143:86740a56073b 517 ftm_chnl_t chnlPairNumber,
AnnaBridge 143:86740a56073b 518 const ftm_dual_edge_capture_param_t *edgeParam,
AnnaBridge 143:86740a56073b 519 uint32_t filterValue);
AnnaBridge 143:86740a56073b 520
AnnaBridge 143:86740a56073b 521 /*! @}*/
AnnaBridge 143:86740a56073b 522
AnnaBridge 143:86740a56073b 523 /*!
AnnaBridge 143:86740a56073b 524 * @brief Sets up the working of the FTM fault protection.
AnnaBridge 143:86740a56073b 525 *
AnnaBridge 143:86740a56073b 526 * FTM can have up to 4 fault inputs. This function sets up fault parameters, fault level, and a filter.
AnnaBridge 143:86740a56073b 527 *
AnnaBridge 143:86740a56073b 528 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 529 * @param faultNumber FTM fault to configure.
AnnaBridge 143:86740a56073b 530 * @param faultParams Parameters passed in to set up the fault
AnnaBridge 143:86740a56073b 531 */
AnnaBridge 143:86740a56073b 532 void FTM_SetupFault(FTM_Type *base, ftm_fault_input_t faultNumber, const ftm_fault_param_t *faultParams);
AnnaBridge 143:86740a56073b 533
AnnaBridge 143:86740a56073b 534 /*!
AnnaBridge 143:86740a56073b 535 * @name Interrupt Interface
AnnaBridge 143:86740a56073b 536 * @{
AnnaBridge 143:86740a56073b 537 */
AnnaBridge 143:86740a56073b 538
AnnaBridge 143:86740a56073b 539 /*!
AnnaBridge 143:86740a56073b 540 * @brief Enables the selected FTM interrupts.
AnnaBridge 143:86740a56073b 541 *
AnnaBridge 143:86740a56073b 542 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 543 * @param mask The interrupts to enable. This is a logical OR of members of the
AnnaBridge 143:86740a56073b 544 * enumeration ::ftm_interrupt_enable_t
AnnaBridge 143:86740a56073b 545 */
AnnaBridge 143:86740a56073b 546 void FTM_EnableInterrupts(FTM_Type *base, uint32_t mask);
AnnaBridge 143:86740a56073b 547
AnnaBridge 143:86740a56073b 548 /*!
AnnaBridge 143:86740a56073b 549 * @brief Disables the selected FTM interrupts.
AnnaBridge 143:86740a56073b 550 *
AnnaBridge 143:86740a56073b 551 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 552 * @param mask The interrupts to enable. This is a logical OR of members of the
AnnaBridge 143:86740a56073b 553 * enumeration ::ftm_interrupt_enable_t
AnnaBridge 143:86740a56073b 554 */
AnnaBridge 143:86740a56073b 555 void FTM_DisableInterrupts(FTM_Type *base, uint32_t mask);
AnnaBridge 143:86740a56073b 556
AnnaBridge 143:86740a56073b 557 /*!
AnnaBridge 143:86740a56073b 558 * @brief Gets the enabled FTM interrupts.
AnnaBridge 143:86740a56073b 559 *
AnnaBridge 143:86740a56073b 560 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 561 *
AnnaBridge 143:86740a56073b 562 * @return The enabled interrupts. This is the logical OR of members of the
AnnaBridge 143:86740a56073b 563 * enumeration ::ftm_interrupt_enable_t
AnnaBridge 143:86740a56073b 564 */
AnnaBridge 143:86740a56073b 565 uint32_t FTM_GetEnabledInterrupts(FTM_Type *base);
AnnaBridge 143:86740a56073b 566
AnnaBridge 143:86740a56073b 567 /*! @}*/
AnnaBridge 143:86740a56073b 568
AnnaBridge 143:86740a56073b 569 /*!
AnnaBridge 143:86740a56073b 570 * @name Status Interface
AnnaBridge 143:86740a56073b 571 * @{
AnnaBridge 143:86740a56073b 572 */
AnnaBridge 143:86740a56073b 573
AnnaBridge 143:86740a56073b 574 /*!
AnnaBridge 143:86740a56073b 575 * @brief Gets the FTM status flags.
AnnaBridge 143:86740a56073b 576 *
AnnaBridge 143:86740a56073b 577 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 578 *
AnnaBridge 143:86740a56073b 579 * @return The status flags. This is the logical OR of members of the
AnnaBridge 143:86740a56073b 580 * enumeration ::ftm_status_flags_t
AnnaBridge 143:86740a56073b 581 */
AnnaBridge 143:86740a56073b 582 uint32_t FTM_GetStatusFlags(FTM_Type *base);
AnnaBridge 143:86740a56073b 583
AnnaBridge 143:86740a56073b 584 /*!
AnnaBridge 143:86740a56073b 585 * @brief Clears the FTM status flags.
AnnaBridge 143:86740a56073b 586 *
AnnaBridge 143:86740a56073b 587 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 588 * @param mask The status flags to clear. This is a logical OR of members of the
AnnaBridge 143:86740a56073b 589 * enumeration ::ftm_status_flags_t
AnnaBridge 143:86740a56073b 590 */
AnnaBridge 143:86740a56073b 591 void FTM_ClearStatusFlags(FTM_Type *base, uint32_t mask);
AnnaBridge 143:86740a56073b 592
AnnaBridge 143:86740a56073b 593 /*! @}*/
AnnaBridge 143:86740a56073b 594
AnnaBridge 143:86740a56073b 595 /*!
AnnaBridge 143:86740a56073b 596 * @name Read and write the timer period
AnnaBridge 143:86740a56073b 597 * @{
AnnaBridge 143:86740a56073b 598 */
AnnaBridge 143:86740a56073b 599
AnnaBridge 143:86740a56073b 600 /*!
AnnaBridge 143:86740a56073b 601 * @brief Sets the timer period in units of ticks.
AnnaBridge 143:86740a56073b 602 *
AnnaBridge 143:86740a56073b 603 * Timers counts from 0 until it equals the count value set here. The count value is written to
AnnaBridge 143:86740a56073b 604 * the MOD register.
AnnaBridge 143:86740a56073b 605 *
AnnaBridge 143:86740a56073b 606 * @note
AnnaBridge 143:86740a56073b 607 * 1. This API allows the user to use the FTM module as a timer. Do not mix usage
AnnaBridge 143:86740a56073b 608 * of this API with FTM's PWM setup API's.
AnnaBridge 143:86740a56073b 609 * 2. Call the utility macros provided in the fsl_common.h to convert usec or msec to ticks.
AnnaBridge 143:86740a56073b 610 *
AnnaBridge 143:86740a56073b 611 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 612 * @param ticks A timer period in units of ticks, which should be equal or greater than 1.
AnnaBridge 143:86740a56073b 613 */
AnnaBridge 143:86740a56073b 614 static inline void FTM_SetTimerPeriod(FTM_Type *base, uint32_t ticks)
AnnaBridge 143:86740a56073b 615 {
AnnaBridge 143:86740a56073b 616 base->MOD = ticks;
AnnaBridge 143:86740a56073b 617 }
AnnaBridge 143:86740a56073b 618
AnnaBridge 143:86740a56073b 619 /*!
AnnaBridge 143:86740a56073b 620 * @brief Reads the current timer counting value.
AnnaBridge 143:86740a56073b 621 *
AnnaBridge 143:86740a56073b 622 * This function returns the real-time timer counting value in a range from 0 to a
AnnaBridge 143:86740a56073b 623 * timer period.
AnnaBridge 143:86740a56073b 624 *
AnnaBridge 143:86740a56073b 625 * @note Call the utility macros provided in the fsl_common.h to convert ticks to usec or msec.
AnnaBridge 143:86740a56073b 626 *
AnnaBridge 143:86740a56073b 627 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 628 *
AnnaBridge 143:86740a56073b 629 * @return The current counter value in ticks
AnnaBridge 143:86740a56073b 630 */
AnnaBridge 143:86740a56073b 631 static inline uint32_t FTM_GetCurrentTimerCount(FTM_Type *base)
AnnaBridge 143:86740a56073b 632 {
AnnaBridge 143:86740a56073b 633 return (uint32_t)((base->CNT & FTM_CNT_COUNT_MASK) >> FTM_CNT_COUNT_SHIFT);
AnnaBridge 143:86740a56073b 634 }
AnnaBridge 143:86740a56073b 635
AnnaBridge 143:86740a56073b 636 /*! @}*/
AnnaBridge 143:86740a56073b 637 /*!
AnnaBridge 143:86740a56073b 638 * @name Timer Start and Stop
AnnaBridge 143:86740a56073b 639 * @{
AnnaBridge 143:86740a56073b 640 */
AnnaBridge 143:86740a56073b 641
AnnaBridge 143:86740a56073b 642 /*!
AnnaBridge 143:86740a56073b 643 * @brief Starts the FTM counter.
AnnaBridge 143:86740a56073b 644 *
AnnaBridge 143:86740a56073b 645 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 646 * @param clockSource FTM clock source; After the clock source is set, the counter starts running.
AnnaBridge 143:86740a56073b 647 */
AnnaBridge 143:86740a56073b 648 static inline void FTM_StartTimer(FTM_Type *base, ftm_clock_source_t clockSource)
AnnaBridge 143:86740a56073b 649 {
AnnaBridge 143:86740a56073b 650 uint32_t reg = base->SC;
AnnaBridge 143:86740a56073b 651
AnnaBridge 143:86740a56073b 652 reg &= ~(FTM_SC_CLKS_MASK);
AnnaBridge 143:86740a56073b 653 reg |= FTM_SC_CLKS(clockSource);
AnnaBridge 143:86740a56073b 654 base->SC = reg;
AnnaBridge 143:86740a56073b 655 }
AnnaBridge 143:86740a56073b 656
AnnaBridge 143:86740a56073b 657 /*!
AnnaBridge 143:86740a56073b 658 * @brief Stops the FTM counter.
AnnaBridge 143:86740a56073b 659 *
AnnaBridge 143:86740a56073b 660 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 661 */
AnnaBridge 143:86740a56073b 662 static inline void FTM_StopTimer(FTM_Type *base)
AnnaBridge 143:86740a56073b 663 {
AnnaBridge 143:86740a56073b 664 /* Set clock source to none to disable counter */
AnnaBridge 143:86740a56073b 665 base->SC &= ~(FTM_SC_CLKS_MASK);
AnnaBridge 143:86740a56073b 666 }
AnnaBridge 143:86740a56073b 667
AnnaBridge 143:86740a56073b 668 /*! @}*/
AnnaBridge 143:86740a56073b 669
AnnaBridge 143:86740a56073b 670 /*!
AnnaBridge 143:86740a56073b 671 * @name Software output control
AnnaBridge 143:86740a56073b 672 * @{
AnnaBridge 143:86740a56073b 673 */
AnnaBridge 143:86740a56073b 674
AnnaBridge 143:86740a56073b 675 /*!
AnnaBridge 143:86740a56073b 676 * @brief Enables or disables the channel software output control.
AnnaBridge 143:86740a56073b 677 *
AnnaBridge 143:86740a56073b 678 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 679 * @param chnlNumber Channel to be enabled or disabled
AnnaBridge 143:86740a56073b 680 * @param value true: channel output is affected by software output control
AnnaBridge 143:86740a56073b 681 false: channel output is unaffected by software output control
AnnaBridge 143:86740a56073b 682 */
AnnaBridge 143:86740a56073b 683 static inline void FTM_SetSoftwareCtrlEnable(FTM_Type *base, ftm_chnl_t chnlNumber, bool value)
AnnaBridge 143:86740a56073b 684 {
AnnaBridge 143:86740a56073b 685 if (value)
AnnaBridge 143:86740a56073b 686 {
AnnaBridge 143:86740a56073b 687 base->SWOCTRL |= (1U << chnlNumber);
AnnaBridge 143:86740a56073b 688 }
AnnaBridge 143:86740a56073b 689 else
AnnaBridge 143:86740a56073b 690 {
AnnaBridge 143:86740a56073b 691 base->SWOCTRL &= ~(1U << chnlNumber);
AnnaBridge 143:86740a56073b 692 }
AnnaBridge 143:86740a56073b 693 }
AnnaBridge 143:86740a56073b 694
AnnaBridge 143:86740a56073b 695 /*!
AnnaBridge 143:86740a56073b 696 * @brief Sets the channel software output control value.
AnnaBridge 143:86740a56073b 697 *
AnnaBridge 143:86740a56073b 698 * @param base FTM peripheral base address.
AnnaBridge 143:86740a56073b 699 * @param chnlNumber Channel to be configured
AnnaBridge 143:86740a56073b 700 * @param value true to set 1, false to set 0
AnnaBridge 143:86740a56073b 701 */
AnnaBridge 143:86740a56073b 702 static inline void FTM_SetSoftwareCtrlVal(FTM_Type *base, ftm_chnl_t chnlNumber, bool value)
AnnaBridge 143:86740a56073b 703 {
AnnaBridge 143:86740a56073b 704 if (value)
AnnaBridge 143:86740a56073b 705 {
AnnaBridge 143:86740a56073b 706 base->SWOCTRL |= (1U << (chnlNumber + FTM_SWOCTRL_CH0OCV_SHIFT));
AnnaBridge 143:86740a56073b 707 }
AnnaBridge 143:86740a56073b 708 else
AnnaBridge 143:86740a56073b 709 {
AnnaBridge 143:86740a56073b 710 base->SWOCTRL &= ~(1U << (chnlNumber + FTM_SWOCTRL_CH0OCV_SHIFT));
AnnaBridge 143:86740a56073b 711 }
AnnaBridge 143:86740a56073b 712 }
AnnaBridge 143:86740a56073b 713
AnnaBridge 143:86740a56073b 714 /*! @}*/
AnnaBridge 143:86740a56073b 715
AnnaBridge 143:86740a56073b 716 /*!
AnnaBridge 143:86740a56073b 717 * @brief Enables or disables the FTM global time base signal generation to other FTMs.
AnnaBridge 143:86740a56073b 718 *
AnnaBridge 143:86740a56073b 719 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 720 * @param enable true to enable, false to disable
AnnaBridge 143:86740a56073b 721 */
AnnaBridge 143:86740a56073b 722 static inline void FTM_SetGlobalTimeBaseOutputEnable(FTM_Type *base, bool enable)
AnnaBridge 143:86740a56073b 723 {
AnnaBridge 143:86740a56073b 724 if (enable)
AnnaBridge 143:86740a56073b 725 {
AnnaBridge 143:86740a56073b 726 base->CONF |= FTM_CONF_GTBEOUT_MASK;
AnnaBridge 143:86740a56073b 727 }
AnnaBridge 143:86740a56073b 728 else
AnnaBridge 143:86740a56073b 729 {
AnnaBridge 143:86740a56073b 730 base->CONF &= ~FTM_CONF_GTBEOUT_MASK;
AnnaBridge 143:86740a56073b 731 }
AnnaBridge 143:86740a56073b 732 }
AnnaBridge 143:86740a56073b 733
AnnaBridge 143:86740a56073b 734 /*!
AnnaBridge 143:86740a56073b 735 * @brief Sets the FTM peripheral timer channel output mask.
AnnaBridge 143:86740a56073b 736 *
AnnaBridge 143:86740a56073b 737 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 738 * @param chnlNumber Channel to be configured
AnnaBridge 143:86740a56073b 739 * @param mask true: masked, channel is forced to its inactive state; false: unmasked
AnnaBridge 143:86740a56073b 740 */
AnnaBridge 143:86740a56073b 741 static inline void FTM_SetOutputMask(FTM_Type *base, ftm_chnl_t chnlNumber, bool mask)
AnnaBridge 143:86740a56073b 742 {
AnnaBridge 143:86740a56073b 743 if (mask)
AnnaBridge 143:86740a56073b 744 {
AnnaBridge 143:86740a56073b 745 base->OUTMASK |= (1U << chnlNumber);
AnnaBridge 143:86740a56073b 746 }
AnnaBridge 143:86740a56073b 747 else
AnnaBridge 143:86740a56073b 748 {
AnnaBridge 143:86740a56073b 749 base->OUTMASK &= ~(1U << chnlNumber);
AnnaBridge 143:86740a56073b 750 }
AnnaBridge 143:86740a56073b 751 }
AnnaBridge 143:86740a56073b 752
AnnaBridge 143:86740a56073b 753 #if defined(FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT) && (FSL_FEATURE_FTM_HAS_ENABLE_PWM_OUTPUT)
AnnaBridge 143:86740a56073b 754 /*!
AnnaBridge 143:86740a56073b 755 * @brief Allows users to enable an output on an FTM channel.
AnnaBridge 143:86740a56073b 756 *
AnnaBridge 143:86740a56073b 757 * To enable the PWM channel output call this function with val=true. For input mode,
AnnaBridge 143:86740a56073b 758 * call this function with val=false.
AnnaBridge 143:86740a56073b 759 *
AnnaBridge 143:86740a56073b 760 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 761 * @param chnlNumber Channel to be configured
AnnaBridge 143:86740a56073b 762 * @param value true: enable output; false: output is disabled, used in input mode
AnnaBridge 143:86740a56073b 763 */
AnnaBridge 143:86740a56073b 764 static inline void FTM_SetPwmOutputEnable(FTM_Type *base, ftm_chnl_t chnlNumber, bool value)
AnnaBridge 143:86740a56073b 765 {
AnnaBridge 143:86740a56073b 766 if (value)
AnnaBridge 143:86740a56073b 767 {
AnnaBridge 143:86740a56073b 768 base->SC |= (1U << (chnlNumber + FTM_SC_PWMEN0_SHIFT));
AnnaBridge 143:86740a56073b 769 }
AnnaBridge 143:86740a56073b 770 else
AnnaBridge 143:86740a56073b 771 {
AnnaBridge 143:86740a56073b 772 base->SC &= ~(1U << (chnlNumber + FTM_SC_PWMEN0_SHIFT));
AnnaBridge 143:86740a56073b 773 }
AnnaBridge 143:86740a56073b 774 }
AnnaBridge 143:86740a56073b 775 #endif
AnnaBridge 143:86740a56073b 776
AnnaBridge 143:86740a56073b 777 /*!
AnnaBridge 143:86740a56073b 778 * @name Channel pair operations
AnnaBridge 143:86740a56073b 779 * @{
AnnaBridge 143:86740a56073b 780 */
AnnaBridge 143:86740a56073b 781
AnnaBridge 143:86740a56073b 782 /*!
AnnaBridge 143:86740a56073b 783 * @brief This function enables/disables the fault control in a channel pair.
AnnaBridge 143:86740a56073b 784 *
AnnaBridge 143:86740a56073b 785 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 786 * @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
AnnaBridge 143:86740a56073b 787 * @param value true: Enable fault control for this channel pair; false: No fault control
AnnaBridge 143:86740a56073b 788 */
AnnaBridge 143:86740a56073b 789 static inline void FTM_SetFaultControlEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
AnnaBridge 143:86740a56073b 790 {
AnnaBridge 143:86740a56073b 791 if (value)
AnnaBridge 143:86740a56073b 792 {
AnnaBridge 143:86740a56073b 793 base->COMBINE |= (1U << (FTM_COMBINE_FAULTEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 794 }
AnnaBridge 143:86740a56073b 795 else
AnnaBridge 143:86740a56073b 796 {
AnnaBridge 143:86740a56073b 797 base->COMBINE &= ~(1U << (FTM_COMBINE_FAULTEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 798 }
AnnaBridge 143:86740a56073b 799 }
AnnaBridge 143:86740a56073b 800
AnnaBridge 143:86740a56073b 801 /*!
AnnaBridge 143:86740a56073b 802 * @brief This function enables/disables the dead time insertion in a channel pair.
AnnaBridge 143:86740a56073b 803 *
AnnaBridge 143:86740a56073b 804 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 805 * @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
AnnaBridge 143:86740a56073b 806 * @param value true: Insert dead time in this channel pair; false: No dead time inserted
AnnaBridge 143:86740a56073b 807 */
AnnaBridge 143:86740a56073b 808 static inline void FTM_SetDeadTimeEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
AnnaBridge 143:86740a56073b 809 {
AnnaBridge 143:86740a56073b 810 if (value)
AnnaBridge 143:86740a56073b 811 {
AnnaBridge 143:86740a56073b 812 base->COMBINE |= (1U << (FTM_COMBINE_DTEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 813 }
AnnaBridge 143:86740a56073b 814 else
AnnaBridge 143:86740a56073b 815 {
AnnaBridge 143:86740a56073b 816 base->COMBINE &= ~(1U << (FTM_COMBINE_DTEN0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 817 }
AnnaBridge 143:86740a56073b 818 }
AnnaBridge 143:86740a56073b 819
AnnaBridge 143:86740a56073b 820 /*!
AnnaBridge 143:86740a56073b 821 * @brief This function enables/disables complementary mode in a channel pair.
AnnaBridge 143:86740a56073b 822 *
AnnaBridge 143:86740a56073b 823 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 824 * @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
AnnaBridge 143:86740a56073b 825 * @param value true: enable complementary mode; false: disable complementary mode
AnnaBridge 143:86740a56073b 826 */
AnnaBridge 143:86740a56073b 827 static inline void FTM_SetComplementaryEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
AnnaBridge 143:86740a56073b 828 {
AnnaBridge 143:86740a56073b 829 if (value)
AnnaBridge 143:86740a56073b 830 {
AnnaBridge 143:86740a56073b 831 base->COMBINE |= (1U << (FTM_COMBINE_COMP0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 832 }
AnnaBridge 143:86740a56073b 833 else
AnnaBridge 143:86740a56073b 834 {
AnnaBridge 143:86740a56073b 835 base->COMBINE &= ~(1U << (FTM_COMBINE_COMP0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlPairNumber)));
AnnaBridge 143:86740a56073b 836 }
AnnaBridge 143:86740a56073b 837 }
AnnaBridge 143:86740a56073b 838
AnnaBridge 143:86740a56073b 839 /*!
AnnaBridge 143:86740a56073b 840 * @brief This function enables/disables inverting control in a channel pair.
AnnaBridge 143:86740a56073b 841 *
AnnaBridge 143:86740a56073b 842 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 843 * @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
AnnaBridge 143:86740a56073b 844 * @param value true: enable inverting; false: disable inverting
AnnaBridge 143:86740a56073b 845 */
AnnaBridge 143:86740a56073b 846 static inline void FTM_SetInvertEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)
AnnaBridge 143:86740a56073b 847 {
AnnaBridge 143:86740a56073b 848 if (value)
AnnaBridge 143:86740a56073b 849 {
AnnaBridge 143:86740a56073b 850 base->INVCTRL |= (1U << chnlPairNumber);
AnnaBridge 143:86740a56073b 851 }
AnnaBridge 143:86740a56073b 852 else
AnnaBridge 143:86740a56073b 853 {
AnnaBridge 143:86740a56073b 854 base->INVCTRL &= ~(1U << chnlPairNumber);
AnnaBridge 143:86740a56073b 855 }
AnnaBridge 143:86740a56073b 856 }
AnnaBridge 143:86740a56073b 857
AnnaBridge 143:86740a56073b 858 /*! @}*/
AnnaBridge 143:86740a56073b 859
AnnaBridge 143:86740a56073b 860 /*!
AnnaBridge 143:86740a56073b 861 * @name Quad Decoder
AnnaBridge 143:86740a56073b 862 * @{
AnnaBridge 143:86740a56073b 863 */
AnnaBridge 143:86740a56073b 864
AnnaBridge 143:86740a56073b 865 /*!
AnnaBridge 143:86740a56073b 866 * @brief Configures the parameters and activates the quadrature decoder mode.
AnnaBridge 143:86740a56073b 867 *
AnnaBridge 143:86740a56073b 868 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 869 * @param phaseAParams Phase A configuration parameters
AnnaBridge 143:86740a56073b 870 * @param phaseBParams Phase B configuration parameters
AnnaBridge 143:86740a56073b 871 * @param quadMode Selects encoding mode used in quadrature decoder mode
AnnaBridge 143:86740a56073b 872 */
AnnaBridge 143:86740a56073b 873 void FTM_SetupQuadDecode(FTM_Type *base,
AnnaBridge 143:86740a56073b 874 const ftm_phase_params_t *phaseAParams,
AnnaBridge 143:86740a56073b 875 const ftm_phase_params_t *phaseBParams,
AnnaBridge 143:86740a56073b 876 ftm_quad_decode_mode_t quadMode);
AnnaBridge 143:86740a56073b 877
AnnaBridge 143:86740a56073b 878 /*!
AnnaBridge 143:86740a56073b 879 * @brief Gets the FTM Quad Decoder flags.
AnnaBridge 143:86740a56073b 880 *
AnnaBridge 143:86740a56073b 881 * @param base FTM peripheral base address.
AnnaBridge 143:86740a56073b 882 * @return Flag mask of FTM Quad Decoder, see #_ftm_quad_decoder_flags.
AnnaBridge 143:86740a56073b 883 */
AnnaBridge 143:86740a56073b 884 static inline uint32_t FTM_GetQuadDecoderFlags(FTM_Type *base)
AnnaBridge 143:86740a56073b 885 {
AnnaBridge 143:86740a56073b 886 return base->QDCTRL & (FTM_QDCTRL_QUADIR_MASK | FTM_QDCTRL_TOFDIR_MASK);
AnnaBridge 143:86740a56073b 887 }
AnnaBridge 143:86740a56073b 888
AnnaBridge 143:86740a56073b 889 /*!
AnnaBridge 143:86740a56073b 890 * @brief Sets the modulo values for Quad Decoder.
AnnaBridge 143:86740a56073b 891 *
AnnaBridge 143:86740a56073b 892 * The modulo values configure the minimum and maximum values that the Quad decoder counter can reach. After the counter goes
AnnaBridge 143:86740a56073b 893 * over, the counter value goes to the other side and decrease/increase again.
AnnaBridge 143:86740a56073b 894 *
AnnaBridge 143:86740a56073b 895 * @param base FTM peripheral base address.
AnnaBridge 143:86740a56073b 896 * @param startValue The low limit value for Quad Decoder counter.
AnnaBridge 143:86740a56073b 897 * @param overValue The high limit value for Quad Decoder counter.
AnnaBridge 143:86740a56073b 898 */
AnnaBridge 143:86740a56073b 899 static inline void FTM_SetQuadDecoderModuloValue(FTM_Type *base, uint32_t startValue, uint32_t overValue)
AnnaBridge 143:86740a56073b 900 {
AnnaBridge 143:86740a56073b 901 base->CNTIN = startValue;
AnnaBridge 143:86740a56073b 902 base->MOD = overValue;
AnnaBridge 143:86740a56073b 903 }
AnnaBridge 143:86740a56073b 904
AnnaBridge 143:86740a56073b 905 /*!
AnnaBridge 143:86740a56073b 906 * @brief Gets the current Quad Decoder counter value.
AnnaBridge 143:86740a56073b 907 *
AnnaBridge 143:86740a56073b 908 * @param base FTM peripheral base address.
AnnaBridge 143:86740a56073b 909 * @return Current quad Decoder counter value.
AnnaBridge 143:86740a56073b 910 */
AnnaBridge 143:86740a56073b 911 static inline uint32_t FTM_GetQuadDecoderCounterValue(FTM_Type *base)
AnnaBridge 143:86740a56073b 912 {
AnnaBridge 143:86740a56073b 913 return base->CNT;
AnnaBridge 143:86740a56073b 914 }
AnnaBridge 143:86740a56073b 915
AnnaBridge 143:86740a56073b 916 /*!
AnnaBridge 143:86740a56073b 917 * @brief Clears the current Quad Decoder counter value.
AnnaBridge 143:86740a56073b 918 *
AnnaBridge 143:86740a56073b 919 * The counter is set as the initial value.
AnnaBridge 143:86740a56073b 920 *
AnnaBridge 143:86740a56073b 921 * @param base FTM peripheral base address.
AnnaBridge 143:86740a56073b 922 */
AnnaBridge 143:86740a56073b 923 static inline void FTM_ClearQuadDecoderCounterValue(FTM_Type *base)
AnnaBridge 143:86740a56073b 924 {
AnnaBridge 143:86740a56073b 925 base->CNT = base->CNTIN;
AnnaBridge 143:86740a56073b 926 }
AnnaBridge 143:86740a56073b 927
AnnaBridge 143:86740a56073b 928 /*! @}*/
AnnaBridge 143:86740a56073b 929
AnnaBridge 143:86740a56073b 930 /*!
AnnaBridge 143:86740a56073b 931 * @brief Enables or disables the FTM software trigger for PWM synchronization.
AnnaBridge 143:86740a56073b 932 *
AnnaBridge 143:86740a56073b 933 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 934 * @param enable true: software trigger is selected, false: software trigger is not selected
AnnaBridge 143:86740a56073b 935 */
AnnaBridge 143:86740a56073b 936 static inline void FTM_SetSoftwareTrigger(FTM_Type *base, bool enable)
AnnaBridge 143:86740a56073b 937 {
AnnaBridge 143:86740a56073b 938 if (enable)
AnnaBridge 143:86740a56073b 939 {
AnnaBridge 143:86740a56073b 940 base->SYNC |= FTM_SYNC_SWSYNC_MASK;
AnnaBridge 143:86740a56073b 941 }
AnnaBridge 143:86740a56073b 942 else
AnnaBridge 143:86740a56073b 943 {
AnnaBridge 143:86740a56073b 944 base->SYNC &= ~FTM_SYNC_SWSYNC_MASK;
AnnaBridge 143:86740a56073b 945 }
AnnaBridge 143:86740a56073b 946 }
AnnaBridge 143:86740a56073b 947
AnnaBridge 143:86740a56073b 948 /*!
AnnaBridge 143:86740a56073b 949 * @brief Enables or disables the FTM write protection.
AnnaBridge 143:86740a56073b 950 *
AnnaBridge 143:86740a56073b 951 * @param base FTM peripheral base address
AnnaBridge 143:86740a56073b 952 * @param enable true: Write-protection is enabled, false: Write-protection is disabled
AnnaBridge 143:86740a56073b 953 */
AnnaBridge 143:86740a56073b 954 static inline void FTM_SetWriteProtection(FTM_Type *base, bool enable)
AnnaBridge 143:86740a56073b 955 {
AnnaBridge 143:86740a56073b 956 /* Configure write protection */
AnnaBridge 143:86740a56073b 957 if (enable)
AnnaBridge 143:86740a56073b 958 {
AnnaBridge 143:86740a56073b 959 base->FMS |= FTM_FMS_WPEN_MASK;
AnnaBridge 143:86740a56073b 960 }
AnnaBridge 143:86740a56073b 961 else
AnnaBridge 143:86740a56073b 962 {
AnnaBridge 143:86740a56073b 963 base->MODE |= FTM_MODE_WPDIS_MASK;
AnnaBridge 143:86740a56073b 964 }
AnnaBridge 143:86740a56073b 965 }
AnnaBridge 143:86740a56073b 966
AnnaBridge 143:86740a56073b 967 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 968 }
AnnaBridge 143:86740a56073b 969 #endif
AnnaBridge 143:86740a56073b 970
AnnaBridge 143:86740a56073b 971 /*! @}*/
AnnaBridge 143:86740a56073b 972
AnnaBridge 143:86740a56073b 973 #endif /* _FSL_FTM_H_*/