ftm_common.h File Reference
#include <stddef.h>
#include "status.h"
#include "device_registers.h"
#include "callbacks.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...
 

Macros

#define FTM_RMW_SC(base, mask, value)   (((base)->SC) = ((((base)->SC) & ~(mask)) | (value)))
 FTM_SC - Read and modify and write to Status And Control (RW) More...
 
#define FTM_RMW_CNT(base, mask, value)   (((base)->CNT) = ((((base)->CNT) & ~(mask)) | (value)))
 FTM_CNT - Read and modify and write to Counter (RW) More...
 
#define FTM_RMW_MOD(base, mask, value)   (((base)->MOD) = ((((base)->MOD) & ~(mask)) | (value)))
 FTM_MOD - Read and modify and write Modulo (RW) More...
 
#define FTM_RMW_CNTIN(base, mask, value)   (((base)->CNTIN) = ((((base)->CNTIN) & ~(mask)) | (value)))
 FTM_CNTIN - Read and modify and write Counter Initial Value (RW) More...
 
#define FTM_RMW_STATUS(base, mask, value)   (((base)->STATUS) = ((((base)->STATUS) & ~(mask)) | (value)))
 FTM_STATUS - Read and modify and write Capture And Compare Status (RW) More...
 
#define FTM_RMW_MODE(base, mask, value)   (((base)->MODE) = ((((base)->MODE) & ~(mask)) | (value)))
 FTM_MODE - Read and modify and write Counter Features Mode Selection (RW) More...
 
#define FTM_RMW_CnSCV_REG(base, channel, mask, value)   (((base)->CONTROLS[channel].CnSC) = ((((base)->CONTROLS[channel].CnSC) & ~(mask)) | (value)))
 FTM_CnSCV - Read and modify and write Channel (n) Status And Control (RW) More...
 
#define FTM_RMW_DEADTIME(base, mask, value)   (((base)->DEADTIME) = ((((base)->DEADTIME) & ~(mask)) | (value)))
 FTM_DEADTIME - Read and modify and write Dead-time Insertion Control (RW) More...
 
#define FTM_RMW_EXTTRIG_REG(base, mask, value)   (((base)->EXTTRIG) = ((((base)->EXTTRIG) & ~(mask)) | (value)))
 FTM_EXTTRIG - Read and modify and write External Trigger Control (RW) More...
 
#define FTM_RMW_FLTCTRL(base, mask, value)   (((base)->FLTCTRL) = ((((base)->FLTCTRL) & ~(mask)) | (value)))
 FTM_FLTCTRL - Read and modify and write Fault Control (RW) More...
 
#define FTM_RMW_FMS(base, mask, value)   (((base)->FMS) = ((((base)->FMS) & ~(mask)) | (value)))
 FTM_FMS - Read and modify and write Fault Mode Status (RW) More...
 
#define FTM_RMW_CONF(base, mask, value)   (((base)->CONF) = ((((base)->CONF) & ~(mask)) | (value)))
 FTM_CONF - Read and modify and write Configuration (RW) More...
 
#define FTM_RMW_POL(base, mask, value)   (((base)->POL) = ((((base)->POL) & ~(mask)) | (value)))
 POL - Read and modify and write Polarity (RW) More...
 
#define FTM_RMW_FILTER(base, mask, value)   (((base)->FILTER) = ((((base)->FILTER) & ~(mask)) | (value)))
 FILTER - Read and modify and write Filter (RW) More...
 
#define FTM_RMW_SYNC(base, mask, value)   (((base)->SYNC) = ((((base)->SYNC) & ~(mask)) | (value)))
 SYNC - Read and modify and write Synchronization (RW) More...
 
#define FTM_RMW_QDCTRL(base, mask, value)   (((base)->QDCTRL) = ((((base)->QDCTRL) & ~(mask)) | (value)))
 QDCTRL - Read and modify and write Quadrature Decoder Control And Status (RW) More...
 
#define FTM_RMW_PAIR0DEADTIME(base, mask, value)   (((base)->PAIR0DEADTIME) = ((((base)->PAIR0DEADTIME) & ~(mask)) | (value)))
 FTM_PAIR0DEADTIME - Read and modify and write Dead-time Insertion Control for the pair 0 (RW) More...
 
#define FTM_RMW_PAIR1DEADTIME(base, mask, value)   (((base)->PAIR1DEADTIME) = ((((base)->PAIR1DEADTIME) & ~(mask)) | (value)))
 FTM_PAIR1DEADTIME - Read and modify and write Dead-time Insertion Control for the pair 1 (RW) More...
 
#define FTM_RMW_PAIR2DEADTIME(base, mask, value)   (((base)->PAIR2DEADTIME) = ((((base)->PAIR2DEADTIME) & ~(mask)) | (value)))
 FTM_PAIR2DEADTIME - Read and modify and write Dead-time Insertion Control for the pair 2 (RW) More...
 
#define FTM_RMW_PAIR3DEADTIME(base, mask, value)   (((base)->PAIR3DEADTIME) = ((((base)->PAIR3DEADTIME) & ~(mask)) | (value)))
 FTM_PAIR3DEADTIME - Read and modify and write Dead-time Insertion Control for the pair 3 (RW) More...
 
#define FTM_RMW_MOD_MIRROR(base, mask, value)   (((base)->MOD_MIRROR) = ((((base)->MOD_MIRROR) & ~(mask)) | (value)))
 FTM_MOD_MIRROR - Read and modify and write mirror of modulo value for the FTM counter (RW) More...
 
#define FTM_RMW_CnV_MIRROR(base, channel, mask, value)   (((base)->CV_MIRROR[channel]) = ((((base)->CV_MIRROR[channel]) & ~(mask)) | (value)))
 FTM_CnV_MIRROR - Read and modify and write mirror of channel (n) match value (RW) More...
 
#define CHAN0_IDX   (0U)
 Channel number for CHAN1. More...
 
#define CHAN1_IDX   (1U)
 Channel number for CHAN2. More...
 
#define CHAN2_IDX   (2U)
 Channel number for CHAN3. More...
 
#define CHAN3_IDX   (3U)
 Channel number for CHAN4. More...
 
#define CHAN4_IDX   (4U)
 Channel number for CHAN5. More...
 
#define CHAN5_IDX   (5U)
 Channel number for CHAN6. More...
 
#define CHAN6_IDX   (6U)
 Channel number for CHAN7. More...
 
#define CHAN7_IDX   (7U)
 

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_clock_source_t { FTM_CLOCK_SOURCE_NONE = 0x00U, FTM_CLOCK_SOURCE_SYSTEMCLK = 0x01U, FTM_CLOCK_SOURCE_FIXEDCLK = 0x02U, FTM_CLOCK_SOURCE_EXTERNALCLK = 0x03U }
 FlexTimer clock source selection. More...
 
enum  ftm_clock_ps_t {
  FTM_CLOCK_DIVID_BY_1 = 0x00U, FTM_CLOCK_DIVID_BY_2 = 0x01U, FTM_CLOCK_DIVID_BY_4 = 0x02U, FTM_CLOCK_DIVID_BY_8 = 0x03U,
  FTM_CLOCK_DIVID_BY_16 = 0x04U, FTM_CLOCK_DIVID_BY_32 = 0x05U, FTM_CLOCK_DIVID_BY_64 = 0x06U, FTM_CLOCK_DIVID_BY_128 = 0x07U
}
 FlexTimer pre-scaler factor selection for the clock source. In quadrature decoder mode set FTM_CLOCK_DIVID_BY_1. More...
 
enum  ftm_interrupt_option_t {
  FTM_CHANNEL0_INT_ENABLE = 0x00000001U, FTM_CHANNEL1_INT_ENABLE = 0x00000002U, FTM_CHANNEL2_INT_ENABLE = 0x00000004U, FTM_CHANNEL3_INT_ENABLE = 0x00000008U,
  FTM_CHANNEL4_INT_ENABLE = 0x00000010U, FTM_CHANNEL5_INT_ENABLE = 0x00000020U, FTM_CHANNEL6_INT_ENABLE = 0x00000040U, FTM_CHANNEL7_INT_ENABLE = 0x00000080U,
  FTM_FAULT_INT_ENABLE = 0x00000100U, FTM_TIME_OVER_FLOW_INT_ENABLE = 0x00000200U, FTM_RELOAD_INT_ENABLE = 0x00000400U
}
 List of FTM interrupts. More...
 
enum  ftm_status_flag_t {
  FTM_CHANNEL0_FLAG = 0x00000001U, FTM_CHANNEL1_FLAG = 0x00000002U, FTM_CHANNEL2_FLAG = 0x00000004U, FTM_CHANNEL3_FLAG = 0x00000008U,
  FTM_CHANNEL4_FLAG = 0x00000010U, FTM_CHANNEL5_FLAG = 0x00000020U, FTM_CHANNEL6_FLAG = 0x00000040U, FTM_CHANNEL7_FLAG = 0x00000080U,
  FTM_FAULT_FLAG = 0x00000100U, FTM_TIME_OVER_FLOW_FLAG = 0x00000200U, FTM_RELOAD_FLAG = 0x00000400U, FTM_CHANNEL_TRIGGER_FLAG = 0x00000800U
}
 List of FTM flags. More...
 
enum  ftm_reg_update_t { FTM_SYSTEM_CLOCK = 0U, FTM_PWM_SYNC = 1U }
 FTM sync source. More...
 
enum  ftm_pwm_sync_mode_t { FTM_WAIT_LOADING_POINTS = 0U, FTM_UPDATE_NOW = 1U }
 FTM update register. More...
 
enum  ftm_deadtime_ps_t { FTM_DEADTIME_DIVID_BY_1 = 0x01U, FTM_DEADTIME_DIVID_BY_4 = 0x02U, FTM_DEADTIME_DIVID_BY_16 = 0x03U }
 FlexTimer pre-scaler factor for the dead-time insertion. 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...
 
enum  ftm_bdm_mode_t { FTM_BDM_MODE_00 = 0x00U, FTM_BDM_MODE_01 = 0x01U, FTM_BDM_MODE_10 = 0x02U, FTM_BDM_MODE_11 = 0x03U }
 Options for the FlexTimer behavior in BDM Mode. 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 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_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 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 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_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_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_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...
 
static void FTM_DRV_SetMirrorMod (FTM_Type *const ftmBase, uint16_t value)
 Sets the mirror of the modulo integer value. More...
 
static uint16_t FTM_DRV_GetMirrorMod (const FTM_Type *ftmBase)
 Returns the mirror of the FTM peripheral counter modulo value. More...
 
static uint8_t FTM_DRV_GetModFracVal (const FTM_Type *ftmBase)
 Returns The modulo fractional value is used in the PWM period dithering. More...
 
static void FTM_DRV_SetMirrorChnMatchVal (FTM_Type *const ftmBase, uint8_t channel, uint16_t value)
 Sets the mirror of the channel (n) match integer value. More...
 
static uint16_t FTM_DRV_GetMirrorChnMatchVal (const FTM_Type *ftmBase, uint8_t channel)
 Returns the mirror of the channel (n) match integer value. More...
 
static uint8_t FTM_DRV_GetChnMatchFracVal (const FTM_Type *ftmBase, uint8_t channel)
 Returns the channel (n) match fractional value. 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_SetAllChnSoftwareOutputControl (uint32_t instance, uint8_t channelMask, uint8_t channelValueMask)
 This function will control list of channels by software to force the output to specified value. 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_SetOutputlevel (uint32_t instance, uint8_t channel, uint8_t level)
 This function will set the channel edge or level on the selection of the channel mode. 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...
 
status_t FTM_DRV_EnableInterrupts (uint32_t instance, uint32_t interruptMask)
 This function will enable the generation a list of interrupts. It includes the FTM overflow interrupts, the reload point interrupt, the fault interrupt and the channel (n) interrupt. More...
 
void FTM_DRV_DisableInterrupts (uint32_t instance, uint32_t interruptMask)
 This function is used to disable some interrupts. More...
 
uint32_t FTM_DRV_GetEnabledInterrupts (uint32_t instance)
 This function will get the enabled FTM interrupts. More...
 
uint32_t FTM_DRV_GetStatusFlags (uint32_t instance)
 This function will get the FTM status flags. More...
 
void FTM_DRV_ClearStatusFlags (uint32_t instance, uint32_t flagMask)
 This function is used to clear the FTM status flags. 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 [(2u)]
 Table of base addresses for FTM instances. More...
 
const IRQn_Type g_ftmIrqId [(2u)][(8U)]
 Interrupt vectors for the FTM peripheral. More...
 
const IRQn_Type g_ftmFaultIrqId [(2u)]
 
const IRQn_Type g_ftmOverflowIrqId [(2u)]
 
const IRQn_Type g_ftmReloadIrqId [(2u)]
 
ftm_state_tftmStatePtr [(2u)]
 Pointer to runtime state structure. More...