S32 SDK
ftm_common.h File Reference
#include "ftm_hw_access.h"

Go to the source code of this file.

Data Structures

struct  ftm_state_t
 FlexTimer state structure of the driver. More...
 
struct  ftm_pwm_sync_t
 FlexTimer Registers sync parameters Please don't use software and hardware trigger simultaneously Implements : ftm_pwm_sync_t_Class. More...
 
struct  ftm_user_config_t
 Configuration structure that the user needs to set. More...
 

Typedefs

typedef void(* ftm_channel_event_callback_t) (void *userData)
 Channel event callback function. More...
 

Enumerations

enum  ftm_config_mode_t {
  FTM_MODE_NOT_INITIALIZED = 0x00U, FTM_MODE_INPUT_CAPTURE = 0x01U, FTM_MODE_OUTPUT_COMPARE = 0x02U, FTM_MODE_EDGE_ALIGNED_PWM = 0x03U,
  FTM_MODE_CEN_ALIGNED_PWM = 0x04U, FTM_MODE_QUADRATURE_DECODER = 0x05U, FTM_MODE_UP_TIMER = 0x06U, FTM_MODE_UP_DOWN_TIMER = 0x07U
}
 FlexTimer operation mode. More...
 
enum  ftm_quad_decode_mode_t { FTM_QUAD_PHASE_ENCODE = 0x00U, FTM_QUAD_COUNT_AND_DIR = 0x01U }
 FlexTimer quadrature decode modes, phase encode or count and direction mode. More...
 
enum  ftm_quad_phase_polarity_t { FTM_QUAD_PHASE_NORMAL = 0x00U, FTM_QUAD_PHASE_INVERT = 0x01U }
 FlexTimer quadrature phase polarities, normal or inverted polarity. More...
 

Functions

static void FTM_DRV_SetClockFilterPs (FTM_Type *const ftmBase, uint8_t filterPrescale)
 Sets the filter Pre-scaler divider. More...
 
static uint8_t FTM_DRV_GetClockFilterPs (const FTM_Type *ftmBase)
 Reads the FTM filter clock divider. More...
 
static uint8_t FTM_DRV_GetClockSource (const FTM_Type *ftmBase)
 Reads the FTM clock source. More...
 
static uint8_t FTM_DRV_GetClockPs (const FTM_Type *ftmBase)
 Reads the FTM clock divider. More...
 
static bool FTM_DRV_IsOverflowIntEnabled (const FTM_Type *ftmBase)
 Reads the bit that controls enabling the FTM timer overflow interrupt. More...
 
static bool FTM_DRV_HasTimerOverflowed (const FTM_Type *ftmBase)
 Returns the FTM peripheral timer overflow interrupt flag. More...
 
static bool FTM_DRV_GetCpwms (const FTM_Type *ftmBase)
 Gets the FTM count direction bit. More...
 
static void FTM_DRV_SetReIntEnabledCmd (FTM_Type *const ftmBase, bool enable)
 Set the FTM reload interrupt enable. More...
 
static bool FTM_DRV_GetReloadFlag (const FTM_Type *ftmBase)
 Get the state whether the FTM counter reached a reload point. More...
 
static void FTM_DRV_ClearReloadFlag (FTM_Type *const ftmBase)
 Clears the reload flag bit. More...
 
static uint16_t FTM_DRV_GetCounter (const FTM_Type *ftmBase)
 Returns the FTM peripheral current counter value. More...
 
static uint16_t FTM_DRV_GetMod (const FTM_Type *ftmBase)
 Returns the FTM peripheral counter modulo value. More...
 
static uint16_t FTM_DRV_GetCounterInitVal (const FTM_Type *ftmBase)
 Returns the FTM peripheral counter initial value. More...
 
static void FTM_DRV_ClearChSC (FTM_Type *const ftmBase, uint8_t channel)
 Clears the content of Channel (n) Status And Control. More...
 
static uint8_t FTM_DRV_GetChnMode (const FTM_Type *ftmBase, uint8_t channel)
 Gets the FTM peripheral timer channel mode. More...
 
static uint8_t FTM_DRV_GetChnEdgeLevel (const FTM_Type *ftmBase, uint8_t channel)
 Gets the FTM peripheral timer channel edge level. More...
 
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. More...
 
static bool FTM_DRV_IsChnIcrst (const FTM_Type *ftmBase, uint8_t channel)
 Returns whether the FTM FTM counter is reset. More...
 
static void FTM_DRV_SetChnDmaCmd (FTM_Type *const ftmBase, uint8_t channel, bool enable)
 Enables or disables the FTM peripheral timer channel DMA. More...
 
static bool FTM_DRV_IsChnDma (const FTM_Type *ftmBase, uint8_t channel)
 Returns whether the FTM peripheral timer channel DMA is enabled. More...
 
static bool FTM_DRV_IsChnIntEnabled (const FTM_Type *ftmBase, uint8_t channel)
 Get FTM channel(n) interrupt enabled or not. More...
 
static bool FTM_DRV_HasChnEventOccurred (const FTM_Type *ftmBase, uint8_t channel)
 Returns whether any event for the FTM peripheral timer channel has occurred. More...
 
static void FTM_DRV_SetTrigModeControlCmd (FTM_Type *const ftmBase, uint8_t channel, bool enable)
 Enables or disables the trigger generation on FTM channel outputs. More...
 
static bool FTM_DRV_GetTriggerControled (const FTM_Type *ftmBase, uint8_t channel)
 Returns whether the trigger mode is enabled. More...
 
static bool FTM_DRV_GetChInputState (const FTM_Type *ftmBase, uint8_t channel)
 Get the state of channel input. More...
 
static bool FTM_DRV_GetChOutputValue (const FTM_Type *ftmBase, uint8_t channel)
 Get the value of channel output. More...
 
static uint16_t FTM_DRV_GetChnCountVal (const FTM_Type *ftmBase, uint8_t channel)
 Gets the FTM peripheral timer channel counter value. More...
 
static bool FTM_DRV_GetChnEventStatus (const FTM_Type *ftmBase, uint8_t channel)
 Gets the FTM peripheral timer channel event status. More...
 
static uint32_t FTM_DRV_GetEventStatus (const FTM_Type *ftmBase)
 Gets the FTM peripheral timer status info for all channels. More...
 
static void FTM_DRV_ClearChnEventStatus (FTM_Type *const ftmBase, uint8_t channel)
 Clears the FTM peripheral timer all channel event status. More...
 
static void FTM_DRV_SetChnOutputMask (FTM_Type *const ftmBase, uint8_t channel, bool mask)
 Sets the FTM peripheral timer channel output mask. More...
 
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. More...
 
static void FTM_DRV_DisableFaultInt (FTM_Type *const ftmBase)
 Disables the FTM peripheral timer fault interrupt. More...
 
static bool FTM_DRV_IsFaultIntEnabled (const FTM_Type *ftmBase)
 Return true/false whether the Fault interrupt was enabled or not. More...
 
static void FTM_DRV_ClearFaultsIsr (FTM_Type *const ftmBase)
 Clears all fault interrupt flags that are active. More...
 
static void FTM_DRV_SetCaptureTestCmd (FTM_Type *const ftmBase, bool enable)
 Enables or disables the FTM peripheral timer capture test mode. More...
 
static bool FTM_DRV_IsFtmEnable (const FTM_Type *ftmBase)
 Get status of the FTMEN bit in the FTM_MODE register. More...
 
static void FTM_DRV_SetInitChnOutputCmd (FTM_Type *const ftmBase, bool enable)
 Initializes the channels output. More...
 
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 detected. More...
 
static bool FTM_DRV_GetDualEdgeCaptureBit (const FTM_Type *ftmBase, uint8_t chnlPairNum)
 Enables the FTM peripheral timer dual edge capture mode. More...
 
static bool FTM_DRV_GetDualChnCombineCmd (const FTM_Type *ftmBase, uint8_t chnlPairNum)
 Verify if an channels pair is used in combine mode or not. More...
 
static bool FTM_DRV_IsChnTriggerGenerated (const FTM_Type *ftmBase)
 Checks whether any channel trigger event has occurred. More...
 
static void FTM_DRV_ClearChnTriggerFlag (FTM_Type *const ftmBase)
 Clear the channel trigger flag. More...
 
static bool FTM_DRV_GetDetectedFaultInput (const FTM_Type *ftmBase)
 Gets the FTM detected fault input. More...
 
static bool FTM_DRV_IsWriteProtectionEnabled (const FTM_Type *ftmBase)
 Checks whether the write protection is enabled. More...
 
static bool FTM_DRV_IsFaultInputEnabled (const FTM_Type *ftmBase)
 Checks whether the logic OR of the fault inputs is enabled. More...
 
static bool FTM_DRV_IsFaultFlagDetected (const FTM_Type *ftmBase, uint8_t channel)
 Checks whether a fault condition is detected at the fault input. More...
 
static void FTM_DRV_ClearFaultFlagDetected (FTM_Type *const ftmBase, uint8_t channel)
 Clear a fault condition is detected at the fault input. More...
 
static void FTM_DRV_SetQuadPhaseBFilterCmd (FTM_Type *const ftmBase, bool enable)
 Enables or disables the phase B input filter. More...
 
static void FTM_DRV_SetQuadPhaseAPolarity (FTM_Type *const ftmBase, ftm_quad_phase_polarity_t mode)
 Selects polarity for the quadrature decode phase A input. More...
 
static void FTM_DRV_SetQuadPhaseBPolarity (FTM_Type *const ftmBase, ftm_quad_phase_polarity_t mode)
 Selects polarity for the quadrature decode phase B input. More...
 
static void FTM_DRV_SetQuadMode (FTM_Type *const ftmBase, ftm_quad_decode_mode_t quadMode)
 Sets the encoding mode used in quadrature decoding mode. More...
 
static bool FTM_DRV_GetQuadDir (const FTM_Type *ftmBase)
 Gets the FTM counter direction in quadrature mode. More...
 
static bool FTM_DRV_GetQuadTimerOverflowDir (const FTM_Type *ftmBase)
 Gets the Timer overflow direction in quadrature mode. More...
 
static void FTM_DRV_SetDualChnInvertCmd (FTM_Type *const ftmBase, uint8_t chnlPairNum, bool enable)
 Enables or disables the channel invert for a channel pair. More...
 
static void FTM_DRV_SetChnSoftwareCtrlCmd (FTM_Type *const ftmBase, uint8_t channel, bool enable)
 Enables or disables the channel software output control. More...
 
static void FTM_DRV_SetChnSoftwareCtrlVal (FTM_Type *const ftmBase, uint8_t channel, bool enable)
 Sets the channel software output control value. More...
 
static void FTM_DRV_SetGlobalLoadCmd (FTM_Type *const ftmBase)
 Set the global load mechanism. More...
 
static void FTM_DRV_SetLoadCmd (FTM_Type *const ftmBase, bool enable)
 Enable the global load. More...
 
static void FTM_DRV_SetHalfCycleCmd (FTM_Type *const ftmBase, bool enable)
 Enable the half cycle reload. More...
 
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. More...
 
static void FTM_DRV_SetPwmLoadChnSelCmd (FTM_Type *const ftmBase, uint8_t channel, bool enable)
 Includes or excludes the channel in the matching process. More...
 
static void FTM_DRV_SetInitTrigOnReloadCmd (FTM_Type *const ftmBase, bool enable)
 Enables or disables the FTM initialization trigger on Reload Point. More...
 
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. More...
 
static void FTM_DRV_SetGlobalTimeBaseCmd (FTM_Type *const ftmBase, bool enable)
 Enables or disables the FTM timer global time base. More...
 
static void FTM_DRV_SetLoadFreq (FTM_Type *const ftmBase, uint8_t val)
 Sets the FTM timer TOF Frequency. More...
 
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. More...
 
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. More...
 
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. More...
 
status_t FTM_DRV_Init (uint32_t instance, const ftm_user_config_t *info, ftm_state_t *state)
 Initializes the FTM driver. More...
 
status_t FTM_DRV_Deinit (uint32_t instance)
 Shuts down the FTM driver. More...
 
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 channels. More...
 
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 event. More...
 
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. More...
 
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 function it's mandatory to mask the match events using FTM_DRV_MaskOutputChannels and to enable software output control using FTM_DRV_SetSoftwareOutputChannelControl. More...
 
status_t FTM_DRV_SetSoftwareOutputChannelControl (uint32_t instance, uint8_t channelsMask, bool softwareTrigger)
 This function will configure which output channel can be software controlled. More...
 
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. More...
 
status_t FTM_DRV_SetModuloCounterValue (uint32_t instance, uint16_t counterValue, bool softwareTrigger)
 This function configure the maximum counter value. More...
 
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). More...
 
uint32_t FTM_DRV_GetFrequency (uint32_t instance)
 Retrieves the frequency of the clock source feeding the FTM counter. More...
 
uint16_t FTM_DRV_ConvertFreqToPeriodTicks (uint32_t instance, uint32_t freqencyHz)
 This function is used to covert the given frequency to period in ticks. More...
 

Variables

FTM_Type *const g_ftmBase [FTM_INSTANCE_COUNT]
 Table of base addresses for FTM instances. More...
 
const IRQn_Type g_ftmIrqId [FTM_INSTANCE_COUNT][FEATURE_FTM_CHANNEL_COUNT]
 Interrupt vectors for the FTM peripheral. More...
 
const IRQn_Type g_ftmFaultIrqId [FTM_INSTANCE_COUNT]
 
const IRQn_Type g_ftmOverflowIrqId [FTM_INSTANCE_COUNT]
 
const IRQn_Type g_ftmReloadIrqId [FTM_INSTANCE_COUNT]
 
ftm_state_tftmStatePtr [FTM_INSTANCE_COUNT]
 Pointer to runtime state structure. More...