PDL for FM0+  Version1.0
Peripheral Driverl Library for FM0+
Input Capture Unit (ICU)

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...

Defines

#define stc_mftn_icu_t   FM0P_MFT_ICU_TypeDef
#define MFT0_ICU   (*((volatile stc_mftn_icu_t *) FM0P_MFT0_ICU_BASE))
#define MFT1_ICU   (*((volatile stc_mftn_icu_t *) FM0P_MFT1_ICU_BASE))
#define MFT2_ICU   (*((volatile stc_mftn_icu_t *) FM0P_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.
typedef enum en_mft_icu_frt en_mft_icu_frt_t
 Frt channel.
typedef enum en_mft_icu_mode en_mft_icu_mode_t
 Icu mode.
typedef enum en_icu_edge en_mft_icu_edge_t
 Icu edge.
typedef struct stc_mft_icu_config stc_mft_icu_config_t
 Structure of Mft icu configuration.
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.
typedef struct
stc_mft_icu_instance_data 
stc_mft_icu_instance_data_t
 Mft_icu instance data type.

Enumerations

enum  en_icu_instance_index { IcuInstanceIndexIcu0, IcuInstanceIndexIcu1, IcuInstanceIndexIcu2 }
 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_tMftIcuGetInternDataPtr (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu)
 Return the internal data for a certain MFT_ICU instance.
static void Mft_Icu_InitIrq (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu)
 Device dependent initialization of interrupts according CMSIS with level defined in pdl.h.
static void Mft_Icu_DeInitIrq (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu)
 Device dependent de-initialization of interrupts according CMSIS.
void Mft_Icu_IrqHandler (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, stc_mft_icu_intern_data_t *pstcMftIcuInternData)
 Device Interrupt handler.
en_result_t Mft_Icu_SelFrt (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, en_mft_icu_frt_t enFrt)
 Select FRTx channel to connect to ICUx.
en_result_t Mft_Icu_ConfigDetectMode (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, en_mft_icu_mode_t enMode)
 Configure ICU module detection mode(different edge)
en_result_t Mft_Icu_EnableInt (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch, func_ptr_t pfnCallback)
 Enable Mft Icu interrupt.
en_result_t Mft_Icu_DisableInt (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Disable Mft Icu interrupt and release callback function.
en_int_flag_t Mft_Icu_GetIntFlag (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Get interrupt flag.
en_result_t Mft_Icu_ClrIntFlag (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Clear interrupt flag.
en_mft_icu_edge_t Mft_Icu_GetLastEdge (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Get the latest captured edge type.
uint16_t Mft_Icu_GetCaptureData (volatile FM0P_MFT_ICU_TypeDef *pstcMftIcu, uint8_t u8Ch)
 Readout captured data value.

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

Provided functions of ICU module:

How to use 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 function, 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.


Define Documentation

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

Definition at line 115 of file mft_icu.h.

Referenced by Mft_Icu_DeInitIrq(), Mft_Icu_InitIrq(), and MFT_IPC_IRQHandler().

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

Definition at line 116 of file mft_icu.h.

Referenced by Mft_Icu_DeInitIrq(), Mft_Icu_InitIrq(), and MFT_IPC_IRQHandler().

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

Definition at line 117 of file mft_icu.h.

Referenced by Mft_Icu_DeInitIrq(), Mft_Icu_InitIrq(), and MFT_IPC_IRQHandler().

Value:

Definition at line 126 of file mft_icu.h.

Referenced by MftIcuGetInternDataPtr().

#define stc_mftn_icu_t   FM0P_MFT_ICU_TypeDef

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 183 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 154 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 169 of file mft_icu.h.


Function Documentation

en_result_t Mft_Icu_ClrIntFlag ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Clear interrupt flag.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Return values:
OkInterrupt flag is clear
ErrorInvalidParameterIf one of following conditions are met:
  • NULL == pstcMftIcu
  • u8Ch > MFT_ICU_CHx_MAX
  • Other invalid configuration

Definition at line 574 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 FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch,
en_mft_icu_mode_t  enMode 
)

Configure ICU module detection mode(different edge)

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]enModeIcu detect mode
  • IcuDisable, IcuRisingDetect, IcuFallingDetect, IcuBothDetect
Return values:
OkICU detection mode selected
ErrorInvalidParameterIf one of following conditions are met:
  • NULL == pstcMftIcu
  • u8Ch > MFT_ICU_CHx_MAX
  • enMode > IcuBothDetect

mode set

Definition at line 340 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.

static void Mft_Icu_DeInitIrq ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu) [static]

Device dependent de-initialization of interrupts according CMSIS.

Parameters:
[in]pstcMftIcuPointer to ICU instance

Definition at line 221 of file mft_icu.c.

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

Referenced by Mft_Icu_DisableInt().

Here is the caller graph for this function:

en_result_t Mft_Icu_DisableInt ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Disable Mft Icu interrupt and release callback function.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Return values:
OkICU interrupt are disabled
ErrorInvalidParameterIf one of following conditions are met:
  • NULL == pstcMftIcu
  • u8Ch > MFT_ICU_CHx_MAX
  • Other invalid configuration

Definition at line 467 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, Mft_Icu_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 FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch,
func_ptr_t  pfnCallback 
)

Enable Mft Icu interrupt.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]pfnCallbackregister callback function
  • user interrupt application function
Return values:
OkICU interrupt are enabled
ErrorInvalidParameterIf one of following conditions are met:
  • NULL == pstcMftIcu
  • u8Ch > MFT_ICU_CHx_MAX
  • Other invalid configuration

Interrupt

Definition at line 401 of file mft_icu.c.

References ErrorInvalidParameter, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, MFT_ICU_CHx_MAX, Mft_Icu_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 FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Readout captured data value.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns:
captured data value

Count read

Definition at line 660 of file mft_icu.c.

References MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, and MFT_ICU_CH3.

en_int_flag_t Mft_Icu_GetIntFlag ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Get interrupt flag.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Return values:
FALSEICU active edge is not detected
TRUEICU active edge is detected

Definition at line 529 of file mft_icu.c.

References MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, MFT_ICU_CH3, PdlClr, and PdlSet.

en_mft_icu_edge_t Mft_Icu_GetLastEdge ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu,
uint8_t  u8Ch 
)

Get the latest captured edge type.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
Returns:
Detected edge type

Status read/write

Definition at line 620 of file mft_icu.c.

References IcuFallingEdge, IcuRisingEdge, MFT_ICU_CH0, MFT_ICU_CH1, MFT_ICU_CH2, and MFT_ICU_CH3.

static void Mft_Icu_InitIrq ( volatile FM0P_MFT_ICU_TypeDef *  pstcMftIcu) [static]

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

Parameters:
pstcMftIcuPointer to ICU instance

Definition at line 202 of file mft_icu.c.

References MFT0_ICU, MFT1_ICU, MFT2_ICU, PDL_IRQ_LEVEL_MFT_ICU, and stc_mftn_icu_t.

Referenced by Mft_Icu_EnableInt().

Here is the caller graph for this function:

void Mft_Icu_IrqHandler ( volatile FM0P_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 154 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.

Referenced by MFT_IPC_IRQHandler().

Here is the caller graph for this function:

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

Select FRTx channel to connect to ICUx.

Parameters:
[in]pstcMftIcuPointer to ICU instance
[in]u8ChMft Icu channel
  • MFT_ICU_CH0 ~ MFT_ICU_CH3
[in]enFrtFrt channel number
  • Frt0ToIcu, Frt1ToIcu, Frt2ToIcu, IcuFrtToExt0, IcuFrtToExt1
Return values:
OkFRT channel selected
ErrorInvalidParameterIf one of following conditions are met:
  • NULL == pstcMftIcu
  • u8Ch > MFT_ICU_CHx_MAX
  • enFrt > IcuFrtToExt1

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

Definition at line 272 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 stc_mft_icu_intern_data_t * MftIcuGetInternDataPtr ( volatile FM0P_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 130 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  FM0P_MFT_ICU_TypeDef  *) FM0P_MFT0_ICU_BASE)) ,    
        {NULL,NULL,NULL,NULL}          
    },


    { 
        & (*((volatile  FM0P_MFT_ICU_TypeDef  *) FM0P_MFT1_ICU_BASE)) ,    
        {NULL,NULL,NULL,NULL}          
    },


    { 
        & (*((volatile  FM0P_MFT_ICU_TypeDef  *) FM0P_MFT2_ICU_BASE)) ,    
        {NULL,NULL,NULL,NULL}          
    },

}

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

Definition at line 74 of file mft_icu.c.

Referenced by MFT_IPC_IRQHandler().

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

Definition at line 74 of file mft_icu.c.

Referenced by MFT_IPC_IRQHandler().