![]() |
PDL for FM4
Version1.2
Peripheral Driverl Library for FM4
|
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)] |
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.
| #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_CH0 0u |
Definition at line 119 of file mft_icu.h.
Referenced by Mft_Icu_ClrIntFlag(), Mft_Icu_ConfigDetectMode(), Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), Mft_Icu_GetCaptureData(), Mft_Icu_GetIntFlag(), Mft_Icu_GetLastEdge(), and Mft_Icu_SelFrt().
| #define MFT_ICU_CH1 1u |
Definition at line 120 of file mft_icu.h.
Referenced by Mft_Icu_ClrIntFlag(), Mft_Icu_ConfigDetectMode(), Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), Mft_Icu_GetCaptureData(), Mft_Icu_GetIntFlag(), Mft_Icu_GetLastEdge(), and Mft_Icu_SelFrt().
| #define MFT_ICU_CH2 2u |
Definition at line 121 of file mft_icu.h.
Referenced by Mft_Icu_ClrIntFlag(), Mft_Icu_ConfigDetectMode(), Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), Mft_Icu_GetCaptureData(), Mft_Icu_GetIntFlag(), Mft_Icu_GetLastEdge(), and Mft_Icu_SelFrt().
| #define MFT_ICU_CH3 3u |
Definition at line 122 of file mft_icu.h.
Referenced by Mft_Icu_ClrIntFlag(), Mft_Icu_ConfigDetectMode(), Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), Mft_Icu_GetCaptureData(), Mft_Icu_GetIntFlag(), Mft_Icu_GetLastEdge(), and Mft_Icu_SelFrt().
| #define MFT_ICU_CHx_MAX 3u |
Definition at line 124 of file mft_icu.h.
Referenced by Mft_Icu_ClrIntFlag(), Mft_Icu_ConfigDetectMode(), Mft_Icu_DisableInt(), Mft_Icu_EnableInt(), Mft_Icu_GetCaptureData(), and Mft_Icu_SelFrt().
| #define MFT_ICU_INSTANCE_COUNT |
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 enum en_icu_instance_index en_icu_instance_index_t |
Enumeration to define an index for each ICU instance.
| typedef enum en_icu_edge en_mft_icu_edge_t |
Icu edge.
To select Icu edge
| typedef enum en_mft_icu_frt en_mft_icu_frt_t |
Frt channel.
To select FRT channel to connect to ICU
| typedef enum en_mft_icu_mode en_mft_icu_mode_t |
Icu mode.
To select Icu edge detection mode
| typedef struct stc_mft_icu_config stc_mft_icu_config_t |
Structure of Mft icu configuration.
| typedef struct stc_mft_icu_instance_data stc_mft_icu_instance_data_t |
Mft_icu instance data type.
| 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.
| enum en_icu_edge |
| enum en_mft_icu_frt |
| enum en_mft_icu_mode |
| en_result_t Mft_Icu_ClrIntFlag | ( | volatile FM4_MFT_ICU_TypeDef * | pstcMftIcu, |
| uint8_t | u8Ch | ||
| ) |
Clear interrupt flag.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
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)
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
| [in] | enMode | Icu detect mode
|
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.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
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.

| en_result_t Mft_Icu_EnableInt | ( | volatile FM4_MFT_ICU_TypeDef * | pstcMftIcu, |
| uint8_t | u8Ch, | ||
| func_ptr_t | pfnCallback | ||
| ) |
Enable Mft Icu interrupt.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
| [in] | pfnCallback | register callback function
|
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.

| uint16_t Mft_Icu_GetCaptureData | ( | volatile FM4_MFT_ICU_TypeDef * | pstcMftIcu, |
| uint8_t | u8Ch | ||
| ) |
Readout captured data value.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
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.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
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.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
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.
| [in] | pstcMftIcu | Pointer to ICU instance |
| [in] | pstcMftIcuInternData | Pointer to intern data |
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.
| [in] | pstcMftIcu | Pointer to Mft instance
|
| [in] | u8Ch | Mft Icu channel
|
| [in] | enFrt | Frt channel number
|
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 |
Device dependent de-initialization of interrupts according CMSIS.
| [in] | pstcMftIcu | Pointer to ICU instance |
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().

|
static |
Device dependent initialization of interrupts according CMSIS with level defined in l3.h.
| pstcMftIcu | Pointer to ICU instance |
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().

|
static |
Return the internal data for a certain MFT_ICU instance.
| pstcMftIcu | Pointer to MftIcu instance |
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().

| 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)] |
Look-up table for all enabled MFT_ICU instances and their internal data
| 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)] |