38 #include "ftm_hw_access.h"
61 extern bool faultDetection;
190 #if defined(__cplusplus)
203 uint8_t filterPrescale)
404 ((ftmBase)->CONTROLS[channel].CnSC) = 0U;
665 return (uint16_t)((ftmBase)->CONTROLS[channel].CnV);
685 return (((ftmBase)->STATUS) & (1UL << channel)) != 0U;
699 return ((ftmBase)->STATUS) & (0xFFU);
715 ((ftmBase)->STATUS) &= (~(1UL << channel));
741 ((ftmBase)->OUTMASK) |= (1UL << channel);
745 ((ftmBase)->OUTMASK) &= ~(1UL << channel);
768 ((ftmBase)->OUTINIT) |= (1UL << channel);
772 ((ftmBase)->OUTINIT) &= ~(1UL << channel);
1034 ((ftmBase)->FMS) &= (~(1UL << channel));
1156 uint8_t chnlPairNum,
1163 ((ftmBase)->INVCTRL) |= (1UL << chnlPairNum);
1167 ((ftmBase)->INVCTRL) &= ~(1UL << chnlPairNum);
1190 ((ftmBase)->SWOCTRL) |= (1UL << channel);
1194 ((ftmBase)->SWOCTRL) &= ~(1UL << channel);
1328 ((ftmBase)->PWMLOAD) |= (1UL << channel);
1332 ((ftmBase)->PWMLOAD) &= ~(1UL << channel);
1409 uint8_t channelPair,
1415 switch (channelPair)
1448 uint8_t channelPair,
1449 ftm_deadtime_ps_t divider)
1453 switch (channelPair)
1487 uint8_t channelPair,
1493 switch (channelPair)
1513 #if FEATURE_FTM_HAS_SUPPORTED_DITHERING
1522 static inline void FTM_DRV_SetMirrorMod(
FTM_Type *
const ftmBase,
1537 static inline uint16_t FTM_DRV_GetMirrorMod(
const FTM_Type * ftmBase)
1551 static inline uint8_t FTM_DRV_GetModFracVal(
const FTM_Type * ftmBase)
1565 static inline void FTM_DRV_SetMirrorChnMatchVal(
FTM_Type *
const ftmBase,
1582 static inline uint16_t FTM_DRV_GetMirrorChnMatchVal(
const FTM_Type * ftmBase,
1598 static inline uint8_t FTM_DRV_GetChnMatchFracVal(
const FTM_Type * ftmBase,
1641 uint32_t channelsMask,
1642 bool softwareTrigger);
1657 uint16_t counterValue,
1658 bool softwareTrigger);
1671 uint16_t reloadPoint,
1672 bool softwareTrigger);
1688 uint8_t channelsValues,
1689 bool softwareTrigger);
1702 uint8_t channelsMask,
1703 bool softwareTrigger);
1716 uint8_t channelsPairMask,
1717 bool softwareTrigger);
1730 uint16_t counterValue,
1731 bool softwareTrigger);
1765 uint32_t freqencyHz);
1767 #if defined(__cplusplus)
const IRQn_Type g_ftmOverflowIrqId[FTM_INSTANCE_COUNT]
static bool FTM_DRV_GetQuadDir(const FTM_Type *ftmBase)
Gets the FTM counter direction in quadrature mode.
static uint16_t FTM_DRV_GetCounterInitVal(const FTM_Type *ftmBase)
Returns the FTM peripheral counter initial value.
#define FTM_QDCTRL_TOFDIR_MASK
#define FTM_QDCTRL_QUADMODE_MASK
static void FTM_DRV_SetCaptureTestCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the FTM peripheral timer capture test mode.
ftm_reg_update_t initCounterSync
static void FTM_DRV_SetChnIcrstCmd(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Configure the feature of FTM counter reset by the selected input capture event.
#define FTM_FMS_FAULTF0_MASK
status_t FTM_DRV_SetSoftwareOutputChannelControl(uint32_t instance, uint8_t channelsMask, bool softwareTrigger)
This function will configure which output channel can be software controlled.
#define FTM_SC_CLKS_SHIFT
ftm_pwm_sync_t syncMethod
static void FTM_DRV_SetPwmLoadCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the loading of MOD, CNTIN and CV with values of their write buffer.
static uint16_t FTM_DRV_GetChnCountVal(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel counter value.
#define FTM_CONF_GTBEOUT_MASK
FlexTimer state structure of the driver.
static void FTM_DRV_SetQuadPhaseBFilterCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the phase B input filter.
static bool FTM_DRV_GetChOutputValue(const FTM_Type *ftmBase, uint8_t channel)
Get the value of channel output.
static void FTM_DRV_SetChnSoftwareCtrlCmd(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Enables or disables the channel software output control.
#define FTM_SC_TOIE_SHIFT
static bool FTM_DRV_IsChnIcrst(const FTM_Type *ftmBase, uint8_t channel)
Returns whether the FTM FTM counter is reset.
static void FTM_DRV_ClearChnTriggerFlag(FTM_Type *const ftmBase)
Clear the channel trigger flag.
status_t FTM_DRV_SetSync(uint32_t instance, const ftm_pwm_sync_t *param)
This function configures sync mechanism for some FTM registers (MOD, CNINT, HCR, CnV, OUTMASK, INVCTRL, SWOCTRL).
#define FTM_PWMLOAD_GLEN_SHIFT
static void FTM_DRV_SetPwmLoadChnSelCmd(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Includes or excludes the channel in the matching process.
#define FTM_CnSC_ELSB_SHIFT
#define FTM_FMS_FAULTF_MASK
#define FTM_PAIR3DEADTIME_DTVALEX_MASK
#define FTM_PWMLOAD_HCSEL_SHIFT
static bool FTM_DRV_IsWriteProtectionEnabled(const FTM_Type *ftmBase)
Checks whether the write protection is enabled.
#define FTM_COMBINE_COMBINE0_MASK
Configuration structure that the user needs to set.
#define FTM_FMS_FAULTF1_MASK
#define FTM_MOD_MIRROR_MOD_SHIFT
FTM_Type *const g_ftmBase[FTM_INSTANCE_COUNT]
Table of base addresses for FTM instances.
static uint8_t FTM_DRV_GetClockPs(const FTM_Type *ftmBase)
Reads the FTM clock divider.
static void FTM_DRV_SetChnOutputInitStateCmd(FTM_Type *const ftmBase, uint8_t channel, bool state)
Sets the FTM peripheral timer channel output initial state 0 or 1.
#define FTM_PAIR1DEADTIME_DTPS_MASK
static bool FTM_DRV_IsChnDma(const FTM_Type *ftmBase, uint8_t channel)
Returns whether the FTM peripheral timer channel DMA is enabled.
#define FTM_SC_FLTPS_MASK
static bool FTM_DRV_GetCpwms(const FTM_Type *ftmBase)
Gets the FTM count direction bit.
FlexTimer Registers sync parameters Please don't use software and hardware trigger simultaneously Imp...
ftm_state_t * ftmStatePtr[FTM_INSTANCE_COUNT]
Pointer to runtime state structure.
#define FTM_SWOCTRL_CH0OCV_SHIFT
#define FTM_FMS_FAULTF3(x)
status_t FTM_DRV_SetInitialCounterValue(uint32_t instance, uint16_t counterValue, bool softwareTrigger)
This function configure the initial counter value. The counter will get this value after an overflow ...
#define FTM_PAIR3DEADTIME_DTVAL(x)
#define FTM_MOD_MIRROR_FRACMOD_SHIFT
static uint8_t FTM_DRV_GetChnEdgeLevel(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel edge level.
#define FTM_MOD_MIRROR_FRACMOD_MASK
static void FTM_DRV_SetGlobalTimeBaseOutputCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the FTM global time base signal generation to other FTM's.
#define FTM_CONF_GTBEEN_MASK
static void FTM_DRV_ClearFaultsIsr(FTM_Type *const ftmBase)
Clears all fault interrupt flags that are active.
static bool FTM_DRV_HasTimerOverflowed(const FTM_Type *ftmBase)
Returns the FTM peripheral timer overflow interrupt flag.
#define FTM_PAIR3DEADTIME_DTPS_MASK
#define FTM_QDCTRL_PHAPOL(x)
static bool FTM_DRV_IsChnIntEnabled(const FTM_Type *ftmBase, uint8_t channel)
Get FTM channel(n) interrupt enabled or not.
static uint8_t FTM_DRV_GetClockFilterPs(const FTM_Type *ftmBase)
Reads the FTM filter clock divider.
static bool FTM_DRV_IsChnTriggerGenerated(const FTM_Type *ftmBase)
Checks whether any channel trigger event has occurred.
status_t FTM_DRV_SetHalfCycleReloadPoint(uint32_t instance, uint16_t reloadPoint, bool softwareTrigger)
This function configure the value of the counter which will generates an reload point.
#define FTM_CnSC_TRIGMODE(x)
static void FTM_DRV_SetCountReinitSyncCmd(FTM_Type *const ftmBase, bool enable)
Determines if the FTM counter is re-initialized when the selected trigger for synchronization is dete...
#define FEATURE_FTM_CHANNEL_COUNT
#define FTM_CONF_GTBEOUT(x)
#define FTM_CNTIN_INIT_MASK
static void FTM_DRV_SetInitChnOutputCmd(FTM_Type *const ftmBase, bool enable)
Initializes the channels output.
#define FTM_PAIR2DEADTIME_DTVALEX_MASK
static uint8_t FTM_DRV_GetChnMode(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel mode.
#define FTM_CNTIN_INIT_SHIFT
#define FTM_MODE_FAULTIE_MASK
static bool FTM_DRV_GetChnEventStatus(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel event status.
#define FTM_MOD_MIRROR_MOD(x)
static bool FTM_DRV_GetDualChnCombineCmd(const FTM_Type *ftmBase, uint8_t chnlPairNum)
Verify if an channels pair is used in combine mode or not.
static void FTM_DRV_ClearReloadFlag(FTM_Type *const ftmBase)
Clears the reload flag bit.
static void FTM_DRV_SetExtPairDeadtimeValue(FTM_Type *const ftmBase, uint8_t channelPair, uint8_t value)
Sets the FTM extended dead-time value for the channel pair.
#define FTM_MODE_INIT_MASK
#define FTM_MODE_FAULTIE(x)
uint32_t FTM_DRV_GetFrequency(uint32_t instance)
Retrieves the frequency of the clock source feeding the FTM counter.
#define FTM_PAIR1DEADTIME_DTVAL(x)
#define FTM_PWMLOAD_GLDOK_SHIFT
uint16_t FTM_DRV_ConvertFreqToPeriodTicks(uint32_t instance, uint32_t freqencyHz)
This function is used to covert the given frequency to period in ticks.
static uint8_t FTM_DRV_GetClockSource(const FTM_Type *ftmBase)
Reads the FTM clock source.
#define FTM_FMS_WPEN_MASK
#define FTM_PAIR1DEADTIME_DTPS(x)
#define FTM_PAIR1DEADTIME_DTVAL_MASK
#define FTM_CnSC_MSB_SHIFT
#define FTM_PAIR2DEADTIME_DTPS(x)
#define FTM_QDCTRL_QUADIR_MASK
#define FTM_CnSC_ELSA_MASK
static void FTM_DRV_SetLoadCmd(FTM_Type *const ftmBase, bool enable)
Enable the global load.
#define FTM_QDCTRL_QUADMODE(x)
#define FTM_MODE_FAULTIE_SHIFT
static void FTM_DRV_SetQuadPhaseAPolarity(FTM_Type *const ftmBase, ftm_quad_phase_polarity_t mode)
Selects polarity for the quadrature decode phase A input.
const IRQn_Type g_ftmReloadIrqId[FTM_INSTANCE_COUNT]
#define FTM_FMS_FAULTF0(x)
ftm_clock_source_t ftmClockSource
static bool FTM_DRV_GetReloadFlag(const FTM_Type *ftmBase)
Get the state whether the FTM counter reached a reload point.
#define FTM_EXTTRIG_TRIGF_MASK
static bool FTM_DRV_GetQuadTimerOverflowDir(const FTM_Type *ftmBase)
Gets the Timer overflow direction in quadrature mode.
#define FTM_PAIR0DEADTIME_DTVALEX_MASK
static void FTM_DRV_SetChnDmaCmd(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Enables or disables the FTM peripheral timer channel DMA.
static void FTM_DRV_SetClockFilterPs(FTM_Type *const ftmBase, uint8_t filterPrescale)
Sets the filter Pre-scaler divider.
#define FTM_CnSC_CHF_MASK
#define FTM_QDCTRL_PHBFLTREN_SHIFT
ftm_pwm_sync_mode_t syncPoint
static void FTM_DRV_SetGlobalLoadCmd(FTM_Type *const ftmBase)
Set the global load mechanism.
#define FTM_CV_MIRROR_VAL(x)
static void FTM_DRV_SetInitTrigOnReloadCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the FTM initialization trigger on Reload Point.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
static void FTM_DRV_ClearChSC(FTM_Type *const ftmBase, uint8_t channel)
Clears the content of Channel (n) Status And Control.
#define FTM_MOD_MOD_SHIFT
#define FTM_CnSC_CHIE_MASK
#define FTM_SC_CPWMS_MASK
static void FTM_DRV_SetChnSoftwareCtrlVal(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Sets the channel software output control value.
#define FTM_CnSC_ELSB_MASK
ftm_quad_phase_polarity_t
FlexTimer quadrature phase polarities, normal or inverted polarity.
struct FTM_Type::@12 CONTROLS[FTM_CONTROLS_COUNT]
#define FTM_QDCTRL_PHBPOL_MASK
static void FTM_DRV_SetDualChnInvertCmd(FTM_Type *const ftmBase, uint8_t chnlPairNum, bool enable)
Enables or disables the channel invert for a channel pair.
#define FTM_MODE_CAPTEST_MASK
#define FTM_INSTANCE_COUNT
status_t FTM_DRV_SetInvertingControl(uint32_t instance, uint8_t channelsPairMask, bool softwareTrigger)
This function will configure if the second channel of a pair will be inverted or not.
#define FTM_CV_MIRROR_VAL_MASK
#define FTM_PAIR0DEADTIME_DTVAL_MASK
static bool FTM_DRV_GetDualEdgeCaptureBit(const FTM_Type *ftmBase, uint8_t chnlPairNum)
Enables the FTM peripheral timer dual edge capture mode.
#define FTM_CONF_ITRIGR_MASK
static void FTM_DRV_SetTrigModeControlCmd(FTM_Type *const ftmBase, uint8_t channel, bool enable)
Enables or disables the trigger generation on FTM channel outputs.
#define FTM_PAIR3DEADTIME_DTVAL_MASK
ftm_quad_decode_mode_t
FlexTimer quadrature decode modes, phase encode or count and direction mode.
#define FTM_CnSC_ELSA_SHIFT
bool enableInitializationTrigger
#define FTM_PAIR0DEADTIME_DTPS_MASK
#define FTM_PAIR3DEADTIME_DTPS(x)
void(* ftm_channel_event_callback_t)(void *userData)
Channel event callback function.
#define FTM_PAIR1DEADTIME_DTVALEX(x)
static uint32_t FTM_DRV_GetEventStatus(const FTM_Type *ftmBase)
Gets the FTM peripheral timer status info for all channels.
#define FTM_QDCTRL_PHBPOL(x)
ftm_reg_update_t inverterSync
static bool FTM_DRV_IsFaultIntEnabled(const FTM_Type *ftmBase)
Return true/false whether the Fault interrupt was enabled or not.
#define FTM_MODE_CAPTEST(x)
#define FTM_CV_MIRROR_FRACVAL_MASK
#define FTM_PAIR3DEADTIME_DTVALEX(x)
#define FTM_CnSC_CHOV_MASK
static void FTM_DRV_SetQuadPhaseBPolarity(FTM_Type *const ftmBase, ftm_quad_phase_polarity_t mode)
Selects polarity for the quadrature decode phase B input.
const IRQn_Type g_ftmFaultIrqId[FTM_INSTANCE_COUNT]
#define FTM_CnSC_MSA_SHIFT
ftm_config_mode_t ftmMode
#define FTM_FMS_FAULTF2(x)
static void FTM_DRV_SetLoadFreq(FTM_Type *const ftmBase, uint8_t val)
Sets the FTM timer TOF Frequency.
#define FTM_COMBINE_DECAPEN0_MASK
static bool FTM_DRV_IsFtmEnable(const FTM_Type *ftmBase)
Get status of the FTMEN bit in the FTM_MODE register.
#define FTM_SC_CPWMS_SHIFT
static void FTM_DRV_SetGlobalTimeBaseCmd(FTM_Type *const ftmBase, bool enable)
Enables or disables the FTM timer global time base.
static void FTM_DRV_SetHalfCycleCmd(FTM_Type *const ftmBase, bool enable)
Enable the half cycle reload.
#define FTM_SYNC_REINIT_MASK
#define FTM_FMS_FAULTF3_MASK
static bool FTM_DRV_GetChInputState(const FTM_Type *ftmBase, uint8_t channel)
Get the state of channel input.
#define FTM_FMS_FAULTF1(x)
#define FTM_CnSC_CHIS_MASK
#define FTM_PAIR0DEADTIME_DTPS(x)
status_t FTM_DRV_SetModuloCounterValue(uint32_t instance, uint16_t counterValue, bool softwareTrigger)
This function configure the maximum counter value.
#define FTM_CONF_GTBEEN(x)
#define FTM_CnSC_TRIGMODE_MASK
#define FTM_CONF_ITRIGR(x)
ftm_config_mode_t ftmMode
static void FTM_DRV_SetChnOutputMask(FTM_Type *const ftmBase, uint8_t channel, bool mask)
Sets the FTM peripheral timer channel output mask.
#define FTM_CV_MIRROR_VAL_SHIFT
#define FTM_CONF_LDFQ_MASK
static void FTM_DRV_SetQuadMode(FTM_Type *const ftmBase, ftm_quad_decode_mode_t quadMode)
Sets the encoding mode used in quadrature decoding mode.
#define FTM_FEATURE_COMBINE_CHAN_CTRL_WIDTH
static void FTM_DRV_SetReIntEnabledCmd(FTM_Type *const ftmBase, bool enable)
Set the FTM reload interrupt enable.
status_t FTM_DRV_Deinit(uint32_t instance)
Shuts down the FTM driver.
#define FTM_FMS_FAULTIN_MASK
#define FTM_CnSC_ICRST(x)
static bool FTM_DRV_HasChnEventOccurred(const FTM_Type *ftmBase, uint8_t channel)
Returns whether any event for the FTM peripheral timer channel has occurred.
status_t FTM_DRV_MaskOutputChannels(uint32_t instance, uint32_t channelsMask, bool softwareTrigger)
This function will mask the output of the channels and at match events will be ignored by the masked ...
#define FTM_EXTTRIG_TRIGF(x)
ftm_reg_update_t maskRegSync
#define FTM_MOD_MIRROR_MOD_MASK
#define FTM_PAIR2DEADTIME_DTVAL(x)
#define FTM_SYNC_REINIT(x)
static void FTM_DRV_ClearChnEventStatus(FTM_Type *const ftmBase, uint8_t channel)
Clears the FTM peripheral timer all channel event status.
#define FTM_CnSC_ICRST_MASK
#define FTM_PAIR1DEADTIME_DTVALEX_MASK
#define FTM_MODE_FTMEN_SHIFT
static uint16_t FTM_DRV_GetMod(const FTM_Type *ftmBase)
Returns the FTM peripheral counter modulo value.
#define FTM_CnSC_DMA_MASK
static bool FTM_DRV_IsFaultFlagDetected(const FTM_Type *ftmBase, uint8_t channel)
Checks whether a fault condition is detected at the fault input.
#define FTM_CnSC_MSA_MASK
status_t FTM_DRV_Init(uint32_t instance, const ftm_user_config_t *info, ftm_state_t *state)
Initializes the FTM driver.
status_t FTM_DRV_SetSoftOutChnValue(uint32_t instance, uint8_t channelsValues, bool softwareTrigger)
This function will force the output value of a channel to a specific value. Before using this functio...
static void FTM_DRV_SetPairDeadtimeCount(FTM_Type *const ftmBase, uint8_t channelPair, uint8_t count)
Sets the FTM dead-time value for the channel pair.
#define FTM_PAIR2DEADTIME_DTVALEX(x)
#define FTM_PAIR0DEADTIME_DTVAL(x)
#define FTM_CNT_COUNT_SHIFT
#define FTM_QDCTRL_PHAPOL_MASK
#define FTM_PWMLOAD_LDOK_SHIFT
#define FTM_MODE_FTMEN_MASK
static void FTM_DRV_DisableFaultInt(FTM_Type *const ftmBase)
Disables the FTM peripheral timer fault interrupt.
static bool FTM_DRV_GetDetectedFaultInput(const FTM_Type *ftmBase)
Gets the FTM detected fault input.
static bool FTM_DRV_IsFaultInputEnabled(const FTM_Type *ftmBase)
Checks whether the logic OR of the fault inputs is enabled.
#define FTM_PAIR2DEADTIME_DTPS_MASK
#define FTM_PAIR2DEADTIME_DTVAL_MASK
ftm_clock_source_t ftmClockSource
static void FTM_DRV_SetPairDeadtimePrescale(FTM_Type *const ftmBase, uint8_t channelPair, ftm_deadtime_ps_t divider)
Sets the FTM dead time divider for the channel pair.
#define FTM_FMS_FAULTF(x)
#define FTM_CnSC_MSB_MASK
ftm_config_mode_t
FlexTimer operation mode.
#define FTM_CNT_COUNT_MASK
uint32_t ftmSourceClockFrequency
const IRQn_Type g_ftmIrqId[FTM_INSTANCE_COUNT][FEATURE_FTM_CHANNEL_COUNT]
Interrupt vectors for the FTM peripheral.
#define FTM_CV_MIRROR_FRACVAL_SHIFT
ftm_reg_update_t outRegSync
#define FTM_SC_FLTPS_SHIFT
static bool FTM_DRV_IsOverflowIntEnabled(const FTM_Type *ftmBase)
Reads the bit that controls enabling the FTM timer overflow interrupt.
static uint16_t FTM_DRV_GetCounter(const FTM_Type *ftmBase)
Returns the FTM peripheral current counter value.
static bool FTM_DRV_GetTriggerControled(const FTM_Type *ftmBase, uint8_t channel)
Returns whether the trigger mode is enabled.
ftm_clock_ps_t ftmPrescaler
IRQn_Type
Defines the Interrupt Numbers definitions.
static void FTM_DRV_ClearFaultFlagDetected(FTM_Type *const ftmBase, uint8_t channel)
Clear a fault condition is detected at the fault input.
#define FTM_FMS_FAULTF2_MASK
#define FTM_PAIR0DEADTIME_DTVALEX(x)