/*!
* @file     Icu.c
*
* @version  1.0.0
*
* @brief    Code file of AUTOSAR Icu driver
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

/*
* MISRA-C:2012 compliance checks
*
*      Icu_c_MISRA_REF1
*          Breaks the required M3CM Rule-11.4 of MISRA 2012 guidelines,
*          A conversion should not be performed between a pointer to object and an integer type.
*
*      Icu_c_MISRA_REF2
*          Breaks the required M3CM Rule-10.3 of MISRA 2012 guidelines,
*          The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.
*
*      Icu_c_MISRA_REF3
*          Breaks the required M3CM Rule-10.5 of MISRA 2012 guidelines,
*          The value of an expression should not be cast to an inappropriate essential type.
*
*      Icu_c_MISRA_REF4
*          Breaks the required M3CM Rule-18.4 of MISRA 2012 guidelines,
*          The +, -, += and -= operators should not be applied to an expression of pointer type.
*
*      Icu_c_MISRA_REF5
*          Breaks the required M3CM Rule-2.1 of MISRA 2012 guidelines,
*          A project shall not contain unreachable code.
*/

#ifdef __cplusplus
extern "C"{
#endif

#include "Mcal.h"
#include "Icu.h"
#include "SchM_Icu.h"
#include "Icu_Irq.h"
#include "Icu_PortCi.h"
#include "Icu_Eint.h"

 #if ((STD_ON == ICU_DEV_ERROR_DETECT_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE))
     #include "Det.h"
#endif

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup ICU_Driver
  * @brief ICU driver modules
  @{
*/

/** @defgroup ICU_Macros
  @{
*/
/**************************************************************************
                  VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define ICU_VENDOR_ID                      0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_AR_RELEASE_MAJOR_VERSION       0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_AR_RELEASE_MINOR_VERSION       0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_AR_RELEASE_REVISION_VERSION    0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_SW_MAJOR_VERSION               0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_SW_MINOR_VERSION               0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_SW_PATCH_VERSION               0x00U

/**@} end of group ICU_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Icu.c and Icu.h */
#if (ICU_VENDOR_ID != ICU_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu.c and Icu.h "
#endif
/* Make sure the AUTOSAR major version number is the same between Icu.c and Icu.h */
#if (ICU_AR_RELEASE_MAJOR_VERSION != ICU_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu.c and Icu.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu.c and Icu.h */
#if (ICU_AR_RELEASE_MINOR_VERSION != ICU_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu.c and Icu.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu.c and Icu.h */
#if (ICU_AR_RELEASE_REVISION_VERSION != ICU_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu.c and Icu.h "
#endif
/* Make sure the software major version number is the same between Icu.c and Icu.h */
#if (ICU_SW_MAJOR_VERSION != ICU_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu.c and Icu.h "
#endif
/* Make sure the software minor version number is the same between Icu.c and Icu.h */
#if (ICU_SW_MINOR_VERSION != ICU_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu.c and Icu.h "
#endif
/* Make sure the software patch version number is the same between Icu.c and Icu.h */
#if (ICU_SW_PATCH_VERSION != ICU_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu.c and Icu.h "
#endif

/* Make sure the vendor id is the same between Icu.c and Icu_Irq.h */
#if (ICU_VENDOR_ID != ICU_IRQ_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the AUTOSAR major version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_AR_RELEASE_MAJOR_VERSION != ICU_IRQ_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_AR_RELEASE_MINOR_VERSION != ICU_IRQ_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_AR_RELEASE_REVISION_VERSION != ICU_IRQ_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the software major version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_SW_MAJOR_VERSION != ICU_IRQ_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the software minor version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_SW_MINOR_VERSION != ICU_IRQ_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu.c and Icu_Irq.h "
#endif
/* Make sure the software patch version number is the same between Icu.c and Icu_Irq.h */
#if (ICU_SW_PATCH_VERSION != ICU_IRQ_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu.c and Icu_Irq.h "
#endif

/* Make sure the vendor id is the same between Icu.c and Icu_PortCi.h */
#if (ICU_VENDOR_ID != ICU_PORT_CI_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the AUTOSAR major version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_AR_RELEASE_MAJOR_VERSION != ICU_PORT_CI_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_AR_RELEASE_MINOR_VERSION != ICU_PORT_CI_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_AR_RELEASE_REVISION_VERSION != ICU_PORT_CI_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the software major version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_SW_MAJOR_VERSION != ICU_PORT_CI_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the software minor version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_SW_MINOR_VERSION != ICU_PORT_CI_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif
/* Make sure the software patch version number is the same between Icu.c and Icu_PortCi.h */
#if (ICU_SW_PATCH_VERSION != ICU_PORT_CI_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu.c and Icu_PortCi.h "
#endif

#if (STD_ON == ICU_DEV_ERROR_DETECT_ENABLE)
    #ifdef ENABLE_INTERMODULE_MCAL_CHECK
        /* Make sure the AUTOSAR major version number is the same between Icu.c and Det.h */
        #if (ICU_AR_RELEASE_MAJOR_VERSION != DET_H_AR_RELEASE_MAJOR_VERSION)
            #error "AUTOSAR Major Version Number mismatch between Icu.c and Det.h "
        #endif
        /* Make sure the AUTOSAR minor version number is the same between Icu.c and Det.h */
        #if (ICU_AR_RELEASE_MINOR_VERSION != DET_H_AR_RELEASE_MINOR_VERSION)
            #error "AUTOSAR Minor Version Number mismatch between Icu.c and Det.h "
        #endif
    #endif
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Icu.c and SchM_Icu.h */
    #if (ICU_AR_RELEASE_MAJOR_VERSION != SCHM_ICU_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Icu.c and SchM_Icu.h "
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Icu.c and SchM_Icu.h */
    #if (ICU_AR_RELEASE_MINOR_VERSION != SCHM_ICU_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Icu.c and SchM_Icu.h "
    #endif

    /* Make sure the AUTOSAR major version number is the same between Icu.c and Mcal.h */
    #if (ICU_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Icu.c and Mcal.h "
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Icu.c and Mcal.h */
    #if (ICU_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Icu.c and Mcal.h "
    #endif
#endif

/**************************************************************************
                    MACRO DEFINITION
**************************************************************************/
/** @defgroup ICU_Macros
  @{
*/

#define ICU_FOUR_FUNCTION   (\
                             (uint8)ICU_MODE_SIGNAL_EDGE_DETECT | (uint8)ICU_MODE_EDGE_COUNTER | \
                             (uint8)ICU_MODE_SIGNAL_MEASUREMENT | (uint8)ICU_MODE_TIMESTAMP \
                            )

/**@} end of group ICU_Macros */

/**************************************************************************
                    GLOBAL VARIABLE
**************************************************************************/
#define ICU_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
static VAR(Pdl_DmaChHwConfigType, AUTOMATIC) s_startTimestampDmaChCfg[ICU_MAX_CFG_CH_CNT];
#endif

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

#define ICU_START_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_CALL_AND_CHANNEL))
static VAR(Icu_ModuleStateType, ICU_VAR) s_icuModuleState = ICU_MODULE_STATE_IS_UNINIT;
#endif

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

#define ICU_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
/** save signal valid level time measurement result */
static volatile VAR(Icu_ValueType, ICU_VAR) s_icuValidLevelTimeResult[ICU_MAX_CFG_CH_CNT];
/** save signal period measurement result */
static volatile VAR(Icu_ValueType, ICU_VAR) s_icuPeriodTimeResult[ICU_MAX_CFG_CH_CNT];
#endif 

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/** indicate buffer size used for save time stamp value */
static VAR(Icu_IndexType, ICU_VAR) g_icuTimestampBufferSize[ICU_MAX_CFG_CH_CNT];
/** indicate notify count value */
static volatile VAR(Icu_IndexType, ICU_VAR) g_icuNotifyCountValue[ICU_MAX_CFG_CH_CNT];
/** indicate NotifyInterval value */
static VAR(Icu_IndexType, ICU_VAR) g_icuTimestampNotifyIntervalValue[ICU_MAX_CFG_CH_CNT];
/** define buffer used for save time stamp value */
static P2VAR(Icu_ValueType, ICU_VAR, ICU_APPL_DATA) g_icuTimestampBufferPtr[ICU_MAX_CFG_CH_CNT];
/** save Icu_GetTimestampIndex() result */
static volatile VAR(Icu_IndexType, ICU_VAR) g_icuTimestampIndexResult[ICU_MAX_CFG_CH_CNT];
#endif

/** indicate icu channel all feature state */
static volatile VAR(Icu_StateByteType, ICU_VAR) g_icuChFeatureState[ICU_MAX_CFG_CH_CNT];

/** indicate icu current state NORMAL/SLEEP */
static VAR(Icu_ModeType, ICU_VAR) g_icuCurrentMode;

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

#define ICU_START_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

P2CONST(Icu_ConfigType, ICU_VAR, ICU_APPL_CONST) g_icuCfgPtr = NULL_PTR;

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/**************************************************************************
                    FUNCTION DECLARATION
**************************************************************************/
#define ICU_START_SEC_CODE
#include "Icu_MemMap.h"

/** @defgroup ICU_Fuctions
  @{
*/

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_TIMESTAMP_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampBufferPtrValue
                                            (P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_CONST) timeStampBufferPtr);

LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampBufferSizeValue
                                            (VAR(uint16, AUTOMATIC) timeStampBufferSize);

LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampNotifyInterval
                 (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint16, AUTOMATIC) timeStampNotifyInterval);
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckPrescalerWhetherDefine
                                            (VAR(Icu_ClockDivisionType, AUTOMATIC) division);
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_TIMESTAMP_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimestampPara
            (VAR(Icu_ChannelType, AUTOMATIC) ch, P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_CONST) timeStampBufferPtr,
             VAR(uint16, AUTOMATIC) timeStampBufferSize, VAR(uint16, AUTOMATIC) timeStampNotifyInterval);
#endif

#if((STD_ON == ICU_CHECK_PARAMS) && \
   ((STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE)))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckMeasureProperty
      (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint16, AUTOMATIC) propertyMaskVal, VAR(uint8, AUTOMATIC)  apiServiceId);
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckDutyCycleNullPara
                                            (P2CONST(Icu_DutyCycleType, AUTOMATIC, ICU_APPL_CONST) saveResultBufferPtr);
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_SET_MODE_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckModeWhetherDefine(VAR(Icu_ModeType, AUTOMATIC) aimMode);
#endif

#if((STD_ON == ICU_CHECK_PARAMS) && ((STD_ON == ICU_WAKEUP_FUNCTIONALITY_API_ENABLE) || \
    (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE)||(STD_ON == ICU_DISABLE_WAKEUP_API_ENABLE)))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckChannelWakeupOpen
                                            (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint8, AUTOMATIC) apiServiceId);
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimestampChannelWoring(VAR(Icu_ChannelType, AUTOMATIC) ch);
#endif

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_ClearChFeatureStateBit
                                  (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(Icu_StateByteType, AUTOMATIC) aimBit);

#if ((STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_CHECK_PARAMS))
#if ((STD_ON == ICU_EDGE_COUNT_API_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE) || \
     (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
LOCAL_INLINE FUNC(boolean, ICU_CODE) Icu_CheckChannelWhetherOverflow
                 (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint8, AUTOMATIC) apiServiceId, VAR(uint8, AUTOMATIC) errorId);
#endif
#endif

#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) && (STD_ON == ICU_SET_MODE_API_ENABLE))
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckSetModeEnviroment(VAR(Icu_ModeType, AUTOMATIC) aimMode);
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckChannelSuitableApi
                 (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint8, AUTOMATIC) modePara, VAR(uint8, AUTOMATIC) apiServiceId);
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckEdgeWhetherDefine(VAR(Icu_ActivationType, AUTOMATIC) aimEdge);
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckApiRunInSleepMode(VAR(uint8, AUTOMATIC) apiServiceId);

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_SetModuleStateBeforeExitApi
                                  (VAR(Std_ReturnType,AUTOMATIC) result, VAR(uint8, AUTOMATIC) apiServiceId);

LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckModuleState(VAR(uint8, AUTOMATIC) apiServiceId);
#endif

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_SetChFeatureStateBit
                                  (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(Icu_StateByteType, AUTOMATIC) aimBit);

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_InitTimeStampGlobalVar(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                                                  P2VAR(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr,
                                                                  VAR(uint16, AUTOMATIC) BufferSize,
                                                                  VAR(uint16, AUTOMATIC) NotifyInterval);
#endif

#if ((STD_ON == ICU_TIMESTAMP_API_ENABLE) && (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE))
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_InitTimeStampDma(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                                       P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr,
                                                       VAR(uint16, AUTOMATIC) BufferSize,
                                                       VAR(uint16, AUTOMATIC) NotifyInterval);
#endif

LOCAL_INLINE  FUNC(void, ICU_CODE) Icu_Impl_TMR_Init(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
LOCAL_INLINE  FUNC(void, ICU_CODE) Icu_Impl_PORT_CI_Init(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

#if (STD_ON == ICU_DE_INIT_API_ENABLE)
LOCAL_INLINE  FUNC(void, ICU_CODE) Icu_Impl_TMR_DeInit(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
LOCAL_INLINE  FUNC(void, ICU_CODE) Icu_Impl_PORT_CI_DeInit(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif 

#if (STD_ON == ICU_SET_MODE_API_ENABLE)
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_SetSleepMode (VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_SetNormalMode (VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_SetActivationCondition(VAR(Icu_ChannelType, AUTOMATIC) ch,
      VAR(Icu_ActivationType, AUTOMATIC) aimEdge, VAR(Icu_MeasurementModeType, AUTOMATIC) chFunction,
      CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)
LOCAL_INLINE FUNC (Icu_InputStateType, ICU_CODE) Icu_Impl_GetInputState
     (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_StartTimestamp
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr,
     VAR(boolean, AUTOMATIC) dmaCap);

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_StopTimestamp
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
LOCAL_INLINE FUNC(uint32, ICU_CODE) Icu_Impl_GetStartAddress
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif 
#endif

#if (STD_ON == ICU_EDGE_COUNT_API_ENABLE)
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_ResetEdgeCount
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_EnableEdgeCount
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_DisableEdgeCount
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

LOCAL_INLINE FUNC(Icu_EdgeNumberType, ICU_CODE) Icu_Impl_GetEdgeNumbers
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

#if (STD_ON == ICU_EDGE_DETECT_API_ENABLE)
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_EnableEdgeDetection
     (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);

LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_DisableEdgeDetection
     (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_StartSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr,
             VAR(Icu_SignalMeasurementPropertyType, AUTOMATIC) meaItem);

LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_StopSignalMeasurement
     (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

#if (STD_ON == ICU_READ_CCN_REG_API_ENABLE)
LOCAL_INLINE FUNC(Icu_ValueType, ICU_CODE) Icu_Impl_ReadTmrCCnRegValue
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetClkPrescaler
    (CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr, VAR(Icu_ClockDivisionType, AUTOMATIC) divMode);
#endif

#if ((STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_CHECK_PARAMS))
#if ((STD_ON == ICU_EDGE_COUNT_API_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE) || \
     (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
LOCAL_INLINE FUNC(boolean, ICU_CODE) Icu_Impl_GetOverflow
    (VAR(Icu_ChannelType, AUTOMATIC) ch, CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr);
#endif
#endif

/**************************************************************************
                    LOCAL FUNCTION
**************************************************************************/
#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_TIMESTAMP_API_ENABLE))
/*!
* @brief           Check if the time stamp buffer pointer is NULL_PTR
*
* @param[in]       timeStampBufferPtr    -time stamp buffer pointer
* @param[out]      None
* @param[in,out]   None
*
* @retval          E_OK:      time stamp buffer pointer is not NULL_PTR
*                  E_NOT_OK:  time stamp buffer pointer is NULL_PTR
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampBufferPtrValue
                                            (P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_CONST) timeStampBufferPtr)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)((NULL_PTR == timeStampBufferPtr) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)ICU_STARTTIMESTAMP_SERVICE_ID, (uint8)ICU_E_PARAM_POINTER);
    }
    else
    {
        /* No error report */
    }

    return result;
}

/*!
* @brief           Check if the time stamp buffer size is 0
*
* @param[in]       timeStampBufferSize    -time stamp buffer size
* @param[out]      None
* @param[in,out]   None
*
* @retval          E_OK:      time stamp buffer size is not 0
*                  E_NOT_OK:  time stamp buffer size is 0
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampBufferSizeValue
                                            (VAR(uint16, AUTOMATIC) timeStampBufferSize)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)(((uint16)0U == timeStampBufferSize) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)ICU_STARTTIMESTAMP_SERVICE_ID, (uint8)ICU_E_PARAM_BUFFER_SIZE);
    }
    else
    {
        /* No error report */
    }

    return result;
}

/*!
* @brief           Check the time stamp notify interval
*
* @param[in]       ch                         -channael id
* @param[in]       timeStampNotifyInterval    -time stamp notify interval value
* @param[out]      None
* @param[in,out]   None
*
* @retval          E_OK:         time stamp notify interval is correct
*                  E_NOT_OK:     time stamp notify interval is not correct
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimeStampNotifyInterval
                 (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint16, AUTOMATIC) timeStampNotifyInterval)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_OK;

    if((uint8)ICU_NOTIFICATION_FEATURE_BIT != ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_NOTIFICATION_FEATURE_BIT))
    {
        /* No error report */
    }
    else if(NULL_PTR == (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr)
    {
        /* No error report */
    }
    else if((uint16)0U != timeStampNotifyInterval)
    {
        /* No error report */
    }
    else
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)ICU_STARTTIMESTAMP_SERVICE_ID, (uint8)ICU_E_PARAM_NOTIFY_INTERVAL);
        result = (Std_ReturnType)E_NOT_OK;
    }

    return result;
}
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE))
/*!
* @brief           This function is used to check whether clock prescaler is defined.
*
* @param[in]       division      - clock prescaler value
* @param[out]      None
* @param[in,out]   None
*
* @retval          E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckPrescalerWhetherDefine
                                            (VAR(Icu_ClockDivisionType, AUTOMATIC) division)
{
    VAR(Std_ReturnType, AUTOMATIC) result;

    switch (division)
    {
        case ICU_CLK_DIV_DEFAULT:
        case ICU_CLK_DIV_ALTERNATE:
            result = (Std_ReturnType)E_OK;
            break;

        default:
            (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                               (uint8)ICU_SETCLOCKMODE_SERVICE_ID, (uint8)ICU_E_CLK_MODE_BEYOND);
            result = (Std_ReturnType)E_NOT_OK;
            break;
    }

    return result;
}
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_TIMESTAMP_API_ENABLE))
/*!
* @brief         This function is used to check Icu_StartTimestamp() parameter.
*
* @param[in]     ch                         -channel id
* @param[in]     timeStampBufferPtr         -point to time stamp buffer
* @param[in]     timeStampBufferSize        -time stamp buffer size
* @param[in]     timeStampNotifyInterval    -time stamp notify interval
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimestampPara
            (VAR(Icu_ChannelType, AUTOMATIC) ch, P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_CONST) timeStampBufferPtr,
             VAR(uint16, AUTOMATIC) timeStampBufferSize, VAR(uint16, AUTOMATIC) timeStampNotifyInterval)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    if((Std_ReturnType)E_NOT_OK == Icu_CheckTimeStampBufferPtrValue(timeStampBufferPtr))
    {
        result = (Std_ReturnType)E_NOT_OK;
    }
    else if((Std_ReturnType)E_NOT_OK == Icu_CheckTimeStampBufferSizeValue(timeStampBufferSize))
    {
        result = (Std_ReturnType)E_NOT_OK;
    }
    else if((Std_ReturnType)E_NOT_OK == Icu_CheckTimeStampNotifyInterval(ch, timeStampNotifyInterval))
    {
        result = (Std_ReturnType)E_NOT_OK;
    }
    else
    {
        result= (Std_ReturnType)E_OK;
    }

    return result;
}
#endif

#if((STD_ON == ICU_CHECK_PARAMS) && \
   ((STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE)))
/*!
* @brief         This function is used to check whether measure property is suitable for channel configuration.
*
* @param[in]     ch                   -channel id
* @param[in]     propertyMaskVal      -property mask value
* @param[in]     apiServiceId         -API channel id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
/*** @warning Icu_c_MISRA_REF5 Static function 'Icu_CheckMeasureProperty' is not used within this translation unit. */
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckMeasureProperty
      (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint16, AUTOMATIC) propertyMaskVal, VAR(uint8, AUTOMATIC)  apiServiceId)
{
    VAR (Icu_ModeCfgItemType, AUTOMATIC) channelPropertyPara = (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChModeCfgItem;

    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)
                                  ((channelPropertyPara != (propertyMaskVal & channelPropertyPara)) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U, 
                              (uint8)apiServiceId, (uint8)ICU_E_PARAM_CHANNEL);
    }
    else
    {
        /* No error report */
    }

    return result;
}
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
/*!
* @brief         This function is used to check whether DutyCycleValues parameter is NULL_PTR.
*
* @param[in]     saveResultBufferPtr      -pointer to buffer which save measurement result
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
/*** @warning Icu_c_MISRA_REF5 Static function 'Icu_CheckDutyCycleNullPara' is not used within this translation unit. */
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckDutyCycleNullPara(P2CONST(Icu_DutyCycleType, AUTOMATIC, ICU_APPL_CONST) 
    saveResultBufferPtr)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)((NULL_PTR == saveResultBufferPtr) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)ICU_GETDUTYCYCLEVALUES_SERVICE_ID, (uint8)ICU_E_PARAM_POINTER);
    }
    else
    {
        /* No error report */
    }

    return result;
}
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_ON == ICU_SET_MODE_API_ENABLE))
/*!
* @brief         This function is used to check whether icu mode is defined.
*
* @param[in]     aimMode             -aim mode
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckModeWhetherDefine(VAR(Icu_ModeType, AUTOMATIC) aimMode)
{
    VAR(Std_ReturnType, AUTOMATIC) result;

    switch (aimMode)
    {
        case ICU_MODE_NORMAL:
        case ICU_MODE_SLEEP:
            result = (Std_ReturnType)E_OK;
            break;

        default:
            (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                  (uint8)ICU_SETMODE_SERVICE_ID, (uint8)ICU_E_PARAM_MODE);
            result = (Std_ReturnType)E_NOT_OK;
            break;
    }

    return result;
}
#endif

#if((STD_ON == ICU_CHECK_PARAMS) && ((STD_ON == ICU_WAKEUP_FUNCTIONALITY_API_ENABLE) || \
    (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE)|| (STD_ON == ICU_DISABLE_WAKEUP_API_ENABLE)))
/*!
* @brief         This function is used to check whether icu wakeup function open.
*
* @param[in]     ch             -channel id
* @param[in]     apiServiceId   -API service id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckChannelWakeupOpen(VAR(Icu_ChannelType, AUTOMATIC) ch,
    VAR(uint8, AUTOMATIC) apiServiceId)
{
    VAR(Icu_EdgeAndWakeupFlagType, AUTOMATIC) channelWakeupPara =
                                             (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuCHActiveEdgeAndWakeup;

    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)(((Icu_EdgeAndWakeupFlagType)ICU_CH_WAKEUP_MASK_VAL !=
                                         (channelWakeupPara & (Icu_EdgeAndWakeupFlagType)ICU_CH_WAKEUP_MASK_VAL))
                                          ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)apiServiceId, (uint8)ICU_E_PARAM_CHANNEL);
    }
    else
    {
        /* No error report */
    }

    return result;
}
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/*!
* @brief         This function is used to check Icu_StartTimestamp() channel whether is working.
*
* @param[in]     ch             -channel id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckTimestampChannelWoring(VAR(Icu_ChannelType, AUTOMATIC) ch)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)(((uint8)ICU_RUNNING_FEATURE_BIT !=
                            ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_RUNNING_FEATURE_BIT)) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportRuntimeError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                     (uint8)ICU_STOPTIMESTAMP_SERVICE_ID, (uint8)ICU_E_NOT_STARTED);
    }
    else
    {
        /* No error report */
    }

    return result;
}
#endif

/*!
* @brief         This function is used to clear g_icuChFeatureState bit according to parameter.
*
* @param[in]     ch       -channel id
* @param[in]     aimBit   -aim bit
* @param[out]    None
* @param[in,out] None
*
* @retval        None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_ClearChFeatureStateBit(VAR(Icu_ChannelType, AUTOMATIC) ch,
    VAR(Icu_StateByteType, AUTOMATIC) aimBit)
{
    SchM_Enter_Icu_ICU_CRITICAL_SECTION1();
    g_icuChFeatureState[ch] &= ((Icu_StateByteType)(~aimBit));
    SchM_Exit_Icu_ICU_CRITICAL_SECTION1();
}

#if ((STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_CHECK_PARAMS))
#if ((STD_ON == ICU_EDGE_COUNT_API_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE) || \
     (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
/*!
* @brief         This function is used to check whether channel over flow.
*
* @param[in]     ch             -channel id
* @param[in]     apiServiceId   -API service id
* @param[in]     errorId        -error id
* @param[out]    None
* @param[in,out] None
*
* @retval        TRUE / FALSE
*/
LOCAL_INLINE FUNC(boolean, ICU_CODE) Icu_CheckChannelWhetherOverflow(VAR(Icu_ChannelType, AUTOMATIC) ch,
    VAR(uint8, AUTOMATIC) apiServiceId, VAR(uint8, AUTOMATIC) errorId)
{
    VAR(boolean, AUTOMATIC) result;
    VAR(boolean, AUTOMATIC) ChOvfBitState;

    ChOvfBitState = (boolean)(((uint8)ICU_OVERFLOW_FEATURE_BIT ==
    ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_OVERFLOW_FEATURE_BIT)) ? TRUE : FALSE );

    result = (boolean)((((boolean)TRUE == Icu_Impl_GetOverflow(ch, &g_icuCfgPtr->moduleAchieveWayCfg)) ||
                        ((boolean)TRUE == ChOvfBitState)) ?  TRUE : FALSE );

    if ((boolean)TRUE == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U, apiServiceId, errorId);
    }
    else
    {
        /* No error report */
    }

    return result;
}
#endif
#endif

#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) && (STD_ON == ICU_SET_MODE_API_ENABLE))
/*!
* @brief         This function is used to check that the condition for calling Icu_SetMode().
*
* @param[in]     aimMode             -aim mode
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckSetModeEnviroment(VAR(Icu_ModeType, AUTOMATIC) aimMode)
{
    VAR(boolean, AUTOMATIC) chIsRun = TRUE;
    VAR(Std_ReturnType,  AUTOMATIC) result;
    VAR(Icu_ChannelType, AUTOMATIC) ch = 0;

    if (aimMode == g_icuCurrentMode)
    {
        /* The current mode is the same as the target mode, no opration */
        result = (Std_ReturnType)E_OK;
    }
    else
    {
        /* Check if there are channels running */
        while (ch < g_icuCfgPtr->totalNumberChannel)
        {
                  chIsRun = (boolean)((((uint8)ICU_RUNNING_FEATURE_BIT ==
     ((uint8)g_icuChFeatureState[ch] & ((uint8)ICU_RUNNING_FEATURE_BIT | (uint8)ICU_WAKEUP_FEATURE_BIT)))) ? TRUE : FALSE );

            if((boolean)TRUE == chIsRun)
            {
                (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                      (uint8)ICU_SETMODE_SERVICE_ID, (uint8)ICU_E_BUSY_OPERATION);
                break;
            }
            else
            {
                /* Check next channel */
            }

            ch++;
        }

        if((boolean)TRUE == chIsRun)
        {
            result = (Std_ReturnType)E_NOT_OK;
        }
        else
        {
            result = (Std_ReturnType)E_OK;
        }
    }

    return result;
}
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
/*!
* @brief         This function is used to check whether channel suitable for API.
*
* @param[in]     ch             -channel id
* @param[in]     modePara       -mode mask value
* @param[in]     apiServiceId   -API service id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckChannelSuitableApi
                 (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(uint8, AUTOMATIC) modePara, VAR(uint8, AUTOMATIC) apiServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    if (ICU_MODULE_STATE_IS_UNINIT == s_icuModuleState)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)apiServiceId, (uint8)ICU_E_UNINIT);
    }
    else
    {
        VAR(Icu_MeasurementModeType, AUTOMATIC) suitableMode = (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChModeSelect;

        if ((ch > g_icuCfgPtr->totalNumberChannel) ||
            ((uint8)suitableMode != (modePara & (uint8)suitableMode)))
        {
            (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                  (uint8)apiServiceId, (uint8)ICU_E_PARAM_CHANNEL);
        }
        else
        {
            result = (Std_ReturnType)E_OK;
        }
    }

    return result;
}
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
/*!
* @brief         This function is used to check whether aim edge is defined.
*
* @param[in]     aimEdge             -aim edge
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckEdgeWhetherDefine(VAR(Icu_ActivationType, AUTOMATIC) aimEdge)
{
   VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_OK;

    switch (aimEdge)
    {
        case ICU_RISING_EDGE:
        case ICU_FALLING_EDGE:
        case ICU_BOTH_EDGES:
            result = (Std_ReturnType)E_OK;
            break;

        default:
            (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                  (uint8)ICU_SETACTIVATIONCONDITION_SERVICE_ID, (uint8)ICU_E_PARAM_ACTIVATION);
            result = (Std_ReturnType)E_NOT_OK;
            break;
    }

   return result;
}
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
/*!
* @brief         This function is used to check whether API runs in sleep mode.
*
* @param[in]     apiServiceId      -API Service Id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckApiRunInSleepMode(VAR(uint8, AUTOMATIC) apiServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)((ICU_MODE_SLEEP == g_icuCurrentMode) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)apiServiceId, (uint8)ICU_E_API_RUN_SLEEP_MODE);
    }
    else
    {
        /* No error report */
    }

    return result;
}

/*!
* @brief         This function is used to set icu module state before exit API.
*
* @param[in]     result             -API run result
* @param[in]     apiServiceId       -API service id
* @param[out]    None
* @param[in,out] None
*
* @retval        None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_SetModuleStateBeforeExitApi
                                  (VAR(Std_ReturnType,AUTOMATIC) result, VAR(uint8, AUTOMATIC) apiServiceId)
{
    if ((Std_ReturnType)E_OK == result)
    {
        s_icuModuleState = ((uint8)ICU_DEINIT_SERVICE_ID == apiServiceId) ?
                            ICU_MODULE_STATE_IS_UNINIT : ICU_MODULE_STATE_IS_IDLE ;
    }
    else
    {
        /* Nothing to do */
    }
}

/*!
* @brief         This function is used to check icu module environment.
*
* @param[in]     apiServiceId       -API service id
* @param[out]    None
* @param[in,out] None
*
* @retval        E_OK / E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, ICU_CODE) Icu_CheckModuleState(VAR(uint8, AUTOMATIC) apiServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_OK;

    switch (s_icuModuleState)
    {
        case ICU_MODULE_STATE_IS_UNINIT:
            result = (Std_ReturnType)(((uint8)ICU_INIT_SERVICE_ID != apiServiceId) ? E_NOT_OK : E_OK );
            if ((Std_ReturnType)E_NOT_OK == result)
            {
                (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                      (uint8)apiServiceId, (uint8)ICU_E_UNINIT);
            }
            else
            {
                /* No error report */
            }
            break;

        default:
            result = (Std_ReturnType)(((uint8)ICU_INIT_SERVICE_ID == apiServiceId) ? E_NOT_OK : E_OK );
            if ((Std_ReturnType)E_NOT_OK == result)
            {
                (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                      (uint8)apiServiceId, (uint8)ICU_E_ALREADY_INITIALIZED);
            }
            else
            {
                /* No error report */
            }
            break;
    }

    return result;
}
#endif

/*!
* @brief         This function is used to set g_icuChFeatureState bit according to parameter.
*
* @param[in]     ch       -channel id
* @param[in]     aimBit   -aim bit
* @param[out]    None
* @param[in,out] None
*
* @retval        None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_SetChFeatureStateBit
                                  (VAR(Icu_ChannelType, AUTOMATIC) ch, VAR(Icu_StateByteType, AUTOMATIC) aimBit)
{
    SchM_Enter_Icu_ICU_CRITICAL_SECTION0();
    g_icuChFeatureState[ch] |= aimBit;
    SchM_Exit_Icu_ICU_CRITICAL_SECTION0();
}

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/*!
* @brief         Initialize global variant about time stamp according parameter.
*
* @param[in]     Channel           -channel id
* @param[in]     BufferPtr         -time stamp buffer pointer
* @param[in]     BufferSize        -time stamp buffer size
* @param[in]     NotifyInterval    -time stamp notification interval
* @param[out]    None
* @param[in,out] None
*
* @retval        None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_InitTimeStampGlobalVar(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                                                  P2VAR(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr,
                                                                  VAR(uint16, AUTOMATIC) BufferSize,
                                                                  VAR(uint16, AUTOMATIC) NotifyInterval)
{
    SchM_Enter_Icu_ICU_CRITICAL_SECTION2();

    /* operate g_icuChFeatureState's feature bit */
    Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);

    g_icuTimestampBufferPtr[Channel] = BufferPtr;
    g_icuTimestampBufferSize[Channel] = BufferSize;
    g_icuTimestampNotifyIntervalValue[Channel] = NotifyInterval;
    g_icuNotifyCountValue[Channel] = 0U;
    g_icuTimestampIndexResult[Channel] = 0U;

    SchM_Exit_Icu_ICU_CRITICAL_SECTION2();
}
#endif

#if ((STD_ON == ICU_TIMESTAMP_API_ENABLE) && (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE))
/*!
* @brief         Initialize global variant about time stamp dma.
*
* @param[in]     Channel           -channel id
* @param[in]     BufferPtr         -time stamp buffer pointer
* @param[in]     BufferSize        -time stamp buffer size
* @param[in]     NotifyInterval    -time stamp notification interval
* @param[out]    None
* @param[in,out] None
*
* @retval        None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_InitTimeStampDma(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                                       P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr,
                                                       VAR(uint16, AUTOMATIC) BufferSize,
                                                       VAR(uint16, AUTOMATIC) NotifyInterval)
{
    s_startTimestampDmaChCfg[Channel].periphAddr =
                             Icu_Impl_GetStartAddress(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
    /*** @warning Icu_c_MISRA_REF1 [I] Cast between a pointer to object and an integral type. */
    s_startTimestampDmaChCfg[Channel].memAddr = (uint32)BufferPtr;
    s_startTimestampDmaChCfg[Channel].dir = DMA_DIR_PERIPHERAL;
    s_startTimestampDmaChCfg[Channel].periphInc = DMA_PERIPHERAL_INC_DISABLE;
    s_startTimestampDmaChCfg[Channel].memInc = DMA_MEMORY_INC_ENABLE;
    s_startTimestampDmaChCfg[Channel].periphDataWidth = DMA_PERIPHERAL_DATASIZE_WORD;
    s_startTimestampDmaChCfg[Channel].memDataWidth = DMA_MEMORY_DATASIZE_WORD;
    s_startTimestampDmaChCfg[Channel].circularMode = DMA_CIRCULAR_DISABLE;
    s_startTimestampDmaChCfg[Channel].priority = DMA_PRIORITY_LEVEL_VERYHIGH;
    s_startTimestampDmaChCfg[Channel].mem2Mem = DMA_M2M_DISABLE;

    if ((NotifyInterval >= BufferSize) || (NotifyInterval == (uint16)0))
    {
        s_startTimestampDmaChCfg[Channel].bufSize = BufferSize;
    }
    else
    {
        s_startTimestampDmaChCfg[Channel].bufSize = NotifyInterval;
    }
}

/*!
* @brief         Set the Dma channel function of the Icu TMR Low-level driver.
*
* @param[in]     ch                 -channel id
* @param[in]     dmaChConfig        -dma channel configuration
* @param[out]    None
* @param[in,out] None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetDmaCh(VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr, VAR(uint8, AUTOMATIC) dmaChEn)
{
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    /* TMR implement */
    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;

    Icu_Tmr_SetDmaCh((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel), &s_startTimestampDmaChCfg[ch], dmaChEn);
}

#endif

/*!
* @brief          Initialization Icu configuration by TMR
* 
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_TMR_Init(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    if (NULL_PTR != ipCfgPtr->channelTmrIpConfigPtr)
    {
        Icu_Tmr_Init(ipCfgPtr->channelTmrIpConfigPtr);
    }
    else
    {
        /* nothing to do */
    }
}

/*!
* @brief          Initialization Icu configuration by PORT
*
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_PORT_CI_Init(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    if (NULL_PTR != ipCfgPtr->channelPORT_CIIpConfigPtr)
    {
        Icu_PortCi_Init(ipCfgPtr->channelPORT_CIIpConfigPtr);
    }
    else
    {
        /* nothing to do */
    }
}

#if (STD_ON == ICU_DE_INIT_API_ENABLE)

/*!
* @brief          De-Initialization Icu configuration by TMR
*
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_TMR_DeInit(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    if (NULL_PTR != ipCfgPtr->channelTmrIpConfigPtr)
    {
        Icu_Tmr_Deinit(ipCfgPtr->channelTmrIpConfigPtr);
    }
    else
    {
        /* nothing to do */
    }
}

/*!
* @brief          De-Initialization Icu configuration by PORT
*
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_PORT_CI_DeInit(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    if (NULL_PTR != ipCfgPtr->channelPORT_CIIpConfigPtr)
    {
        Icu_PortCi_DeInit(ipCfgPtr->channelPORT_CIIpConfigPtr);
    }
    else
    {
        /* nothing to do */
    }
}

#endif

#if (STD_ON == ICU_SET_MODE_API_ENABLE)

/*!
* @brief          SetSleepMode code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetSleepMode(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST)  portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType, AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_SetSleepMode((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        case ICU_PORT_CI_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;
            Icu_PortCi_SetSleepMode((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel), 
                portciCHCfgPtr->icuPortPinMode);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          SetNormalMode code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetNormalMode(VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC)  implChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST)  portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType, AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_SetNormalMode((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        case ICU_PORT_CI_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;
            Icu_PortCi_SetNormalMode((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel), portciCHCfgPtr->icuPortPinMode);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

#endif

/*!
* @brief          SetActivationCondition code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      aimEdge     - aim edge
* @param[in]      chFunction  - channel function
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetActivationCondition(VAR(Icu_ChannelType, AUTOMATIC) ch,
      VAR(Icu_ActivationType, AUTOMATIC) aimEdge, VAR(Icu_MeasurementModeType, AUTOMATIC) chFunction,
      CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(Icu_TmrActiveEdgeType, AUTOMATIC)implEdge;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST) portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType,AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    (void) chFunction;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;

            switch (aimEdge)
            {
                case ICU_FALLING_EDGE:
                    implEdge = ICU_TMR_ACTIVE_EDGE_IS_FALLING;
                    break;

                case ICU_RISING_EDGE:
                    implEdge = ICU_TMR_ACTIVE_EDGE_IS_RISING;
                    break;

                default:
                    implEdge = ICU_TMR_ACTIVE_EDGE_IS_BOTH;
                    break;
            }

            Icu_Tmr_SetActivationCondition((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel),
                (Icu_TmrActiveEdgeType)implEdge);
            break;

        case ICU_PORT_CI_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;

            switch (aimEdge)
            {
                case ICU_FALLING_EDGE:
                    implEdge = ICU_PORT_CI_ACTIVE_EDGE_IS_FALLING;
                    break;

                case ICU_RISING_EDGE:
                    implEdge = ICU_PORT_CI_ACTIVE_EDGE_IS_RISING;
                    break;

                default:
                    implEdge = ICU_PORT_CI_ACTIVE_EDGE_IS_BOTH;
                    break;
            }

            Icu_PortCi_SetActivationCondition
            ((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel),(Icu_Port_CiActiveEdgeType)implEdge, portciCHCfgPtr->icuPortPinMode);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)

/*!
* @brief          GetInputState code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*
* @retval         ICU_IDLE / ICU_ACTIVE
*/
LOCAL_INLINE FUNC(Icu_InputStateType, ICU_CODE) Icu_Impl_GetInputState(VAR(Icu_ChannelType, AUTOMATIC) ch,
 CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_InputStateType, AUTOMATIC) implReturn = ICU_IDLE;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST) portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType,AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;

            if (Icu_Tmr_GetInputState((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel)) != 0U)
            {
                implReturn = ICU_ACTIVE;
            }
            else
            {
                /* nothing to do */
            }
            break;

        case ICU_PORT_CI_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;

            if (Icu_PortCi_GetInputState((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel)) != 0U)
            {
                implReturn = ICU_ACTIVE;
            }
            else
            {
                /* nothing to do */
            }
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }

    return implReturn;
}

#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)

/*!
* @brief          StartTimestamp code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[in]      dmaCap      - dma support
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_StartTimestamp(VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr, VAR(boolean, AUTOMATIC) dmaCap)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_StartTimestamp((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel), (boolean)dmaCap);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          StopTimestamp code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_StopTimestamp(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_StopTimestamp((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)

/*!
* @brief          Get Start Address code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*
* @retval         uint32
*/
LOCAL_INLINE FUNC(uint32, ICU_CODE) Icu_Impl_GetStartAddress(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(uint32, AUTOMATIC) resultAddr;

    /* TMR implement */
    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;

    resultAddr = Icu_Tmr_GetStartAddress((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
    return resultAddr;
}
#endif
#endif

#if (STD_ON == ICU_EDGE_COUNT_API_ENABLE)

/*!
* @brief          ResetEdgeCount code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_ResetEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_ResetEdgeCount((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          EnableEdgeCount code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_EnableEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_EnableEdgeCount((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          DisableEdgeCount code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_DisableEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_DisableEdgeCount((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          GetEdgeNumbers code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*
* @retval         Icu_EdgeNumberType
*/
LOCAL_INLINE FUNC(Icu_EdgeNumberType, ICU_CODE) Icu_Impl_GetEdgeNumbers(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC)  workChannel;
    VAR(Icu_EdgeNumberType, AUTOMATIC)  edgeCountResult = 0U;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            edgeCountResult = Icu_Tmr_GetEdgeNumbers((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }

    return edgeCountResult;
}

#endif

#if (STD_ON == ICU_EDGE_DETECT_API_ENABLE)
/*!
* @brief          EnableEdgeDetection code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_EnableEdgeDetection(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST) tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST)  portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType, AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_EnableEdgeDetection((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        case ICU_PORT_CI_CH_TYPE:
            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;
            Icu_PortCi_EnableEdgeDetection((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel), portciCHCfgPtr->icuPortPinMode);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

/*!
* @brief          DisableEdgeDetection code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_DisableEdgeDetection(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST)  portciIPCfgPtr;
    P2CONST(Icu_Port_CiCHCfgType, AUTOMATIC, ICU_APPL_CONST)  portciCHCfgPtr;

    switch ((*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelCountIPSelect)
    {
        case ICU_TMR_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
            tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
            Icu_Tmr_DisableEdgeDetection((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
            break;

        case ICU_PORT_CI_CH_TYPE:

            workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
            portciIPCfgPtr = ipCfgPtr->channelPORT_CIIpConfigPtr;
            portciCHCfgPtr = &(*portciIPCfgPtr->icuChannelCfgPtr)[workChannel];
            implChannel = (Icu_ChannelType)portciCHCfgPtr->icuChannelId;
            Icu_PortCi_DisableEdgeDetection((Icu_Port_CiCHType)ICU_PORT_CI_CH_ID_BASE_PORT_CI(implChannel), portciCHCfgPtr->icuPortPinMode);
            break;

        default:
            {
                /* Intentionally Empty */
            }
            break;
    }
}

#endif

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)

/*!
* @brief          StartSignalMeasurement code of Icu implement layer
* 
* @param[in]      ch            - channel id
* @param[in]      ipCfgPtr      - pointer to icu configuration structure
* @param[in]      activeEdge    - active edge
* @param[in]      meaItem       - measurement item
* @param[in]      dmaCap        - dma support
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_StartSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr,
             VAR(Icu_SignalMeasurementPropertyType, AUTOMATIC) meaItem)
{
    /* Only TMR support signal measurement function */
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;

    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;

    Icu_Tmr_StartSignalMeasurement((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel),
                                   (Icu_TmrMeasurePropertyType)meaItem);
}

/*!
* @brief          StopSignalMeasurement code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Impl_StopSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    /* Only TMR support signal measurement function */
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8,  AUTOMATIC) workChannel;

    /* TMR implement */
    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
    Icu_Tmr_StopSignalMeasurement((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));
}

#endif

#if (STD_ON == ICU_READ_CCN_REG_API_ENABLE)

/*!
* @brief          ReadCHVRegValue code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*
* @retval         Icu_ValueType
*/
LOCAL_INLINE FUNC(Icu_ValueType, ICU_CODE) Icu_Impl_ReadTmrCCnRegValue(VAR(Icu_ChannelType, AUTOMATIC) ch,
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    /* Only TMR support read capture register function */
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC) workChannel;
    VAR(Icu_ValueType, AUTOMATIC) chvRegValue;

    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
    /*** @warning Icu_c_MISRA_REF2 An expression of 'essentially unsigned' type (unsigned char) is being converted to enum type, 'Icu_TmrHwChType' on assignment. */
    chvRegValue = (Icu_ValueType)Icu_Tmr_ReadTmrCCnRegValue(TMR_CH_ID(ICU_TMR_CH_ID_BASE_TMR(implChannel)),
    /*** @warning Icu_c_MISRA_REF2 An expression of 'essentially unsigned' type (unsigned char) is being converted to enum type, 'Icu_TmrModuleType' on assignment. */
                                                            TMR_MOD_ID(ICU_TMR_CH_ID_BASE_TMR(implChannel)));

    return chvRegValue;
}

#endif

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)

/*!
* @brief          SetClkPrescaler code of Icu implement layer
* 
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[in]      divMode     - clock prescaler mode
* @param[out]     None
* @param[in,out]  None
*/
LOCAL_INLINE FUNC(void, ICU_CODE) Icu_Impl_SetClkPrescaler(CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr,
    VAR(Icu_ClockDivisionType, AUTOMATIC) divMode)
{
    VAR(uint8, AUTOMATIC) moduleCount = 0U;
    VAR(Icu_TmrPscType, AUTOMATIC) gloCfgDiv;

    if (NULL_PTR == ipCfgPtr->channelTmrIpConfigPtr)
    {
        /* nothing to do */
    }
    else
    {
        /* configurate TMR clock according to global setting(for configured Tmrs) */
        while(moduleCount < ICU_TMR_IP_CFG_CNT)
        {
            /* Get ICU module global clock prescaler */
            gloCfgDiv = (Icu_TmrPscType)((ICU_CLK_DIV_DEFAULT == divMode) ?
                             ((*(ipCfgPtr->channelTmrIpConfigPtr->icuTmrGlobalCfgPtr))[moduleCount].icuTmrClkPrescale):
                             ((*(ipCfgPtr->channelTmrIpConfigPtr->icuTmrGlobalCfgPtr))[moduleCount].icuTmrAltClkPrescale));

            Icu_Tmr_SetClkPrescaler((*(ipCfgPtr->channelTmrIpConfigPtr->icuTmrGlobalCfgPtr))[moduleCount].icuTmrModule, gloCfgDiv);
            moduleCount++;
        }
    }
}

#endif

#if ((STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_CHECK_PARAMS))
#if ((STD_ON == ICU_EDGE_COUNT_API_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE) || \
     (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
/*!
* @brief          GetOverflow code of Icu implement layer
* 
* @param[in]      ch          - channel id
* @param[in]      ipCfgPtr    - pointer to icu configuration structure
* @param[out]     None
* @param[in,out]  None
*
* @retval         TRUE / FALSE
*/
LOCAL_INLINE FUNC(boolean, ICU_CODE) Icu_Impl_GetOverflow(VAR(Icu_ChannelType, AUTOMATIC) ch, 
    CONSTP2CONST(Icu_IpCfgType, AUTOMATIC, ICU_APPL_CONST) ipCfgPtr)
{
    P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrIPCfgPtr;
    P2CONST(Icu_TmrChCfgType, AUTOMATIC, ICU_APPL_CONST)  tmrCHCfgPtr;

    VAR(Icu_ChannelType, AUTOMATIC) implChannel;
    VAR(uint8, AUTOMATIC)  workChannel;
    VAR(boolean, AUTOMATIC) ovfResult;

    /* TMR implement */
    workChannel = (*ipCfgPtr->channelWorkingIpAndIdPtr)[ch].channelWorkingId;
    tmrIPCfgPtr = ipCfgPtr->channelTmrIpConfigPtr;
    tmrCHCfgPtr = &(*tmrIPCfgPtr->icuChannelCfgPtr)[workChannel];
    implChannel = (Icu_ChannelType)tmrCHCfgPtr->icuChannelId;
    ovfResult = (boolean)Icu_Tmr_GetOverflow((Icu_TmrChType)ICU_TMR_CH_ID_BASE_TMR(implChannel));

    return ovfResult;
}
#endif
#endif


/**************************************************************************
                    GLOBAL FUNCTION
**************************************************************************/
/*!
* @brief         Initializes the Icu driver with pre-configurations.
*
* @param[in]     ConfigPtr      -pointer to the pre-configuration
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_Init(P2CONST(Icu_ConfigType, AUTOMATIC, ICU_APPL_CONST) ConfigPtr)
{
#if (STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_PARAMS)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

    VAR(Icu_ChannelType, AUTOMATIC) channelCount = 0U;

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckModuleState((uint8)ICU_INIT_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)

        if (NULL_PTR == ConfigPtr)
        {
            (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                                  (uint8)ICU_INIT_SERVICE_ID, (uint8)ICU_E_INIT_FAILED);
            result = (Std_ReturnType)E_NOT_OK;
        }
        else
        {
            /* No error report */
            result = (Std_ReturnType)E_OK;
        }

        if ((Std_ReturnType)E_OK == result)
        {
#endif
            g_icuCfgPtr = ConfigPtr;
            /* Set register about Icu configuration */
            /* TMR implement */
            Icu_Impl_TMR_Init(&(g_icuCfgPtr->moduleAchieveWayCfg));
            /* Port_Ci implement */
            Icu_Impl_PORT_CI_Init(&(g_icuCfgPtr->moduleAchieveWayCfg));

            while(channelCount < g_icuCfgPtr->totalNumberChannel)
            {
                /* Clear all channel feature state flag */
                g_icuChFeatureState[channelCount] =  0x00U;

                #if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
                    switch ((&((*(g_icuCfgPtr->icuChCfgPtr))[channelCount]))->icuChModeSelect)
                    {
                        case ICU_MODE_TIMESTAMP:
                            /* initialize buffer for timestamp buffer */
                            g_icuTimestampBufferPtr[channelCount] = NULL_PTR;
                            break;

                        default:
                           {
                               /* Nothing to do */
                           }
                            break;
                    }
                #endif

                channelCount++;
            }

            g_icuCurrentMode = ICU_MODE_NORMAL;
#if (STD_ON == ICU_CHECK_PARAMS)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_INIT_SERVICE_ID);
#endif
}

#if (STD_ON == ICU_DE_INIT_API_ENABLE)
/*!
* @brief         De-initializes the Icu driver.
*
* @param[in]     None
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_DeInit(void)
{
    VAR(Icu_ChannelType, AUTOMATIC) channelCount = 0U;

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Icu_CheckModuleState((uint8)ICU_DEINIT_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        /* Reset register about Icu */
        /* TMR implement */
        Icu_Impl_TMR_DeInit(&g_icuCfgPtr->moduleAchieveWayCfg);
        /* Port_Ci implement */
        Icu_Impl_PORT_CI_DeInit(&g_icuCfgPtr->moduleAchieveWayCfg);

        while(channelCount < g_icuCfgPtr->totalNumberChannel)
        {
            /* Clear all channel feature state flag */
            g_icuChFeatureState[channelCount] =  0x00U;

            channelCount++;
        }

        /* Set the pre-configuration pointer to NULL_PTR*/
        g_icuCurrentMode = ICU_MODE_NORMAL;
        g_icuCfgPtr = NULL_PTR;
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_DEINIT_SERVICE_ID);
#endif
}
#endif

#if (STD_ON == ICU_SET_MODE_API_ENABLE)
/*!
* @brief         Set Icu mode NORMAL/SLEEP.
*
* @param[in]     Mode      -aim mode
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_SetMode(VAR(Icu_ModeType, AUTOMATIC) Mode)
{
#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckModuleState((uint8)ICU_SETMODE_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
        result = Icu_CheckSetModeEnviroment(Mode);
        if ((Std_ReturnType)E_OK == result)
        {
#endif
#if (STD_ON == ICU_CHECK_PARAMS)
            result = Icu_CheckModeWhetherDefine(Mode);
            if ((Std_ReturnType)E_OK == result)
            {
#endif
                if (g_icuCurrentMode != Mode)
                {
                    VAR(Icu_ChannelType, AUTOMATIC) channelCount = 0U;
                    while ( channelCount < g_icuCfgPtr->totalNumberChannel )
                    {
                        switch (Mode)
                        {
                            case ICU_MODE_SLEEP:
                                 if (((uint8)g_icuChFeatureState[channelCount] & (uint8)ICU_WAKEUP_FEATURE_BIT)
                                                                              != (uint8)ICU_WAKEUP_FEATURE_BIT)
                                 {
                                     Icu_Impl_SetSleepMode(channelCount, &g_icuCfgPtr->moduleAchieveWayCfg);
                                 }
                                 else
                                 {
                                     /* Nothing to do */
                                 }
                                 break;

                            default:
                                if (((uint8)g_icuChFeatureState[channelCount] & (uint8)ICU_RUNNING_FEATURE_BIT)
                                                                             != (uint8)ICU_RUNNING_FEATURE_BIT)
                                {
                                    Icu_Impl_SetNormalMode(channelCount, &g_icuCfgPtr->moduleAchieveWayCfg);
                                }
                                else
                                {
                                    /* Nothing to do */
                                }
                                break;
                        }

                        channelCount++;
                    }
                    g_icuCurrentMode = Mode;
                }
                else
                {
                    /* Nothing to do */
                }
#if (STD_ON == ICU_CHECK_PARAMS)
            }
            else
            {
                /* Nothing to do */
            }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
        }
        else
        {
            /* Nothing to do */
        }
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_SETMODE_SERVICE_ID);
#endif
}
#endif

#if (STD_ON == ICU_DISABLE_WAKEUP_API_ENABLE)
/*!
* @brief         Disable wakeup capability on a channel.
*
* @param[in]     Channel      -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_DisableWakeup(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if ((STD_ON == ICU_CHECK_CALL_AND_CHANNEL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType,AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_FOUR_FUNCTION, (uint8)ICU_DISABLEWAKEUP_SERVICE_ID);

    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
        result = Icu_CheckChannelWakeupOpen(Channel, (uint8)ICU_DISABLEWAKEUP_SERVICE_ID);

        if ((Std_ReturnType)E_OK == result)
        {
#endif
            Icu_ClearChFeatureStateBit(Channel, (uint8)ICU_WAKEUP_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_PARAMS)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}
#endif

#if (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE)
/*!
* @brief         Enable wakeup capability on a channel.
*
* @param[in]     Channel      -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_EnableWakeup(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_CALL_AND_CHANNEL))
    VAR(Std_ReturnType,AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckApiRunInSleepMode((uint8)ICU_ENABLEWAKEUP_SERVICE_ID);

    if((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_FOUR_FUNCTION, (uint8)ICU_ENABLEWAKEUP_SERVICE_ID);

        if((Std_ReturnType)E_OK == result)
        {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
            if((Std_ReturnType)E_OK == Icu_CheckChannelWakeupOpen(Channel, (uint8)ICU_ENABLEWAKEUP_SERVICE_ID))
            {
#endif
                Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_WAKEUP_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_PARAMS)
            }
            else
            {
                /* Nothing to do */
            }
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}
#endif

#if ((STD_ON == ICU_WAKEUP_FUNCTIONALITY_API_ENABLE) && (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE) && \
     (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE))
/*!
* @brief         Verify whether Icu channel is the cause of a wakeup event.
*
* @param[in]     WakeupSource      -wakeup source feature value
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_CheckWakeup(VAR(EcuM_WakeupSourceType, AUTOMATIC) WakeupSource)
{
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    VAR(Std_ReturnType,AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Icu_CheckModuleState((uint8)ICU_CHECKWAKEUP_SERVICE_ID);

    if ((Std_ReturnType)E_OK == result)
    {
#endif
        VAR(Icu_ChannelType, AUTOMATIC) channelCount = 0U;
        P2CONST(Icu_ChCfgType, AUTOMATIC, ICU_APPL_CONST) channelWakeupParaPtr = NULL_PTR;

        while (channelCount < g_icuCfgPtr->totalNumberChannel)
        {
            channelWakeupParaPtr = &(*(g_icuCfgPtr->icuChCfgPtr))[channelCount];

            if(((uint8)ICU_WAKEUP_SOURCE_FEATURE_BIT | (uint8)ICU_WAKEUP_FEATURE_BIT) !=
              (((uint8)ICU_WAKEUP_SOURCE_FEATURE_BIT | (uint8)ICU_WAKEUP_FEATURE_BIT) & g_icuChFeatureState[channelCount]))
            {
                /* nothing to do */
            }
            else if(WakeupSource != (EcuM_WakeupSourceType)channelWakeupParaPtr->icuCHWakeupfeatureValue)
            {
                /* nothing to do */
            }
            else
            {
                EcuM_SetWakeupEvent(WakeupSource);
                Icu_ClearChFeatureStateBit(channelCount, (Icu_StateByteType)ICU_WAKEUP_SOURCE_FEATURE_BIT);
                break;
            }

            channelCount++;
        }
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_CHECKWAKEUP_SERVICE_ID);
#endif 
}
#endif 

/*!
* @brief         Set active edge on a channel.
*
* @param[in]     Channel      -channel id
* @param[in]     Activation   -aim active edge
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_SetActivationCondition(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                                VAR(Icu_ActivationType, AUTOMATIC) Activation)
{
#if ((STD_ON == ICU_CHECK_CALL_AND_CHANNEL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    result = Icu_CheckChannelSuitableApi
             (Channel, (uint8)ICU_MODE_EDGE_COUNTER | (uint8)ICU_MODE_SIGNAL_EDGE_DETECT | (uint8)ICU_MODE_TIMESTAMP, 
              (uint8)ICU_SETACTIVATIONCONDITION_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
        result = Icu_CheckEdgeWhetherDefine(Activation);
        if ((Std_ReturnType)E_OK == result)
        {
#endif
            /* clear g_icuChFeatureState's idle feature bit */
            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
            /* call Impl layer function*/
            Icu_Impl_SetActivationCondition(Channel, Activation,(*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChModeSelect,
                                            &g_icuCfgPtr->moduleAchieveWayCfg);
#if (STD_ON == ICU_CHECK_PARAMS)
        }
        else
        {
            /* Nothing to do */
        }
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Disable notification capability on a channel.
*
* @param[in]     Channel      -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_DisableNotification(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    /* check api applicable */
    result = Icu_CheckChannelSuitableApi(Channel,
             (uint8)ICU_MODE_SIGNAL_EDGE_DETECT | (uint8)ICU_MODE_TIMESTAMP, (uint8)ICU_DISABLENOTIFICATION_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        /* clear g_icuChFeatureState's notification feature bit */
        Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_NOTIFICATION_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
    /* set icu module state before exit API */
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_DISABLENOTIFICATION_SERVICE_ID);
#endif
}

/*!
* @brief         Enable notification capability on a channel.
*
* @param[in]     Channel      -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_EnableNotification(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    /* check api applicable */
    result = Icu_CheckChannelSuitableApi(Channel,
             (uint8)ICU_MODE_SIGNAL_EDGE_DETECT |(uint8)ICU_MODE_TIMESTAMP, (uint8)ICU_ENABLENOTIFICATION_SERVICE_ID);

    if ((Std_ReturnType)E_OK == result)
    {
#endif
        /* set g_icuChFeatureState's notification feature bit */
        Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_NOTIFICATION_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
    /* set icu module state before exit API */
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_ENABLENOTIFICATION_SERVICE_ID);
#endif
}

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)
/*!
* @brief         Read channel state.
*
* @param[in]     Channel      -channel id 
* @param[out]    None
* @param[in,out] None
*
* @retval        ICU_ACTIVE / ICU_IDLE
*/
FUNC(Icu_InputStateType, ICU_CODE) Icu_GetInputState(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
    VAR(Icu_InputStateType, AUTOMATIC) readResult = ICU_IDLE;

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType,AUTOMATIC) checkResult = (Std_ReturnType)E_NOT_OK;

    checkResult = Icu_CheckChannelSuitableApi
    (Channel, (uint8)ICU_MODE_SIGNAL_EDGE_DETECT | (uint8)ICU_MODE_SIGNAL_MEASUREMENT, (uint8)ICU_GETINPUTSTATE_SERVICE_ID);
    if ((Std_ReturnType)E_OK == checkResult)
    {
#endif
        readResult = (Icu_InputStateType)((((uint8)ICU_IDLE_FEATURE_BIT & (uint8)g_icuChFeatureState[Channel]) == \
                                            (uint8)ICU_IDLE_FEATURE_BIT ) ? ICU_ACTIVE : ICU_IDLE );

        switch (readResult)
        {
            case ICU_ACTIVE:
                Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
            break;

            default:
                if (ICU_MODE_SIGNAL_EDGE_DETECT ==(*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChModeSelect)
                {
                    readResult = Icu_Impl_GetInputState(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
                }
                else
                {
                    /* Nothing to do */
                }
            break;
        }
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(checkResult, (uint8)ICU_GETINPUTSTATE_SERVICE_ID);
#endif

    return readResult;
}
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/*!
* @brief         Configurate a channel for time stamp function.
*
* @param[in]     Channel          -channel id 
* @param[in]     BufferSize       -buffer size 
* @param[in]     NotifyInterval   -notification interval 
* @param[out]    BufferPtr        -pointer to time stamp buffer
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_StartTimestamp(VAR(Icu_ChannelType, AUTOMATIC) Channel,
    P2VAR(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr, VAR(uint16, AUTOMATIC) BufferSize,
    VAR(uint16, AUTOMATIC) NotifyInterval)
{
    VAR(boolean, AUTOMATIC) dmaEnable =  (boolean)FALSE;

#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_CALL_AND_CHANNEL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckApiRunInSleepMode((uint8)ICU_STARTTIMESTAMP_SERVICE_ID);
    if((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_TIMESTAMP, (uint8)ICU_STARTTIMESTAMP_SERVICE_ID);
        if ((Std_ReturnType)E_OK == result)
        {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
            result = Icu_CheckTimestampPara(Channel, BufferPtr, BufferSize, NotifyInterval);
            if ((Std_ReturnType)E_OK == result)
            {
#endif
                /* initialize global variant about time stamp according parameter */
                Icu_InitTimeStampGlobalVar(Channel, BufferPtr, BufferSize, NotifyInterval);
                /* clear g_icuChFeatureState's overflow feature bit */
                Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_OVERFLOW_FEATURE_BIT);

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
                if(ICU_PDL_DMA_CHANNEL_NUMBER != (*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChDmaChId)
                {
                    /* configurate the DMA TCD structure members */
                    Icu_InitTimeStampDma(Channel, BufferPtr, BufferSize, NotifyInterval);

                    /* configurate DMA channels */
                    Icu_Impl_SetDmaCh(Channel, &g_icuCfgPtr->moduleAchieveWayCfg, ENABLE);
                    dmaEnable = (boolean) TRUE;
                }
                else
                {
                    /* Nothing to do */
                }
#endif
                Icu_Impl_StartTimestamp(Channel, &g_icuCfgPtr->moduleAchieveWayCfg, dmaEnable);
#if (STD_ON == ICU_CHECK_PARAMS)
            }
            else
            {
                /* Nothing to do */
            }
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        }
        else
        {
            /* Nothing to do */
        }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_STARTTIMESTAMP_SERVICE_ID);
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Reset a time stamp function channel.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_StopTimestamp(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_TIMESTAMP, (uint8)ICU_STOPTIMESTAMP_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        result = Icu_CheckTimestampChannelWoring(Channel);
        if ((Std_ReturnType)E_OK == result)
        {
#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
            switch ((*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChDmaChId)
            {
                case ICU_PDL_DMA_CHANNEL_NUMBER:
                    break;

                default:
                    Icu_Impl_SetDmaCh(Channel, &g_icuCfgPtr->moduleAchieveWayCfg, DISABLE);
                    break;
            }
#endif
            /* call Impl layer function */
            Icu_Impl_StopTimestamp(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
            /* operate g_icuChFeatureState's feature bit */
            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
        }
        else
        {
            /* Nothing to do */
        }
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Get time stamp index number.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*
* @retval        Icu_IndexType    -time stamp index number
*/
FUNC(Icu_IndexType, ICU_CODE) Icu_GetTimestampIndex(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
    VAR(Icu_IndexType, AUTOMATIC) apiResult = 0U;

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_TIMESTAMP, (uint8)ICU_GETTIMESTAMPINDEX_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        VAR(boolean, AUTOMATIC) checkVal = (boolean)TRUE;

        checkVal = Icu_CheckChannelWhetherOverflow(Channel, (uint8)ICU_GETTIMESTAMPINDEX_SERVICE_ID, 
            (uint8)ICU_E_TIMESTAMP_RESULT_OVER_MAX);
        if ((boolean)FALSE == checkVal)
        {
#endif
            if (NULL_PTR == g_icuTimestampBufferPtr[Channel])
            {
                apiResult = 0U;
            }
            else
            {
#endif

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
                VAR(uint16, AUTOMATIC) dmaCount = 0U;
                switch ((*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChDmaChId)
                {
                    case ICU_PDL_DMA_CHANNEL_NUMBER:
                        apiResult = g_icuTimestampIndexResult[Channel];
                        break;

                    default:
                        dmaCount = (uint16)(s_startTimestampDmaChCfg[Channel].bufSize);
                        dmaCount = dmaCount -
                            (uint16)Pdl_TopDmaChDataNumRead((*(g_icuCfgPtr->icuChCfgPtr))[Channel].icuChDmaChId);
                        apiResult = g_icuTimestampIndexResult[Channel] + (Icu_IndexType)dmaCount;
                        break;
                }
#else
                apiResult = g_icuTimestampIndexResult[Channel];
#endif
#if (STD_ON == ICU_CHECK_PARAMS)
            }
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
    return apiResult;
}
#endif

#if (STD_ON == ICU_EDGE_COUNT_API_ENABLE)
/*!
* @brief         Set edge count result to zero.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_ResetEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_EDGE_COUNTER, (uint8)ICU_RESETEDGECOUNT_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        /* clear g_icuChFeatureState's overflow feature bit */
        Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_OVERFLOW_FEATURE_BIT);
        /* call Impl layer function */
        Icu_Impl_ResetEdgeCount(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Configurate a channel for edge count function.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_EnableEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if ((STD_ON == ICU_CHECK_GLOBAL_CALL)||(STD_ON == ICU_CHECK_CALL_AND_CHANNEL))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckApiRunInSleepMode((uint8)ICU_ENABLEEDGECOUNT_SERVICE_ID);
    if((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        result = Icu_CheckChannelSuitableApi(Channel,(uint8)ICU_MODE_EDGE_COUNTER, (uint8)ICU_ENABLEEDGECOUNT_SERVICE_ID);
        if ((Std_ReturnType)E_OK == result)
        {
#endif
            /* clear g_icuChFeatureState's overflow feature bit */
            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_OVERFLOW_FEATURE_BIT);
            /* set g_icuChFeatureState's running feature bit */
            Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
            /* call Impl layer function */
            Icu_Impl_EnableEdgeCount(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Reset a edge count function channel.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_DisableEdgeCount(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Icu_CheckChannelSuitableApi(Channel,(uint8)ICU_MODE_EDGE_COUNTER, (uint8)ICU_DISABLEEDGECOUNT_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        /* call Impl layer fnction */
        Icu_Impl_DisableEdgeCount(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
        /* clear g_icuChFeatureState's flag bit */
        Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Get edge count number.
*
* @param[in]     Channel               -channel id 
* @param[out]    None
* @param[in,out] None
*
* @retval        Icu_EdgeNumberType    -edge count number
*/
FUNC(Icu_EdgeNumberType, ICU_CODE) Icu_GetEdgeNumbers(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
    VAR(Icu_EdgeNumberType, AUTOMATIC) countResult = 0U;

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType, AUTOMATIC) checkResult = (Std_ReturnType)E_NOT_OK;
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE))
    VAR(boolean, AUTOMATIC) checkVal = (boolean)TRUE;
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    checkResult = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_EDGE_COUNTER, (uint8)ICU_GETEDGENUMBERS_SERVICE_ID);
    if ((Std_ReturnType)E_OK == checkResult)
    {
#endif

#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE))
        checkVal = Icu_CheckChannelWhetherOverflow(Channel, (uint8)ICU_GETEDGENUMBERS_SERVICE_ID, (uint8)ICU_E_EDGECOUNT_OVER_MAX);
        if ((boolean)FALSE == checkVal)
        {
#endif
            /* call Impl layer function */
            countResult = Icu_Impl_GetEdgeNumbers(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
#if ((STD_ON == ICU_CHECK_PARAMS) && (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE))
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
    return countResult;
}
#endif

#if (STD_ON == ICU_EDGE_DETECT_API_ENABLE)
/*!
* @brief         Configurate a channel for edge detect function.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_EnableEdgeDetection(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_CALL_AND_CHANNEL))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckApiRunInSleepMode((uint8)ICU_ENABLEEDGEDETECTION_SERVICE_ID);
    if((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        result = Icu_CheckChannelSuitableApi
                 (Channel,(uint8)ICU_MODE_SIGNAL_EDGE_DETECT, (uint8)ICU_ENABLEEDGEDETECTION_SERVICE_ID);
        if ((Std_ReturnType)E_OK == result)
        {
#endif
            /* set channel at running state */
            Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
            /* call Impl layer */
            Icu_Impl_EnableEdgeDetection(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        }
        else
        {
            /* Nothing to do */
        }
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Reset a channel for edge detect function.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_DisableEdgeDetection(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType,AUTOMATIC) result = Icu_CheckChannelSuitableApi
        (Channel,(uint8)ICU_MODE_SIGNAL_EDGE_DETECT, (uint8)ICU_DISABLEEDGEDETECTION_SERVICE_ID);

    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Icu_Impl_DisableEdgeDetection(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
        Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}
#endif

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
/*!
* @brief         Configurate a channel for signal measurement function.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_StartSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    if((Std_ReturnType)E_OK == Icu_CheckApiRunInSleepMode((uint8)ICU_STARTSIGNALMEASUREMENT_SERVICE_ID))
    {
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        VAR(Std_ReturnType,AUTOMATIC) result = Icu_CheckChannelSuitableApi
            (Channel,(uint8)ICU_MODE_SIGNAL_MEASUREMENT, (uint8)ICU_STARTSIGNALMEASUREMENT_SERVICE_ID);

        if ((Std_ReturnType)E_OK == result)
        {
#endif
            P2CONST(Icu_ChCfgType, AUTOMATIC, ICU_APPL_CONST) channelFunction = &(*(g_icuCfgPtr->icuChCfgPtr))[Channel];

            SchM_Enter_Icu_ICU_CRITICAL_SECTION8();
            {
                Icu_SetChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
                Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_OVERFLOW_FEATURE_BIT);
#if ((STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) || (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE))
                s_icuValidLevelTimeResult[Channel] = 0U;
                s_icuPeriodTimeResult[Channel] = 0U;
#endif
            }
            SchM_Exit_Icu_ICU_CRITICAL_SECTION8();
            Icu_Impl_StartSignalMeasurement(Channel,
                                           &g_icuCfgPtr->moduleAchieveWayCfg,
            /*** @warning Icu_c_MISRA_REF3 An expression of 'essentially unsigned' type (unsigned char) is being cast to enum type 'Icu_SignalMeasurementPropertyType'. */
                                           (Icu_SignalMeasurementPropertyType)channelFunction->icuChModeCfgItem);
            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}

/*!
* @brief         Reset a channel for signal measurement function.
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_StopSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType,AUTOMATIC) result = Icu_CheckChannelSuitableApi
       (Channel, (uint8)ICU_MODE_SIGNAL_MEASUREMENT, (uint8)ICU_STOPSIGNALMEASUREMENT_SERVICE_ID);

    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Icu_Impl_StopSignalMeasurement(Channel, &g_icuCfgPtr->moduleAchieveWayCfg);
        Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}
#endif

#if (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE) && (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
/*!
* @brief         Get signal measurement result(high level,low level ,period time).
*
* @param[in]     Channel          -channel id 
* @param[out]    None
* @param[in,out] None
*
* @retval        Icu_ValueType   -measurement result
*/
FUNC(Icu_ValueType, ICU_CODE) Icu_GetTimeElapsed(VAR(Icu_ChannelType, AUTOMATIC) Channel)
{
    VAR(Icu_ValueType, AUTOMATIC) timeResult = (Icu_ValueType)0U;
#if ((STD_ON == ICU_CHECK_CALL_AND_CHANNEL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType, AUTOMATIC) checkResult = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    checkResult = Icu_CheckChannelSuitableApi
                  (Channel, (uint8)ICU_MODE_SIGNAL_MEASUREMENT, (uint8)ICU_GETTIMEELAPSED_SERVICE_ID);
    if ((Std_ReturnType)E_OK == checkResult)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        VAR(boolean, AUTOMATIC) checkVal = (boolean)TRUE;
        checkVal = Icu_CheckChannelWhetherOverflow(Channel, (uint8)ICU_GETTIMEELAPSED_SERVICE_ID, (uint8)ICU_E_MEASURE_CHNV_REG_OVER);
        if ((boolean)FALSE == checkVal)
        {
#endif
            checkResult = Icu_CheckMeasureProperty(Channel,
                                                  (uint16)ICU_LOW_TIME | (uint16)ICU_HIGH_TIME | (uint16)ICU_PERIOD_TIME,
                                                  (uint8)ICU_GETTIMEELAPSED_SERVICE_ID);

            if ((Std_ReturnType)E_OK == checkResult)
            {
#endif
                SchM_Enter_Icu_ICU_CRITICAL_SECTION5();
                {
                    P2CONST(Icu_ChCfgType, AUTOMATIC, ICU_APPL_CONST) ptr = &(*(g_icuCfgPtr->icuChCfgPtr))[Channel];

                    switch (ptr->icuChModeCfgItem)
                    {
                        case (Icu_ModeCfgItemType)ICU_PERIOD_TIME:
                            timeResult = s_icuPeriodTimeResult[Channel];
                            s_icuPeriodTimeResult[Channel] = (Icu_ValueType)0U;
                            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
                            break;

                        default:
                            timeResult = s_icuValidLevelTimeResult[Channel];
                            s_icuValidLevelTimeResult[Channel] = (Icu_ValueType)0U;
                            Icu_ClearChFeatureStateBit(Channel, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
                            break;
                    }
                }
                SchM_Exit_Icu_ICU_CRITICAL_SECTION5();
#if (STD_ON == ICU_CHECK_PARAMS)
            }
            else
            {
                /* Nothing to do */
            }
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
    return timeResult;
}
#endif

#if (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE) && (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
/*!
* @brief         Get signal measurement result(dutycycle).
*
* @param[in]     Channel            -channel id
* @param[out]    DutyCycleValues    -measurement resule buffer
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_GetDutyCycleValues(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                            P2VAR(Icu_DutyCycleType, AUTOMATIC, ICU_APPL_DATA) DutyCycleValues)
{
#if ((STD_ON == ICU_CHECK_CALL_AND_CHANNEL) || (STD_ON == ICU_CHECK_PARAMS))
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    result = Icu_CheckChannelSuitableApi(Channel, (uint8)ICU_MODE_SIGNAL_MEASUREMENT, (uint8)ICU_GETDUTYCYCLEVALUES_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        VAR(boolean, AUTOMATIC) checkVal = (boolean)TRUE;
        checkVal = Icu_CheckChannelWhetherOverflow(Channel, (uint8)ICU_GETDUTYCYCLEVALUES_SERVICE_ID, (uint8)ICU_E_MEASURE_CHNV_REG_OVER);
        if ((boolean)FALSE == checkVal)
        {
#endif
            result = Icu_CheckMeasureProperty(Channel,(uint16)ICU_DUTY_CYCLE, (uint8)ICU_GETDUTYCYCLEVALUES_SERVICE_ID);
            if ((Std_ReturnType)E_OK == result)
            {
                result = Icu_CheckDutyCycleNullPara(DutyCycleValues);
                if ((Std_ReturnType)E_OK == result)
                {
#endif
                    SchM_Enter_Icu_ICU_CRITICAL_SECTION6();
                    switch (s_icuPeriodTimeResult[Channel])
                    {
                        case (Icu_ValueType)0U:
                            DutyCycleValues->ActiveTime = (Icu_ValueType)0U;
                            DutyCycleValues->PeriodTime = (Icu_ValueType)0U;
                            break;

                        default:
                            DutyCycleValues->ActiveTime = (Icu_ValueType)s_icuValidLevelTimeResult[Channel];
                            DutyCycleValues->PeriodTime = (Icu_ValueType)s_icuPeriodTimeResult[Channel];
                            s_icuValidLevelTimeResult[Channel] = (Icu_ValueType)0U;
                            s_icuPeriodTimeResult[Channel] = (Icu_ValueType)0U;
                            break;
                    }
                    SchM_Exit_Icu_ICU_CRITICAL_SECTION6();
#if (STD_ON == ICU_CHECK_PARAMS)
                }
                else
                {
                    /* Nothing to do */
                }
            }
            else
            {
                /* Nothing to do */
            }
#if (STD_OFF == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#endif
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    }
    else
    {
        /* Nothing to do */
    }
#endif
}
#endif

#if (STD_ON == ICU_GET_VERSION_INFO_API_ENABLE)
/*!
* @brief         API for get Icu version information.
*
* @param[in]     versioninfo            -point to Icu version
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, ICU_APPL_DATA)versioninfo)
{
#if (STD_ON == ICU_CHECK_PARAMS)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)((NULL_PTR == versioninfo) ? E_NOT_OK : E_OK );

    if ((Std_ReturnType)E_NOT_OK == result)
    {
        (void)Det_ReportError((uint16)ICU_H_MODULE_ID, (uint8)0U,
                              (uint8)ICU_GETVERSIONINFO_SERVICE_ID, (uint8)ICU_E_PARAM_VINFO);
    }
    else
    {
#endif
        (versioninfo)->vendorID         = (uint16)ICU_H_VENDOR_ID;
        (versioninfo)->moduleID         = (uint16)ICU_H_MODULE_ID;
        (versioninfo)->sw_major_version = (uint8)ICU_H_SW_MAJOR_VERSION;
        (versioninfo)->sw_minor_version = (uint8)ICU_H_SW_MINOR_VERSION;
        (versioninfo)->sw_patch_version = (uint8)ICU_H_SW_PATCH_VERSION;
#if (STD_ON == ICU_CHECK_PARAMS)
    }
#endif
}
#endif

#if ((STD_ON == ICU_READ_CCN_REG_API_ENABLE) && ((STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE) || \
     (STD_ON == ICU_TIMESTAMP_API_ENABLE)))
/*!
* @brief    This service returns the value of Capture register.
*           This API is used to measure the time difference  between 2 different timer channels.
*
* @param[in]     ch         -channel id
* @param[out]    None
* @param[in,out] None
*
* @retval        Icu_ValueType
*/
FUNC(Icu_ValueType, ICU_CODE) Icu_ReadCCnRegValue(VAR(Icu_ChannelType, AUTOMATIC) ch)
{
    VAR(Icu_ValueType, AUTOMATIC) regValue = (Icu_ValueType)0U;
#if (STD_ON == ICU_CHECK_CALL_AND_CHANNEL)
    VAR(Std_ReturnType,AUTOMATIC) checkChannel = (Std_ReturnType)E_NOT_OK;
    checkChannel = Icu_CheckChannelSuitableApi(ch,
                                              ((uint8)ICU_MODE_SIGNAL_MEASUREMENT | (uint8)ICU_MODE_TIMESTAMP),
                                               (uint8)ICU_GETCHVREGVALUE_SERVICE_ID);
    regValue = (Icu_ValueType)(((Std_ReturnType)E_OK == checkChannel) ?
                              (Icu_Impl_ReadTmrCCnRegValue(ch, &g_icuCfgPtr->moduleAchieveWayCfg)):(0U));
#else
    regValue = (Icu_ValueType)(Icu_Impl_ReadTmrCCnRegValue(ch, &g_icuCfgPtr->moduleAchieveWayCfg));
#endif
    return regValue;
}
#endif

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)
/*!
* @brief         API for set Icu clock prescaler.
*
* @param[in]     divMode            -prescaler mode
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_SetClkPrescaler(VAR(Icu_ClockDivisionType, AUTOMATIC) divMode)
{
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#endif

#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    result = Icu_CheckModuleState((uint8)ICU_SETCLOCKMODE_SERVICE_ID);
    if ((Std_ReturnType)E_OK == result)
    {
#endif

#if (STD_ON == ICU_CHECK_PARAMS)
        if ((Std_ReturnType)E_OK == Icu_CheckPrescalerWhetherDefine(divMode))
        {
#endif
            Icu_Impl_SetClkPrescaler(&g_icuCfgPtr->moduleAchieveWayCfg, divMode);
#if (STD_ON == ICU_CHECK_PARAMS)
        }
        else
        {
            /* Nothing to do */
        }
#endif
#if (STD_ON == ICU_CHECK_GLOBAL_CALL)
    }
    else
    {
        /* Nothing to do */
    }
    Icu_SetModuleStateBeforeExitApi(result, (uint8)ICU_SETCLOCKMODE_SERVICE_ID);
#endif
}
#endif

/*!
* @brief         Interrupt process function -- report events.
*
* @param[in]     HWCh          -hardware channel
* @param[in]     ovfFlag       -flag of overflow event
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_PrepareCallNotification(VAR(Icu_ChannelType, AUTOMATIC) HWCh, VAR(boolean, AUTOMATIC) ovfFlag)
{
    VAR(Icu_ChannelType, AUTOMATIC) ch = (*(g_icuCfgPtr->icuHwMapPtr))[HWCh];

    Icu_SetChFeatureStateBit(ch, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
    Icu_CallWakeupAndOverflowNotification(HWCh, ovfFlag);

    if((uint8)ICU_NOTIFICATION_FEATURE_BIT != ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_NOTIFICATION_FEATURE_BIT))
    {
        /* nothing to do */
    }
    else if(NULL_PTR == (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr)
    {
        /* nothing to do */
    }
    else
    {
        /* execute notification function */
        (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr();
    }
}

/*!
* @brief         Interrupt process function -- call notification.
*
* @param[in]     HWCh          -hardware channel
* @param[in]     ovfFlag       -flag of overflow event
* @param[out]    None
* @param[in,out] None
*/
FUNC(void, ICU_CODE) Icu_CallWakeupAndOverflowNotification
                     (VAR(Icu_ChannelType, AUTOMATIC) HWCh, VAR(boolean, AUTOMATIC) ovfFlag)
{
    VAR(Icu_ChannelType, AUTOMATIC) ch = (*(g_icuCfgPtr->icuHwMapPtr))[HWCh];
#if (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE)
    VAR(boolean, AUTOMATIC) wakeupFunc;
    VAR(boolean, AUTOMATIC) sleepFunc;

    wakeupFunc = ((uint8)ICU_WAKEUP_FEATURE_BIT == ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_WAKEUP_FEATURE_BIT)) ?
                 (boolean)TRUE : (boolean)FALSE ;
    sleepFunc  = (ICU_MODE_SLEEP == g_icuCurrentMode)? (boolean)TRUE : (boolean)FALSE ;

    if((boolean)TRUE != wakeupFunc)
    {
        /* nothing to do */
    }
    else if((boolean)TRUE != sleepFunc)
    {
        /* nothing to do */
    }
    else
    {
        Icu_SetChFeatureStateBit(ch, (Icu_StateByteType)ICU_WAKEUP_SOURCE_FEATURE_BIT);
        EcuM_CheckWakeup((EcuM_WakeupSourceType)(*(g_icuCfgPtr->icuChCfgPtr))[ch].icuCHWakeupfeatureValue);
    }
#endif

    if ((boolean)TRUE == ovfFlag)
    {
        Icu_SetChFeatureStateBit(ch, (Icu_StateByteType)ICU_OVERFLOW_FEATURE_BIT);
#if defined(ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
        if (NULL_PTR != (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuCHOverflowNotifyFunctionPtr)
        {
           (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuCHOverflowNotifyFunctionPtr();
        }
        else
        {
            /* Nothing to do */
        }
#endif
    }
    else
    {
        /* Nothing to do */
    }
}

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/*!
* @brief         Record time stamp value to internal buffer.
*
* @param[in]     HWCh              -hardware channel
* @param[in]     captureCnt        -the number of capture
* @param[in]     bufferAddrPtr     -point to buffer
* @param[in]     ovfFlag           -overflow flag
* @param[out]    None
* @param[in,out] None
*/
FUNC(void,ICU_CODE) Icu_DealWithTimestamp(VAR(Icu_ChannelType, AUTOMATIC)HWCh, VAR(uint8, AUTOMATIC) captureCnt,
    P2CONST(Icu_ValueType, AUTOMATIC, ICU_APPL_CONST)bufferAddrPtr, VAR(boolean, AUTOMATIC) ovfFlag)
{
    VAR(uint8, AUTOMATIC) count = 0U;
    VAR(Icu_ChannelType, AUTOMATIC) ch = (*(g_icuCfgPtr->icuHwMapPtr))[HWCh];

    Icu_CallWakeupAndOverflowNotification(HWCh, ovfFlag);

    SchM_Enter_Icu_ICU_CRITICAL_SECTION4();
    {
        CONST(Icu_IndexType, ICU_CONST) buffTimestampSize = g_icuTimestampBufferSize[ch];
        CONST(Icu_IndexType, ICU_CONST) buffNotifyIntervalValue = g_icuTimestampNotifyIntervalValue[ch];
        VAR(boolean, AUTOMATIC) continueProcess = (boolean)TRUE;

        while (count < captureCnt)
        {
            /*** @warning Icu_c_MISRA_REF4 Performing pointer arithmetic. */
            g_icuTimestampBufferPtr[ch][g_icuTimestampIndexResult[ch]] = *(bufferAddrPtr + count);

            g_icuTimestampIndexResult[ch] = g_icuTimestampIndexResult[ch] + 1U;

            if (g_icuTimestampIndexResult[ch] >= buffTimestampSize)
            {
                switch ((*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChModeCfgItem)
                {
                    case (uint8)ICU_CIRCULAR_BUFFER:
                        g_icuTimestampIndexResult[ch] = 0U;
                        break;

                    default:
                        /* stop record time stamp value when linear buffer is full */
                        Icu_Impl_StopTimestamp(ch, &g_icuCfgPtr->moduleAchieveWayCfg);
                        Icu_ClearChFeatureStateBit(ch, (Icu_StateByteType)ICU_RUNNING_FEATURE_BIT);
                        continueProcess = (boolean)FALSE;   /* indicate stop time stamp */
                        break;
                }
            }
            else
            {
                /* Nothing to do */
            }

            if (0U == buffNotifyIntervalValue)
            {
                /* no notify interval function will be called */
            }
            else
            {
                g_icuNotifyCountValue[ch] = g_icuNotifyCountValue[ch] + 1U;
                /* prepare to call notification function */
                if (g_icuNotifyCountValue[ch] >= buffNotifyIntervalValue)
                {
                    g_icuNotifyCountValue[ch] = 0U;

                    if((uint8)ICU_NOTIFICATION_FEATURE_BIT != ((uint8)g_icuChFeatureState[ch] & (uint8)ICU_NOTIFICATION_FEATURE_BIT))
                    {
                        /* nothing to do */
                    }
                    else if(NULL_PTR == (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr)
                    {
                        /* nothing to do */
                    }
                    else
                    {
                        /* execute notification function */
                        (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr();
                    }
                }
                else
                {
                    /* Nothing to do */
                }
            }

            if ((boolean)FALSE == continueProcess)
            {
                break;
            }
            else
            {
                /* Nothing to do */
            }

            count++;
        }
    }
    SchM_Exit_Icu_ICU_CRITICAL_SECTION4();
}
#endif

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE) && (STD_ON == ICU_TIMESTAMP_API_ENABLE)
/*!
* @brief         Deal with time stamp with DMA.
*
* @param[in]     ch          -channel id
* @param[out]    None
* @param[in,out] None
*/
FUNC(void,ICU_CODE) Icu_DealWithTimestampWithDma(VAR(Icu_ChannelType, AUTOMATIC)ch)
{
    VAR (Icu_IndexType, AUTOMATIC) icuBufferSave = 0U;
    VAR (Pdl_ChType, AUTOMATIC) icuChDmaChId =(*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChDmaChId;
    VAR (Icu_IndexType, AUTOMATIC) iterCnt = (Icu_IndexType)s_startTimestampDmaChCfg[ch].bufSize;

    SchM_Enter_Icu_ICU_CRITICAL_SECTION3();
    {
        g_icuTimestampIndexResult[ch] = g_icuTimestampIndexResult[ch] + iterCnt;
        icuBufferSave = g_icuTimestampBufferSize[ch] - g_icuTimestampIndexResult[ch];

        /* Deal with DMA notification */
        if ((Icu_IndexType)0 == g_icuTimestampNotifyIntervalValue[ch])
        {
             /* Nothing to do */
        }
        else
        {
            g_icuNotifyCountValue[ch] = g_icuNotifyCountValue[ch] + iterCnt;

            if (g_icuNotifyCountValue[ch] == g_icuTimestampNotifyIntervalValue[ch])
            {
                g_icuNotifyCountValue[ch] = 0U;

                if((uint8)ICU_NOTIFICATION_FEATURE_BIT != (g_icuChFeatureState[ch] & (uint8)ICU_NOTIFICATION_FEATURE_BIT))
                {
                    /* nothing to do */
                }
                else if(NULL_PTR == (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr)
                {
                    /* nothing to do */
                }
                else
                {
                    /* execute notification function */
                    (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChNotifyFunctionPtr();
                }
            }
            else
            {
                /* Nothing to do */
            }
        }

        if (0U == icuBufferSave)
        {
            if ((uint8) ICU_CIRCULAR_BUFFER == (*(g_icuCfgPtr->icuChCfgPtr))[ch].icuChModeCfgItem)
            {
                g_icuTimestampIndexResult[ch] = 0U;
                
                /* Disable the Dma channel */
                Pdl_TopDmaChDis(icuChDmaChId);

                if(g_icuTimestampBufferSize[ch] <= (g_icuTimestampNotifyIntervalValue[ch] - g_icuNotifyCountValue[ch]))
                {
                    /* Refresh the buffer size of the Dma channel */
                    Pdl_TopDmaChDataNumSet(icuChDmaChId, g_icuTimestampBufferSize[ch]);
                    /* Refresh the bufSize for using in the beginning of the API */
                    s_startTimestampDmaChCfg[ch].bufSize = g_icuTimestampBufferSize[ch];
                }
                else if((Icu_IndexType)0 == g_icuTimestampNotifyIntervalValue[ch])
                {
                    /* Refresh the buffer size of the Dma channel */
                    Pdl_TopDmaChDataNumSet(icuChDmaChId, g_icuTimestampBufferSize[ch]);
                    /* Refresh the bufSize for using in the beginning of the API */
                    s_startTimestampDmaChCfg[ch].bufSize = g_icuTimestampBufferSize[ch];
                }
                else
                {
                    /* Refresh the buffer size of the Dma channel */
                    Pdl_TopDmaChDataNumSet(icuChDmaChId, (uint32)g_icuTimestampNotifyIntervalValue[ch] - (uint32)g_icuNotifyCountValue[ch]);
                    /* Refresh the bufSize for using in the beginning of the API */
                    s_startTimestampDmaChCfg[ch].bufSize = (uint32)g_icuTimestampNotifyIntervalValue[ch] - (uint32)g_icuNotifyCountValue[ch];
                }

                /* Refresh the memmory address */
                Pdl_TopDmaMAddrRefresh(icuChDmaChId, (uint32)(s_startTimestampDmaChCfg[ch].memAddr));

                /* Enable the DMA transfer complete interrupt */
                Pdl_TopDmaNotifiEn(icuChDmaChId, PDL_DMA_TRAN_COMPLETED);
                /* Enable the Dma channel */
                Pdl_TopDmaChEn(icuChDmaChId);
            }
            else
            {
                Icu_Impl_StopTimestamp(ch, &g_icuCfgPtr->moduleAchieveWayCfg);
                Icu_ClearChFeatureStateBit(ch, (uint8)ICU_RUNNING_FEATURE_BIT);
            }
        }
        else
        {
            /* Disable the Dma channel */
            Pdl_TopDmaChDis(icuChDmaChId);

            if (iterCnt < g_icuTimestampNotifyIntervalValue[ch])
            {
                Pdl_TopDmaChDataNumSet(icuChDmaChId, g_icuTimestampNotifyIntervalValue[ch]);
                /* Refresh the bufSize for using in the beginning of the API */
                s_startTimestampDmaChCfg[ch].bufSize = g_icuTimestampNotifyIntervalValue[ch];
            }
            else
            {
                /* Intentionally Empty */
            }

            if (icuBufferSave < g_icuTimestampNotifyIntervalValue[ch])
            {
                Pdl_TopDmaChDataNumSet(icuChDmaChId, icuBufferSave);
                /* Refresh the bufSize for using in the beginning of the API */
                s_startTimestampDmaChCfg[ch].bufSize = icuBufferSave;
            }
            else
            {
                Pdl_TopDmaChDataNumSet(icuChDmaChId, g_icuTimestampNotifyIntervalValue[ch]);
                /* Refresh the bufSize for using in the beginning of the API */
                s_startTimestampDmaChCfg[ch].bufSize = g_icuTimestampNotifyIntervalValue[ch];
            }
            
            /* Refresh the memmory address */
            Pdl_TopDmaMAddrRefresh(icuChDmaChId, (uint32)(s_startTimestampDmaChCfg[ch].memAddr + 
                (g_icuTimestampIndexResult[ch] * sizeof(Icu_ValueType))));

            /* Enable the DMA transfer complete interrupt */
            Pdl_TopDmaNotifiEn(icuChDmaChId, PDL_DMA_TRAN_COMPLETED);
            /* Enable the Dma channel */
            Pdl_TopDmaChEn(icuChDmaChId);
        }
    }
    SchM_Exit_Icu_ICU_CRITICAL_SECTION3();
}
#endif

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
/*!
* @brief         Signal measurement process.
*
* @param[in]     HWCh              -hardware channel
* @param[in]     activeLevelCount  -active pulse width
* @param[in]     periodCount       -period width
* @param[out]    None
* @param[in,out] None
*/
FUNC(void,ICU_CODE) Icu_DealWithSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) HWCh, VAR(Icu_ValueType, AUTOMATIC) activeLevelCount,
                                                  VAR(Icu_ValueType, AUTOMATIC) periodCount, VAR(boolean, AUTOMATIC) ovfFlag)
{
    VAR(Icu_ChannelType, AUTOMATIC) ch = (*(g_icuCfgPtr->icuHwMapPtr))[HWCh];

    (void)ovfFlag;

    SchM_Enter_Icu_ICU_CRITICAL_SECTION7();
    {
        s_icuValidLevelTimeResult[ch] = activeLevelCount;
        s_icuPeriodTimeResult[ch] = periodCount;
        Icu_SetChFeatureStateBit(ch, (Icu_StateByteType)ICU_IDLE_FEATURE_BIT);
    }
    SchM_Exit_Icu_ICU_CRITICAL_SECTION7();
}
#endif

/**@} end of group ICU_Fuctions */

#define ICU_STOP_SEC_CODE
#include "Icu_MemMap.h"

#ifdef __cplusplus
}
#endif

/**@} end of group ICU_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
