36 #include "ftm_hw_access.h"
47 #if (FEATURE_FTM_HAS_NUM_IRQS_CHANS == 1U)
48 void FTM0_Ch0_7_IRQHandler(
void);
49 void FTM1_Ch0_7_IRQHandler(
void);
52 #if (FEATURE_FTM_HAS_NUM_IRQS_CHANS == 4U)
53 void FTM0_Ch0_Ch1_IRQHandler(
void);
55 void FTM0_Ch2_Ch3_IRQHandler(
void);
57 void FTM0_Ch4_Ch5_IRQHandler(
void);
59 void FTM0_Ch6_Ch7_IRQHandler(
void);
61 void FTM1_Ch0_Ch1_IRQHandler(
void);
63 void FTM1_Ch2_Ch3_IRQHandler(
void);
65 void FTM1_Ch4_Ch5_IRQHandler(
void);
67 void FTM1_Ch6_Ch7_IRQHandler(
void);
69 #if (FTM_INSTANCE_COUNT > 2U)
70 void FTM2_Ch0_Ch1_IRQHandler(
void);
72 void FTM2_Ch2_Ch3_IRQHandler(
void);
74 void FTM2_Ch4_Ch5_IRQHandler(
void);
76 void FTM2_Ch6_Ch7_IRQHandler(
void);
78 void FTM3_Ch0_Ch1_IRQHandler(
void);
80 void FTM3_Ch2_Ch3_IRQHandler(
void);
82 void FTM3_Ch4_Ch5_IRQHandler(
void);
84 void FTM3_Ch6_Ch7_IRQHandler(
void);
87 #if (FTM_INSTANCE_COUNT > 4U)
88 void FTM4_Ch0_Ch1_IRQHandler(
void);
90 void FTM4_Ch2_Ch3_IRQHandler(
void);
92 void FTM4_Ch4_Ch5_IRQHandler(
void);
94 void FTM4_Ch6_Ch7_IRQHandler(
void);
96 void FTM5_Ch0_Ch1_IRQHandler(
void);
98 void FTM5_Ch2_Ch3_IRQHandler(
void);
100 void FTM5_Ch4_Ch5_IRQHandler(
void);
102 void FTM5_Ch6_Ch7_IRQHandler(
void);
105 #if (FTM_INSTANCE_COUNT > 6U)
106 void FTM6_Ch0_Ch1_IRQHandler(
void);
108 void FTM6_Ch2_Ch3_IRQHandler(
void);
110 void FTM6_Ch4_Ch5_IRQHandler(
void);
112 void FTM6_Ch6_Ch7_IRQHandler(
void);
114 void FTM7_Ch0_Ch1_IRQHandler(
void);
116 void FTM7_Ch2_Ch3_IRQHandler(
void);
118 void FTM7_Ch4_Ch5_IRQHandler(
void);
120 void FTM7_Ch6_Ch7_IRQHandler(
void);
142 uint8_t chnlPairNum = 0U;
144 uint8_t hwChannel = 0U;
152 FTM_DRV_SetCounterInitVal(ftmBase, 0U);
154 FTM_DRV_SetCpwms(ftmBase,
false);
156 FTM_DRV_SetDualChnMofCombineCmd(ftmBase, chnlPairNum,
false);
157 FTM_DRV_SetDualChnCombineCmd(ftmBase, chnlPairNum,
false);
162 chnlPairNum = (uint8_t)(hwChannel >> 1U);
177 FTM_DRV_SetChnInputCaptureFilter(ftmBase, hwChannel, 0U);
184 FTM_DRV_SetDualEdgeCaptureCmd(ftmBase, chnlPairNum,
false);
186 FTM_DRV_SetChnMSnBAMode(ftmBase, hwChannel, 0U);
192 FTM_DRV_EnableChnInt(ftmBase, hwChannel);
200 FTM_DRV_SetDualEdgeCaptureCmd(ftmBase, chnlPairNum,
true);
202 FTM_DRV_SetDualChnDecapCmd(ftmBase, chnlPairNum,
true);
207 FTM_DRV_SetChnMSnBAMode(ftmBase, hwChannel, 3U);
212 FTM_DRV_SetChnMSnBAMode(ftmBase, hwChannel, 2U);
219 FTM_DRV_SetChnEdgeLevel(ftmBase, hwChannel, 1U);
223 FTM_DRV_SetChnEdgeLevel(ftmBase, (uint8_t)(hwChannel + 1U), 2U);
229 FTM_DRV_SetChnEdgeLevel(ftmBase, (uint8_t)(hwChannel + 1U), 1U);
234 FTM_DRV_SetChnEdgeLevel(ftmBase, hwChannel, 2U);
238 FTM_DRV_SetChnEdgeLevel(ftmBase, (uint8_t)(hwChannel + 1U), 1U);
244 FTM_DRV_SetChnEdgeLevel(ftmBase, (uint8_t)(hwChannel + 1U), 2U);
254 FTM_DRV_EnableChnInt(ftmBase, (uint8_t)(hwChannel + 1U));
291 uint8_t chnlPairNum = 0U;
293 uint8_t hwChannel = 0U;
298 FTM_DRV_SetCounterInitVal(ftmBase, 0U);
299 FTM_DRV_SetMod(ftmBase, 0xFFFFU);
300 FTM_DRV_SetCpwms(ftmBase,
false);
304 chnlPairNum = (uint8_t)(hwChannel >> 1U);
308 FTM_DRV_SetChnInputCaptureFilter(ftmBase, hwChannel, 0U);
311 FTM_DRV_SetDualChnCombineCmd(ftmBase, chnlPairNum,
false);
312 FTM_DRV_SetDualEdgeCaptureCmd(ftmBase, chnlPairNum,
false);
313 FTM_DRV_SetChnEdgeLevel(ftmBase, hwChannel, (uint8_t)0U);
314 FTM_DRV_DisableChnInt(ftmBase, hwChannel);
368 uint8_t chnlPairNum = (uint8_t)(channel >> 1U);
373 if (FTM_DRV_GetDualEdgeCaptureBit(ftmBase, chnlPairNum))
376 FTM_DRV_ClearChnEventFlag(ftmBase, (uint8_t)(channel + 1U));
377 FTM_DRV_ClearChnEventFlag(ftmBase, channel);
379 FTM_DRV_SetDualChnDecapCmd(ftmBase, chnlPairNum,
true);
402 bool enableContinuousCapture)
409 uint8_t nextChnlevel = 1U;
410 uint8_t channelPair = (uint8_t)(channel >> 1U);
415 FTM_DRV_SetChnEdgeLevel(ftmBase, channel, 0x0U);
422 FTM_DRV_SetDualEdgeCaptureCmd(ftmBase, channelPair,
false);
424 FTM_DRV_SetChnMSnBAMode(ftmBase, channel, 0U);
426 FTM_DRV_SetChnEdgeLevel(ftmBase, channel, (uint8_t)inputMode);
428 FTM_DRV_EnableChnInt(ftmBase, channel);
435 FTM_DRV_SetDualEdgeCaptureCmd(ftmBase, channelPair,
true);
437 FTM_DRV_SetDualChnDecapCmd(ftmBase, channelPair,
true);
439 if (
true == enableContinuousCapture)
442 FTM_DRV_SetChnMSnBAMode(ftmBase, channel, 3U);
447 FTM_DRV_SetChnMSnBAMode(ftmBase, channel, 2U);
470 FTM_DRV_SetChnEdgeLevel(ftmBase, channel, level);
471 FTM_DRV_SetChnEdgeLevel(ftmBase, (uint8_t)(channel + 1U), nextChnlevel);
474 FTM_DRV_DisableChnInt(ftmBase, channel);
475 FTM_DRV_EnableChnInt(ftmBase, (uint8_t)(channel + 1U));
481 #if (FEATURE_FTM_HAS_NUM_IRQS_CHANS == 1U)
483 void FTM0_Ch0_7_IRQHandler(
void)
489 bool isIntOnChn =
false;
490 bool isIntOnNextChn =
false;
495 isIntOnChn = (((statusFlag & enabledInt) & (0x1UL << shift)) != 0U) ?
true :
false;
497 isIntOnNextChn = (((statusFlag & enabledInt) & (0x1UL << shift)) != 0U) ?
true :
false;
499 if ((isIntOnChn ==
true) || (isIntOnNextChn ==
true))
507 void FTM1_Ch0_7_IRQHandler(
void)
513 bool isIntOnChn =
false;
514 bool isIntOnNextChn =
false;
519 isIntOnChn = (((statusFlag & enabledInt) & (0x1UL << shift)) != 0U) ?
true :
false;
521 isIntOnNextChn = (((statusFlag & enabledInt) & (0x1UL << shift)) != 0U) ?
true :
false;
523 if ((isIntOnChn ==
true) || (isIntOnNextChn ==
true))
531 #if (FEATURE_FTM_HAS_NUM_IRQS_CHANS == 4U)
533 void FTM0_Ch0_Ch1_IRQHandler(
void)
539 void FTM0_Ch2_Ch3_IRQHandler(
void)
545 void FTM0_Ch4_Ch5_IRQHandler(
void)
551 void FTM0_Ch6_Ch7_IRQHandler(
void)
557 void FTM1_Ch0_Ch1_IRQHandler(
void)
563 void FTM1_Ch2_Ch3_IRQHandler(
void)
569 void FTM1_Ch4_Ch5_IRQHandler(
void)
575 void FTM1_Ch6_Ch7_IRQHandler(
void)
580 #if (FTM_INSTANCE_COUNT > 2U)
582 void FTM2_Ch0_Ch1_IRQHandler(
void)
588 void FTM2_Ch2_Ch3_IRQHandler(
void)
594 void FTM2_Ch4_Ch5_IRQHandler(
void)
600 void FTM2_Ch6_Ch7_IRQHandler(
void)
606 void FTM3_Ch0_Ch1_IRQHandler(
void)
612 void FTM3_Ch2_Ch3_IRQHandler(
void)
618 void FTM3_Ch4_Ch5_IRQHandler(
void)
624 void FTM3_Ch6_Ch7_IRQHandler(
void)
630 #if (FTM_INSTANCE_COUNT > 4U)
632 void FTM4_Ch0_Ch1_IRQHandler(
void)
638 void FTM4_Ch2_Ch3_IRQHandler(
void)
644 void FTM4_Ch4_Ch5_IRQHandler(
void)
650 void FTM4_Ch6_Ch7_IRQHandler(
void)
656 void FTM5_Ch0_Ch1_IRQHandler(
void)
662 void FTM5_Ch2_Ch3_IRQHandler(
void)
668 void FTM5_Ch4_Ch5_IRQHandler(
void)
674 void FTM5_Ch6_Ch7_IRQHandler(
void)
680 #if (FTM_INSTANCE_COUNT > 6U)
682 void FTM6_Ch0_Ch1_IRQHandler(
void)
688 void FTM6_Ch2_Ch3_IRQHandler(
void)
694 void FTM6_Ch4_Ch5_IRQHandler(
void)
700 void FTM6_Ch6_Ch7_IRQHandler(
void)
706 void FTM7_Ch0_Ch1_IRQHandler(
void)
712 void FTM7_Ch2_Ch3_IRQHandler(
void)
718 void FTM7_Ch4_Ch5_IRQHandler(
void)
724 void FTM7_Ch6_Ch7_IRQHandler(
void)
754 uint8_t channel = (uint8_t)(channelPair << 1U);
757 if (FTM_DRV_GetDualEdgeCaptureBit(ftmBase, channelPair))
762 if (second_event_time < first_event_time)
770 state->
measurementResults[channel] = (uint16_t)(second_event_time - first_event_time);
774 FTM_DRV_ClearChnEventFlag(ftmBase, channel);
775 FTM_DRV_ClearChnEventFlag(ftmBase, (uint8_t)(channel + 1U));
780 if (
false == FTM_DRV_HasChnEventOccurred(ftmBase, channel))
788 FTM_DRV_ClearChnEventFlag(ftmBase, channel);
ic_callback_t channelsCallbacks[(8U)]
static uint16_t FTM_DRV_GetChnCountVal(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel counter value.
FlexTimer state structure of the driver.
ftm_state_t * ftmStatePtr[(2u)]
Pointer to runtime state structure.
#define FEATURE_FTM_CHANNEL_COUNT
#define CHAN4_IDX
Channel number for CHAN5.
status_t FTM_DRV_StartNewSignalMeasurement(uint32_t instance, uint8_t channel)
Starts new single-shot signal measurement of the given channel.
status_t FTM_IC_DRV_SetChannelMode(uint32_t instance, uint8_t channel, ftm_ic_op_mode_t inputMode, bool enableContinuousCapture)
Set mode operation for channel in the input captue mode.
static void FTM_DRV_InputCaptureHandler(uint32_t instance, uint8_t channelPair)
uint16_t measurementResults[(8U)]
ftm_ic_op_mode_t
The measurement type for input capture mode Implements : ftm_ic_op_mode_t_Class.
bool enableNotification[(8U)]
static void FTM_DRV_IrqHandler(uint32_t instance, uint8_t channelPair)
const IRQn_Type g_ftmIrqId[(2u)][(8U)]
Interrupt vectors for the FTM peripheral.
#define FTM_FEATURE_INPUT_CAPTURE_SINGLE_SHOT
ftm_clock_source_t ftmClockSource
status_t FTM_DRV_InitInputCapture(uint32_t instance, const ftm_input_param_t *param)
Configures Channel Input Capture for either getting time-stamps on edge detection or on signal measur...
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
#define FTM_INSTANCE_COUNT
status_t FTM_DRV_DeinitInputCapture(uint32_t instance, const ftm_input_param_t *param)
Disables input capture mode and clears FTM timer configuration.
ftm_signal_measurement_mode_t
FlexTimer input capture measurement type for dual edge input capture.
ftm_config_mode_t ftmMode
void * channelsCallbacksParams[(8U)]
uint32_t FTM_DRV_GetEnabledInterrupts(uint32_t instance)
This function will get the enabled FTM interrupts.
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
static uint16_t FTM_DRV_GetMod(const FTM_Type *ftmBase)
Returns the FTM peripheral counter modulo value.
uint32_t FTM_DRV_GetStatusFlags(uint32_t instance)
This function will get the FTM status flags.
uint16_t FTM_DRV_GetInputCaptureMeasurement(uint32_t instance, uint8_t channel)
This function is used to calculate the measurement and/or time stamps values which are read from the ...
FTM_Type *const g_ftmBase[(2u)]
Table of base addresses for FTM instances.