PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
Input Capture Unit (ICU)

How to use ICU module. More...

Data Structures

struct  stc_mft_icu_config
 Structure of Mft icu configuration. More...
 
struct  stc_mft_icu_intern_data
 Icu instance internal data, storing internal information for each enabled Icu instance. More...
 
struct  stc_mft_icu_instance_data
 Mft_icu instance data type. More...
 

Macros

#define stc_mftn_icu_t   FM4_MFT_ICU_TypeDef
 
#define MFT0_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT0_ICU_BASE))
 
#define MFT1_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT1_ICU_BASE))
 
#define MFT2_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT2_ICU_BASE))
 
#define MFT_ICU_CH0   0u
 
#define MFT_ICU_CH1   1u
 
#define MFT_ICU_CH2   2u
 
#define MFT_ICU_CH3   3u
 
#define MFT_ICU_CHx_MAX   3u
 
#define MFT_ICU_INSTANCE_COUNT
 

Typedefs

typedef enum en_icu_instance_index en_icu_instance_index_t
 Enumeration to define an index for each ICU instance. More...
 
typedef enum en_mft_icu_frt en_mft_icu_frt_t
 Frt channel. More...
 
typedef enum en_mft_icu_mode en_mft_icu_mode_t
 Icu mode. More...
 
typedef enum en_icu_edge en_mft_icu_edge_t
 Icu edge. More...
 
typedef struct stc_mft_icu_config stc_mft_icu_config_t
 Structure of Mft icu configuration. More...
 
typedef struct
stc_mft_icu_intern_data 
stc_mft_icu_intern_data_t
 Icu instance internal data, storing internal information for each enabled Icu instance. More...
 
typedef struct
stc_mft_icu_instance_data 
stc_mft_icu_instance_data_t
 Mft_icu instance data type. More...
 

Enumerations

enum  en_icu_instance_index {
  IcuInstanceIndexIcu0 = 0u,
  IcuInstanceIndexIcu1 = 1u,
  IcuInstanceIndexIcu2 = 2u
}
 Enumeration to define an index for each ICU instance. More...
 
enum  en_mft_icu_frt {
  Frt0ToIcu = 0u,
  Frt1ToIcu = 1u,
  Frt2ToIcu = 2u,
  IcuFrtToExt0 = 3u,
  IcuFrtToExt1 = 4u
}
 Frt channel. More...
 
enum  en_mft_icu_mode {
  IcuDisable = 0u,
  IcuRisingDetect = 1u,
  IcuFallingDetect = 2u,
  IcuBothDetect = 3u
}
 Icu mode. More...
 
enum  en_icu_edge {
  IcuFallingEdge = 0u,
  IcuRisingEdge = 1u
}
 Icu edge. More...
 

Functions

static stc_mft_icu_intern_data_t * MftIcuGetInternDataPtr (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu)
 Return the internal data for a certain MFT_ICU instance. More...
 
static en_result_t MftIcu_InitIrq (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu)
 Device dependent initialization of interrupts according CMSIS with level defined in l3.h. More...
 
static en_result_t MftIcu_DeInitIrq (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu)
 Device dependent de-initialization of interrupts according CMSIS. More...
 
void Mft_Icu_IrqHandler (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, stc_mft_icu_intern_data_t *pstcMftIcuInternData)
 Device Interrupt handler. More...
 
en_result_t Mft_Icu_SelFrt (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, en_mft_icu_frt_t enFrt)
 Select FRTx channel to connect to ICUx. More...
 
en_result_t Mft_Icu_ConfigDetectMode (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, en_mft_icu_mode_t enMode)
 Configure ICU module detection mode(different edge) More...
 
en_result_t Mft_Icu_EnableInt (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, func_ptr_t pfnCallback)
 Enable Mft Icu interrupt. More...
 
en_result_t Mft_Icu_DisableInt (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Disable Mft Icu interrupt and release callback function. More...
 
en_int_flag_t Mft_Icu_GetIntFlag (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Get interrupt flag. More...
 
en_result_t Mft_Icu_ClrIntFlag (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Clear interrupt flag. More...
 
en_mft_icu_edge_t Mft_Icu_GetLastEdge (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Get the latest captured edge type. More...
 
uint16_t Mft_Icu_GetCaptureData (volatile FM4_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Readout captured data value. More...
 

Variables

stc_mft_icu_instance_data_t m_astcMftIcuInstanceDataLut [(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT0_ICU==PDL_ON)+(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT1_ICU==PDL_ON)+(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT2_ICU==PDL_ON)]
 
stc_mft_icu_instance_data_t m_astcMftIcuInstanceDataLut [(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT0_ICU==PDL_ON)+(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT1_ICU==PDL_ON)+(uint8_t)(PDL_PERIPHERAL_ENABLE_MFT2_ICU==PDL_ON)]
 

Detailed Description

How to use ICU module.

Provided functions of ICU module:

Before using OCU, a FRT used to connect with applying OCU must be initialed. For how to configure FRT, see the description in the mft_frt.h. With Mft_Icu_SelFrt(), a FRT can be connected with OCU.

A ICU interrupt can be enabled by the function Mft_Icu_EnableInt(). This function can set callback function for each channel too.

After above setting, calling Mft_Icu_ConfigDetectMode() will select a detection mode and start ICU operation at the same time. Following detection mode cna be select:

With interrupt mode, the interrupt occurs when valid edge is detected, the interrupt flag will be cleared and run into user interrupt callback function. In the callback fucntion, the capture value can be read with Mft_Icu_GetCaptureData().

With polling mode, user can use Mft_Icu_GetIntFlag() to check if the interrupt occurs, and clear the interrupt flag by Mft_Icu_ClrIntFlag(). when interrupt is detected, the capture value can be read with Mft_Icu_GetCaptureData().

When the valid edge is detected, Mft_Icu_GetLastEdge() can get the edge information of last valid edge.

When stopping the ICU, use Mft_Icu_ConfigDetectMode() to disable ICU and Mft_Icu_DisableInt() to disable ICU interrupt.

Macro Definition Documentation

#define MFT0_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT0_ICU_BASE))

Definition at line 115 of file mft_icu.h.

Referenced by MftIcu_DeInitIrq(), and MftIcu_InitIrq().

#define MFT1_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT1_ICU_BASE))

Definition at line 116 of file mft_icu.h.

Referenced by MftIcu_DeInitIrq(), and MftIcu_InitIrq().

#define MFT2_ICU   (*((volatile stc_mftn_icu_t *) FM4_MFT2_ICU_BASE))

Definition at line 117 of file mft_icu.h.

Referenced by MftIcu_DeInitIrq(), and MftIcu_InitIrq().

#define MFT_ICU_CHx_MAX   3u
#define MFT_ICU_INSTANCE_COUNT
Value:

Definition at line 126 of file mft_icu.h.

Referenced by MftIcuGetInternDataPtr().

#define stc_mftn_icu_t   FM4_MFT_ICU_TypeDef

Definition at line 114 of file mft_icu.h.

Referenced by Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), MftIcu_DeInitIrq(), and MftIcu_InitIrq().

Typedef Documentation

Enumeration to define an index for each ICU instance.

Icu edge.

To select Icu edge

Frt channel.

To select FRT channel to connect to ICU

Icu mode.

To select Icu edge detection mode

Structure of Mft icu configuration.

Mft_icu instance data type.

Icu instance internal data, storing internal information for each enabled Icu instance.

Enumeration Type Documentation

Icu edge.

To select Icu edge

Enumerator
IcuFallingEdge 

select Icu falling edge

IcuRisingEdge 

select Icu rising edge

Definition at line 178 of file mft_icu.h.

Enumeration to define an index for each ICU instance.

Enumerator
IcuInstanceIndexIcu0 

Instance index of ICU0.

IcuInstanceIndexIcu1 

Instance index of ICU1.

IcuInstanceIndexIcu2 

Instance index of ICU2.

Definition at line 135 of file mft_icu.h.

Frt channel.

To select FRT channel to connect to ICU

Enumerator
Frt0ToIcu 

connect Frt channel 0 to Icu

Frt1ToIcu 

connect Frt channel 1 to Icu

Frt2ToIcu 

connect Frt channel 2 to Icu

IcuFrtToExt0 

connect extern Frt channel 0 to Icu

IcuFrtToExt1 

connect extern Frt channel 1 to Icu

Definition at line 149 of file mft_icu.h.

Icu mode.

To select Icu edge detection mode

Enumerator
IcuDisable 

disable Icu edge detection

IcuRisingDetect 

detect Icu rising edge

IcuFallingDetect 

detect Icu falling edge

IcuBothDetect 

detect Icu rising/falling edge

Definition at line 164 of file mft_icu.h.

Function Documentation

en_result_t Mft_Icu_ClrIntFlag ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Clear interrupt flag.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns
Ok
ErrorInvalidParameter

Definition at line 607 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, and Ok.

en_result_t Mft_Icu_ConfigDetectMode ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch,
en_mft_icu_mode_t  enMode 
)

Configure ICU module detection mode(different edge)

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]enModeIcu detect mode
  • IcuDisable, IcuRisingDetect, IcuFallingDetect, IcuBothDetect
Returns
Ok
ErrorInvalidParameter

mode set

Definition at line 375 of file mft_icu.c.

References ErrorInvalidParameter, IcuBothDetect, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, and Ok.

en_result_t Mft_Icu_DisableInt ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Disable Mft Icu interrupt and release callback function.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns
Ok
ErrorInvalidParameter

Definition at line 501 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, MftIcu_DeInitIrq(), MftIcuGetInternDataPtr(), Ok, stc_mft_icu_intern_data::pfnIcu0Callback, stc_mft_icu_intern_data::pfnIcu1Callback, stc_mft_icu_intern_data::pfnIcu2Callback, stc_mft_icu_intern_data::pfnIcu3Callback, and stc_mftn_icu_t.

Here is the call graph for this function:

en_result_t Mft_Icu_EnableInt ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch,
func_ptr_t  pfnCallback 
)

Enable Mft Icu interrupt.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]pfnCallbackregister callback function
  • user interrupt application function
Returns
Ok
ErrorInvalidParameter

Interrupt

Definition at line 438 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, MftIcu_InitIrq(), MftIcuGetInternDataPtr(), Ok, stc_mft_icu_intern_data::pfnIcu0Callback, stc_mft_icu_intern_data::pfnIcu1Callback, stc_mft_icu_intern_data::pfnIcu2Callback, stc_mft_icu_intern_data::pfnIcu3Callback, and stc_mftn_icu_t.

Here is the call graph for this function:

uint16_t Mft_Icu_GetCaptureData ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Readout captured data value.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns
uint16_t captured data value

Count read

Definition at line 695 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, and MFT_ICU_CHx_MAX.

en_int_flag_t Mft_Icu_GetIntFlag ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Get interrupt flag.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns
en_int_flag_t
  • interrupt flag

Definition at line 564 of file mft_icu.c.

References MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, and MFT_ICU_CH3.

en_mft_icu_edge_t Mft_Icu_GetLastEdge ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Get the latest captured edge type.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns
en_mft_icu_edge_t detected edge type

Status read/write

Definition at line 654 of file mft_icu.c.

References MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, and MFT_ICU_CH3.

void Mft_Icu_IrqHandler ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
stc_mft_icu_intern_data_t *  pstcMftIcuInternData 
)

Device Interrupt handler.

Parameters
[in]pstcMftIcuPointer to ICU instance
[in]pstcMftIcuInternDataPointer to intern data
Returns
none

IRQ handler

Definition at line 155 of file mft_icu.c.

References stc_mft_icu_intern_data::pfnIcu0Callback, stc_mft_icu_intern_data::pfnIcu1Callback, stc_mft_icu_intern_data::pfnIcu2Callback, stc_mft_icu_intern_data::pfnIcu3Callback, and TRUE.

en_result_t Mft_Icu_SelFrt ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch,
en_mft_icu_frt_t  enFrt 
)

Select FRTx channel to connect to ICUx.

Parameters
[in]pstcMftIcuPointer to Mft instance
  • structure of Mft_Icu
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]enFrtFrt channel number
  • Frt0ToIcu, Frt1ToIcu, Frt2ToIcu, IcuFrtToExt0, IcuFrtToExt1
Returns
Ok
ErrorInvalidParameter

C binding of definitions if building with C++ compiler Clock

Definition at line 298 of file mft_icu.c.

References ErrorInvalidParameter, IcuFrtToExt1, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, Ok, and TRUE.

static en_result_t MftIcu_DeInitIrq ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu)
static

Device dependent de-initialization of interrupts according CMSIS.

Parameters
[in]pstcMftIcuPointer to ICU instance
Returns
Ok Successful initialization

Definition at line 244 of file mft_icu.c.

References MFT0_ICU, MFT1_ICU, MFT2_ICU, Ok, PDL_DEFAULT_INTERRUPT_LEVEL, and stc_mftn_icu_t.

Referenced by Mft_Icu_DisableInt().

Here is the caller graph for this function:

static en_result_t MftIcu_InitIrq ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu)
static

Device dependent initialization of interrupts according CMSIS with level defined in l3.h.

Parameters
pstcMftIcuPointer to ICU instance
Returns
Ok Successful initialization

Definition at line 206 of file mft_icu.c.

References MFT0_ICU, MFT1_ICU, MFT2_ICU, Ok, PDL_IRQ_LEVEL_MFT0_ICU, PDL_IRQ_LEVEL_MFT1_ICU, PDL_IRQ_LEVEL_MFT2_ICU, and stc_mftn_icu_t.

Referenced by Mft_Icu_EnableInt().

Here is the caller graph for this function:

static stc_mft_icu_intern_data_t * MftIcuGetInternDataPtr ( volatile FM4_MFT_ICU_TypeDef *  pstcMftIcu)
static

Return the internal data for a certain MFT_ICU instance.

Parameters
pstcMftIcuPointer to MftIcu instance
Returns
Pointer to internal data or NULL if instance is not enabled (or not known)

Definition at line 131 of file mft_icu.c.

References MFT_ICU_INSTANCE_COUNT, and stc_mft_icu_instance_data::stcInternData.

Referenced by Mft_Icu_DisableInt(), and Mft_Icu_EnableInt().

Here is the caller graph for this function:

Variable Documentation

Initial value:
=
{
{
& (*((volatile FM4_MFT_ICU_TypeDef *) FM4_MFT0_ICU_BASE)) ,
NULL
},
{
& (*((volatile FM4_MFT_ICU_TypeDef *) FM4_MFT1_ICU_BASE)) ,
NULL
},
{
& (*((volatile FM4_MFT_ICU_TypeDef *) FM4_MFT2_ICU_BASE)) ,
NULL
},
}

Look-up table for all enabled MFT_ICU instances and their internal data

Definition at line 75 of file mft_icu.c.

Look-up table for all enabled MFT_ICU instances and their internal data

Definition at line 75 of file mft_icu.c.