/**
*     @file            Icu_Ipw.c
*     @version 1.0.0
*
*     @brief   AUTOSAR Icu - ICU Driver LLD source file.
*     @details ICU driver source file, containing the LLD variables and functions that are used by
*              the ICU driver.
*
*     @addtogroup ICU_MODULE
*     @{
*/
/*==================================================================================================
*     Project AUTOSAR 4.3 MCAL
*     Platform PA
*     Peripheral eMIOS SIU
*     Dependencies none
*
*     Autosar Version 4.3.1
*     Autosar Revision ASR_REL_4_3_REV_0001
*     Autosar ConfVariant
*     SWVersion 1.0.0
*     BuildVersion MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*     (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*     All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
* The used compilers use more than 31 chars for identifiers.
*
* @section ICU_IPW_C_REF_1
* Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents
* of a header file being included more than once.
* This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section ICU_IPW_C_REF_2
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor
* directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
*
* @section ICU_IPW_C_REF_3
* Violates MISRA 2012 Required Rule 10.3, The value of an expression shall not be assigned to an object with a
* narrower essential type or of a different essential type category.
* The assignment and cast are done respective to mask and shift to get the modes/params.
*
* @section ICU_IPW_C_REF_4
* Violates MISRA 2012 Advisory Rule 10.5, The value of an expression should not be cast to an inappropriate
* essential type.
* The assignment and cast are done respective to mask and shift to get the modes/params.
*
* @section ICU_IPW_C_REF_5
* Violates MISRA 2012 Advisory Rule 8.7, Functions and objects should not be defined with external linkage if
* they are referenced in only one translation unit.
* External linkage is needed to "export" the ISR handler to MCL driver.
*
*/

/*==================================================================================================
*                                          INCLUDE FILES
*  1) system and project includes
*  2) needed interfaces from external units
*  3) internal and external interfaces from this unit
==================================================================================================*/
#include "Mcal.h"

#include "Icu_Cfg.h"

#include "Icu_Ipw.h"
#include "Icu_eMios.h"
#include "Icu_Siu.h"
/*==================================================================================================
*                                         LOCAL MACROS
==================================================================================================*/

#define ICU_IPW_VENDOR_ID_C                     43
#define ICU_IPW_AR_RELEASE_MAJOR_VERSION_C      4
#define ICU_IPW_AR_RELEASE_MINOR_VERSION_C      3
#define ICU_IPW_AR_RELEASE_REVISION_VERSION_C   1
#define ICU_IPW_SW_MAJOR_VERSION_C              1
#define ICU_IPW_SW_MINOR_VERSION_C              0
#define ICU_IPW_SW_PATCH_VERSION_C              0
/*==================================================================================================
*                                       FILE VERSION CHECKS
==================================================================================================*/

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != MCAL_AR_RELEASE_MAJOR_VERSION) || \
         (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != MCAL_AR_RELEASE_MINOR_VERSION))
            #error "AutoSar Version Numbers of Icu_Ipw.c and Mcal.h are different"
    #endif
#endif


#if (ICU_IPW_VENDOR_ID_C != ICU_VENDOR_ID_CFG)
#error "Icu_Ipw.c and Icu_Cfg.h have different vendor IDs"
#endif
/* Check if source file and Icu_Cfg header file are of the same Autosar version */
#if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != ICU_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != ICU_AR_RELEASE_MINOR_VERSION_CFG) || \
     (ICU_IPW_AR_RELEASE_REVISION_VERSION_C != ICU_AR_RELEASE_REVISION_VERSION_CFG))
    #error "AutoSar Version Numbers of Icu_Cfg.h and Icu_Ipw.c are different"
    #endif
/* Check if source file and Icu_Cfg header file are of the same Software version */
#if ((ICU_IPW_SW_MAJOR_VERSION_C != ICU_SW_MAJOR_VERSION_CFG) || \
     (ICU_IPW_SW_MINOR_VERSION_C != ICU_SW_MINOR_VERSION_CFG) || \
     (ICU_IPW_SW_PATCH_VERSION_C != ICU_SW_PATCH_VERSION_CFG))
#error "Software Version Numbers of Icu_Cfg.h and Icu_Ipw.c are different"
#endif


#if (ICU_IPW_VENDOR_ID_C != ICU_TYPES_VENDOR_ID)
#error "Icu_Ipw.c and Icu_Types.h have different vendor IDs"
#endif
/* Check if source file and Icu_Types header file are of the same Autosar version */
#if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != ICU_TYPES_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != ICU_TYPES_AR_RELEASE_MINOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_REVISION_VERSION_C != ICU_TYPES_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Icu_Types.h and Icu_Ipw.c are different"
    #endif
/* Check if source file and Icu_Types header file are of the same Software version */
#if ((ICU_IPW_SW_MAJOR_VERSION_C != ICU_TYPES_SW_MAJOR_VERSION) || \
     (ICU_IPW_SW_MINOR_VERSION_C != ICU_TYPES_SW_MINOR_VERSION) || \
     (ICU_IPW_SW_PATCH_VERSION_C != ICU_TYPES_SW_PATCH_VERSION))
#error "Software Version Numbers of Icu_Types.h and Icu_Ipw.c are different"
#endif


#if (ICU_IPW_VENDOR_ID_C != ICU_IPW_VENDOR_ID)
    #error "Icu_Ipw.c and Icu_Ipw.h have different vendor IDs"
#endif
/* Check if source file and Icu_Ipw header file are of the same Autosar version */
#if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != ICU_IPW_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != ICU_IPW_AR_RELEASE_MINOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_REVISION_VERSION_C != ICU_IPW_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Icu_Ipw.c and Icu_Ipw.h are different"
#endif
/* Check if source file and Icu_Ipw header file are of the same Software version */
#if ((ICU_IPW_SW_MAJOR_VERSION_C != ICU_IPW_SW_MAJOR_VERSION) || \
     (ICU_IPW_SW_MINOR_VERSION_C != ICU_IPW_SW_MINOR_VERSION) || \
     (ICU_IPW_SW_PATCH_VERSION_C != ICU_IPW_SW_PATCH_VERSION))
#error "Software Version Numbers of Icu_Ipw.c and Icu_Ipw.h are different"
#endif

 /* Check if source file and Icu_eMIOS header file are of the same vendor */
#if (ICU_IPW_VENDOR_ID_C != ICU_EMIOS_VENDOR_ID)
    #error "Icu_Ipw.c and Icu_eMIOS.h have different vendor IDs"
#endif
    /* Check if source file and Icu_eMIOS header file are of the same Autosar version */
#if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != ICU_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != ICU_EMIOS_AR_RELEASE_MINOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_REVISION_VERSION_C != ICU_EMIOS_AR_RELEASE_REVISION_VERSION))
 #error "AutoSar Version Numbers of Icu_Ipw.c and Icu_eMIOS.h are different"
#endif
/* Check if source file andIcu_eMIOS header file are of the same software version */
#if ((ICU_IPW_SW_MAJOR_VERSION_C != ICU_EMIOS_SW_MAJOR_VERSION) || \
     (ICU_IPW_SW_MINOR_VERSION_C != ICU_EMIOS_SW_MINOR_VERSION) || \
     (ICU_IPW_SW_PATCH_VERSION_C != ICU_EMIOS_SW_PATCH_VERSION))
 #error "Software Version Numbers of Icu_Ipw.c and Icu_eMIOS.h are different"
#endif


/* Check if source file and Icu_Siu header file are of the same vendor */
#if (ICU_IPW_VENDOR_ID_C != ICU_SIU_VENDOR_ID)
    #error "Icu_Ipw.c and Icu_Siu.h have different vendor IDs"
#endif
    /* Check if source file and Icu_Siu header file are of the same Autosar version */
#if ((ICU_IPW_AR_RELEASE_MAJOR_VERSION_C != ICU_SIU_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_MINOR_VERSION_C != ICU_SIU_AR_RELEASE_MINOR_VERSION) || \
     (ICU_IPW_AR_RELEASE_REVISION_VERSION_C != ICU_SIU_AR_RELEASE_REVISION_VERSION))
 #error "AutoSar Version Numbers of Icu_Ipw.c and Icu_Siu.h are different"
#endif
/* Check if source file and Icu_Siu header file are of the same software version */
#if ((ICU_IPW_SW_MAJOR_VERSION_C != ICU_SIU_SW_MAJOR_VERSION) || \
     (ICU_IPW_SW_MINOR_VERSION_C != ICU_SIU_SW_MINOR_VERSION) || \
     (ICU_IPW_SW_PATCH_VERSION_C != ICU_SIU_SW_PATCH_VERSION))
 #error "Software Version Numbers of Icu_Ipw.c and Icu_Siu.h are different"
#endif
/*==================================================================================================
*                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/


/*==================================================================================================
*                                        LOCAL CONSTANTS
==================================================================================================*/


/*==================================================================================================
*                                        LOCAL VARIABLES
==================================================================================================*/

/*==================================================================================================
*                                        GLOBAL CONSTANTS
==================================================================================================*/


/*==================================================================================================
*                                        GLOBAL VARIABLES
==================================================================================================*/

/*==================================================================================================
*                                    LOCAL FUNCTION PROTOTYPES
==================================================================================================*/

/*==================================================================================================
*                                        LOCAL FUNCTIONS
==================================================================================================*/
#define ICU_START_SEC_CODE
/**
* @violates @ref ICU_IPW_C_REF_1 Directive 4.10, Precautions shall be taken in order to prevent the contents
* of a header file being included more than once.
*
* @violates @ref ICU_IPW_C_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/
#include "Icu_MemMap.h"
/*==================================================================================================
*                                        GLOBAL FUNCTIONS
==================================================================================================*/

 /**
 * @brief      Icu_Ipw_Init
 * @details    Initialize a hardware ICU channel
 *
 * @param[in]      hwChannel   - This index relates the Icu Channel number with the respective
 *                               global variable, depending on the measurement mode
 *                               Each kind of measurement mode has an array(s) in the ICU driver,
 *                               this index points to the corresponding variable within the ICU
 *                               channel
 * @param[in]      ParamValue  - contains the parameters to initialize the hardware channel
 * @param[in]      ChannelMode - The measurement mode of the channel
 *
 * @return void
 *
 * @pre        Icu_DeInit must be called before.
 *
 */
FUNC (void, ICU_CODE) Icu_Ipw_Init
(
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    /* eMIOS Channel Configuration */
    if (NULL_PTR != pIpConfig->peMiosIpConfig)
    {
        Icu_eMios_Init(pIpConfig->peMiosIpConfig);
    }

    /* External Interrupt Channel Configuration */
    if (NULL_PTR != pIpConfig->pSiuIpConfig)
    {
        Icu_Siu_Init(pIpConfig->pSiuIpConfig);
    }
}

 #if (ICU_DE_INIT_API == STD_ON)
/**
* @brief              Icu_Ipw_DeInit
* @details            De-initialize ICU hardware channel
*
* @param[in]          hwChannel - This index relates the Icu Channel number
*
* @return void
*
* @pre                Icu_Init must be called before.
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_DeInit
(
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    /* eMIOS Channel Configuration */
    if (NULL_PTR != pIpConfig->peMiosIpConfig)
    {
        Icu_eMios_DeInit(pIpConfig->peMiosIpConfig);
    }
    /* External Interrupt Channel Configuration */
    if (NULL_PTR != pIpConfig->pSiuIpConfig)
    {
        Icu_Siu_DeInit(pIpConfig->pSiuIpConfig);
    }
}
#endif /* ICU_DE_INIT_API == STD_ON */

#if (ICU_SET_MODE_API == STD_ON)
/**
* @brief      Icu_Ipw_SetSleepMode
* @details    Set sleep mode
*
* @param[in]      hwChannel - The index of ICU channel for current configuration structure
* @param[in]      active     - ICU channel is active during SLEEP mode (wakeup was enabled)
*
* @return void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_SetSleepMode
(
    VAR(Icu_ChannelType,                           AUTOMATIC) nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_SetSleepMode((Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel));
    }
    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;

        Icu_Siu_SetSleepMode((Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel));
    }
}


/**
* @brief      Icu_Ipw_SetNormalMode
* @details    Set normal mode
*
* @param[in]      hwChannel - The index of ICU channel for current configuration structure
*
* @return void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_SetNormalMode
(
    VAR(Icu_ChannelType,                           AUTOMATIC) nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_SetNormalMode((Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel));
    }
    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;

        Icu_Siu_SetNormalMode((Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel));
    }
}
#endif  /* ICU_SET_MODE_API */

/**
* @brief      Icu_Ipw_SetActivationCondition
* @details
*
* @param[in]      nChannelNumber     - The index of ICU channel for current configuration structure
* @param[in]      Activation         - the type of Activation for the ICU channel.
* @param[in]      Mode               - the measurement mode of the channel
*
* @return void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_SetActivationCondition
(
    VAR(Icu_ChannelType,            AUTOMATIC) nChannelNumber,
    VAR(Icu_ActivationType,         AUTOMATIC) Activation,
    VAR(Icu_MeasurementModeType,    AUTOMATIC) Mode,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;
    (void) Mode;

    /* eMIOS Channel Configuration */
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        switch (Activation)
        {
            case ICU_FALLING_EDGE:
            {
                Icu_eMios_SetActivationCondition
                (
                    (Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel),
                    EMIOS_FALLING_EDGE
                );
            }
            break;

            case ICU_RISING_EDGE:
            {
                Icu_eMios_SetActivationCondition
                (
                    (Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel),
                    EMIOS_RISING_EDGE
                );
            }
            break;

            case ICU_BOTH_EDGES:
            {
                Icu_eMios_SetActivationCondition
                (
                    (Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel),
                    EMIOS_BOTH_EDGES
                );
            }
            break;

            default:
            {
                /* no action */
            }
            break;
        }
    }
    /* External Interrupt Channel Configuration */
    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;
        switch (Activation)
        {
            case ICU_FALLING_EDGE:
            {
                Icu_Siu_SetActivationCondition
                (
                    (Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel),
                    SIU_FALLING_EDGE
                );
            }
            break;

            case ICU_RISING_EDGE:
            {
                Icu_Siu_SetActivationCondition
                (
                    (Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel),
                    SIU_RISING_EDGE
                );
            }
            break;

            case ICU_BOTH_EDGES:
            {
                Icu_Siu_SetActivationCondition
                (
                    (Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel),
                    SIU_BOTH_EDGES
                );
            }
            break;

            default:
            {
                /* no action */
            }
            break;
        }
    }

}

#if (ICU_GET_INPUT_STATE_API == STD_ON)
/**
* @brief      Icu_Ipw_GetInputState
* @details    Service that returns the state of the ICU driver
*
* @param[in]      nChannelNumber - The index of ICU channel for current configuration structure
*
* @return Icu_InputStateType
* @retval   ICU_ACTIVE          An active edge has been detected
* @retval   ICU_IDLE            No active edge has been detected since the cast call to
*                               Icu_Ipw_InitChannel or Icu_Ipw_GetInputState
*
*/
FUNC (Icu_InputStateType, ICU_CODE) Icu_Ipw_GetInputState
(
    VAR(Icu_ChannelType,                      AUTOMATIC) nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;
    VAR(Icu_InputStateType, AUTOMATIC) tempReturn = ICU_IDLE;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        if ((boolean)TRUE == Icu_eMios_GetInputState((Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel)))
        {
            tempReturn = ICU_ACTIVE;
        }
    }

    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;

        if ((boolean)TRUE == Icu_Siu_GetInputState((Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel)))
        {
            tempReturn = ICU_ACTIVE;
        }
    }
    return (tempReturn);
}
#endif  /* ICU_GET_INPUT_STATE_API */

#if (ICU_EDGE_DETECT_API == STD_ON)
/**
* @brief          Icu_Ipw_EnableEdgeDetection
* @details        Retrieve the number of edges
*
* @param[in]      hwChannel - The index of ICU channel for current configuration structure
* @return         void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_EnableEdgeDetection
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_EnableEdgeDetection((Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel));
    }
    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;

        Icu_Siu_EnableEdgeDetection((Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel));
    }
}
#endif /* ICU_EDGE_DETECT_API */


#if (ICU_EDGE_DETECT_API == STD_ON)
/**
* @brief      Icu_Ipw_DisableEdgeDetection
* @details    Retrieve the number of edges
*
* @param[in]      hwChannel - The index of ICU channel for current configuration structure
*
* @return         void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_DisableEdgeDetection
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_DisableEdgeDetection((Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel));
    }
    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;

        Icu_Siu_DisableEdgeDetection((Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(nHardwareChannel));
    }
}
#endif /* ICU_EDGE_DETECT_API */

#if (ICU_SIGNAL_MEASUREMENT_API == STD_ON)
/**
* @brief      Icu_Ipw_StartSignalMeasurement
* @details    Starts the signal measurement service
*
* @param[in]      hwChannel     - The index of ICU channel for current configuration structure
* @param[in]      StartEdge     - Activation edge of the signal measurement
* @param[in]      MeasProperty  - the property that will be measured on the channel
* @param[in]      bDmaSupport   - Indicate DMA support
* @param[in]      bWithoutInterrupt - Measurement of ICU signal property without using interrupt
* @return void
*
*/
FUNC (void, ICU_CODE) Icu_Ipw_StartSignalMeasurement
(
    VAR(Icu_ChannelType, AUTOMATIC)                             nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST)   pIpConfig,
    VAR(Icu_ParamType, AUTOMATIC)                               StartEdge,
    VAR(Icu_MeasurementSubModeType,  AUTOMATIC)                 MeasProperty,
    VAR(boolean, AUTOMATIC)                                     bDmaSupport
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    VAR(Icu_eMios_ActivationType,       AUTOMATIC)                 eMiosActivation = EMIOS_RISING_EDGE;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;
    VAR(boolean, AUTOMATIC) bWithoutInterrupt = (boolean)FALSE;

    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
      peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];

        /*Get eMios Hardware Channel */
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        bWithoutInterrupt = (boolean)peMiosChannelConfig->bSignalMeasure_WithoutInterrupt;
        /* Set Default Start Edge, signal can be start measured either by falling edge or
        rising edge */

        if ((uint32)ICU_FALLING_EDGE == StartEdge)
        {
            eMiosActivation = EMIOS_FALLING_EDGE;
        }
        else if ((uint32)ICU_RISING_EDGE == StartEdge)
        {
            eMiosActivation = EMIOS_RISING_EDGE;
        }
        else
        {
            eMiosActivation = EMIOS_BOTH_EDGES;
        }

        /* Start Signal Measurement */
        Icu_eMios_StartSignalMeasurement
        (
            (Icu_eMios_ChannelType)ICU_EMIOS_CHANNELS(nHardwareChannel),
            eMiosActivation,
            MeasProperty,
            (boolean)bDmaSupport,
            (boolean)bWithoutInterrupt
        );
    }
    else
    {
        /* no action */
    }
}
#endif  /* ICU_SIGNAL_MEASUREMENT_API */

#if (ICU_SIGNAL_MEASUREMENT_API == STD_ON)
FUNC (void, ICU_CODE) Icu_Ipw_StopSignalMeasurement
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;


    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_StopSignalMeasurement((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
}
#endif  /* ICU_SIGNAL_MEASUREMENT_API */

#if ((ICU_VALIDATE_PARAMS == STD_ON) && (ICU_GET_INPUT_LEVEL_API == STD_ON))
FUNC (Icu_ChannelType, ICU_CODE) Icu_Ipw_ValidateGetInputLevel
(
    VAR         (Icu_ChannelType,  AUTOMATIC)                 nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType, AUTOMATIC) nChannelInput;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    P2CONST(Icu_Siu_IpConfigType,       AUTOMATIC, ICU_APPL_CONST) pSiuIpChConfig;
    P2CONST(Icu_Siu_ChannelConfigType,  AUTOMATIC,ICU_APPL_CONST)  pSiuChannelConfig;

    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nChannelInput = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;
    }

    else
    {
        u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
        pSiuIpChConfig = pIpConfig->pSiuIpConfig;
        pSiuChannelConfig = &(*pSiuIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nChannelInput = (Icu_ChannelType)pSiuChannelConfig->nHwChannel;
    }
    return nChannelInput;
}
#endif /* (ICU_VALIDATE_PARAMS == STD_ON) && (ICU_GET_INPUT_LEVEL_API == STD_ON */

#if ((ICU_VALIDATE_GLOBAL_CALL == STD_ON) && ((ICU_GET_PULSE_WIDTH_API == STD_ON) && (ICU_SIGNAL_MEASUREMENT_API == STD_ON)))
FUNC (Std_ReturnType, ICU_CODE) Icu_Ipw_ValidateSignalMeasureWithoutInterrupt
(
    VAR         (Icu_ChannelType,  AUTOMATIC)                 nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    /* Variable to store the value returned by the function */
    VAR(Std_ReturnType, AUTOMATIC) Valid = (Std_ReturnType)E_OK;
    Valid = Icu_eMios_ValidateSignalMeasureWithoutInterrupt
          (
            (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig,
            pIpConfig->peMiosIpConfig
          );
    return Valid;
}
#endif /* (ICU_VALIDATE_PARAMS == STD_ON) && ((ICU_GET_PULSE_WIDTH_API == STD_ON) && (ICU_SIGNAL_MEASUREMENT_API == STD_ON))*/

#if ((ICU_SIGNALMEASUREMENT_USES_DMA == STD_ON) || (ICU_TIMESTAMP_USES_DMA == STD_ON))
FUNC(uint32, ICU_CODE)Icu_Ipw_GetStartAddress
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    VAR(uint32, AUTOMATIC) u32Saddress;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        u32Saddress =  Icu_eMios_GetStartAddress((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
        u32Saddress = 0U;
    }
    return (u32Saddress);
}
#endif

#if (ICU_TIMESTAMP_API == STD_ON)
FUNC(void, ICU_CODE) Icu_Ipw_StartTimestamp
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig,
    VAR(boolean,                              AUTOMATIC)      bDmaSupport
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_StartTimestamp((Icu_eMios_ChannelType)nHardwareChannel, (boolean)bDmaSupport);
    }
    else
    {
        /* no action */
    }
}

FUNC(void, ICU_CODE) Icu_Ipw_StopTimestamp
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_StopTimestamp((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
}
#endif  /* ICU_TIMESTAMP_API == STD_ON */

#if (ICU_EDGE_COUNT_API == STD_ON)
FUNC(void, ICU_CODE) Icu_Ipw_ResetEdgeCount
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_ResetEdgeCount((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
}

FUNC(void, ICU_CODE) Icu_Ipw_EnableEdgeCount
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_EnableEdgeCount((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
}

FUNC(void, ICU_CODE) Icu_Ipw_DisableEdgeCount
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        Icu_eMios_DisableEdgeCount((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
}

FUNC(Icu_EdgeNumberType, ICU_CODE) Icu_Ipw_GetEdgeNumbers
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_EdgeNumberType,             AUTOMATIC)                 EdgeNumber;
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*initialize the variable EdgeNumber */
    EdgeNumber = (Icu_EdgeNumberType)0U;
    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        EdgeNumber = Icu_eMios_GetEdgeNumbers((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
    return (EdgeNumber);
}
#endif  /* ICU_EDGE_COUNT_API == STD_ON */

#if ((ICU_EDGE_COUNT_API == STD_ON) || (ICU_TIMESTAMP_API == STD_ON) || \
     (ICU_GET_TIME_ELAPSED_API == STD_ON) || (ICU_GET_DUTY_CYCLE_VALUES_API == STD_ON))
/*
* @violates @ref ICU_IPW_C_REF_5 Advisory Rule 8.7, Functions and objects should not be defined with external linkage if
* they are referenced in only one translation unit.
*/
FUNC(boolean, ICU_CODE) Icu_Ipw_Get_Overflow
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(boolean,                        AUTOMATIC)                 bGetOverflow;
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*initialize the variable bGetOverflow */
    bGetOverflow = (boolean)FALSE;
    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        bGetOverflow = (boolean)Icu_eMios_GetOverflow((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
    return bGetOverflow;
}
#endif  /* ICU_EDGE_COUNT_API == STD_ON */

#if (ICU_GET_INPUT_LEVEL_API == STD_ON)
FUNC(Icu_LevelType, ICU_CODE) Icu_Ipw_GetInputLevel
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_LevelType,                  AUTOMATIC)                 InputLevel;
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

       /* @violates @ref ICU_IPW_C_REF_3 Required Rule 10.3, The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.*/
       /* @violates @ref ICU_IPW_C_REF_4 Advisory Rule 10.5, The value of an expression should not be cast to an inappropriate essential type.*/
        InputLevel = (Icu_LevelType)Icu_eMios_GetInputLevel((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        InputLevel = ICU_LEVEL_LOW;
    }
    return (InputLevel);
}
#endif   /* ICU_GET_INPUT_LEVEL_API == STD_ON */

#if ((ICU_CAPTURERGISTER_API == STD_ON) && ((ICU_SIGNAL_MEASUREMENT_API == STD_ON) || (ICU_TIMESTAMP_API == STD_ON)))
FUNC(Icu_ValueType, ICU_CODE) Icu_Ipw_GetCaptureRegisterValue
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ValueType,                  AUTOMATIC)                 CaptureRegisterValue;
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*initialize the variable CaptureRegisterValue */
    CaptureRegisterValue = (Icu_ValueType)0U;
    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    if (ICU_EMIOS_CHANNEL == (*pIpConfig->pIpChannelsConfig)[nChannelNumber].nChannelIp)
    {
        peMiosIpChConfig = pIpConfig->peMiosIpConfig;
        peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
        nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

        CaptureRegisterValue = (Icu_ValueType)Icu_eMios_GetCaptureRegisterValue((Icu_eMios_ChannelType)nHardwareChannel);
    }
    else
    {
        /* no action */
    }
    return (CaptureRegisterValue);
}
#endif  /* (ICU_CAPTURERGISTER_API == STD_ON) && ((ICU_SIGNAL_MEASUREMENT_API == STD_ON) || (ICU_TIMESTAMP_API == STD_ON)) */

#if (ICU_DUAL_CLOCK_MODE_API == STD_ON)
/*================================================================================================*/
/**
* @brief      This function changes the global prescaler.
* @details    This function sets the module prescalers based on the input mode.
*
* @param[in]  Icu_Ipw_GlobalConfiguration - The index of ICU channel for current
*                                            configuration structure
* @param[in]  Prescaler - Prescaler type ( Normal or Alternate )
*
* @return void
*/
/*================================================================================================*/
FUNC(void, ICU_CODE) Icu_Ipw_SetClockMode
(
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig,
    VAR(Icu_SelectPrescalerType,             AUTOMATIC) Prescaler
)
{
    /* Set ClockMode for eMios Channel */
    if (NULL_PTR != pIpConfig->peMiosIpConfig)
    {
        Icu_eMios_SetClockMode(
                                  pIpConfig->peMiosIpConfig,
                                  (uint32)Prescaler
                              );
    }

    /* Set ClockMode for Siu */
    if (NULL_PTR != pIpConfig->pSiuIpConfig)
    {
        Icu_Siu_SetClockMode(
                                  (Icu_Siu_GlobalConfigurationType)(pIpConfig->pSiuIpConfig->Icu_GlobalConfiguration),
                                  (uint32)Prescaler
                              );
    }
}
#endif /* ICU_DUAL_CLOCK_MODE_API */

#if ((ICU_GET_PULSE_WIDTH_API == STD_ON) && (ICU_SIGNAL_MEASUREMENT_API == STD_ON))
FUNC(void, ICU_CODE) Icu_Ipw_GetPulseWidth
(
    VAR(Icu_ChannelType,                      AUTOMATIC)      nChannelNumber,
    CONSTP2CONST(Icu_IpConfigType, AUTOMATIC, ICU_APPL_CONST) pIpConfig
)
{
    VAR(Icu_ChannelType,                AUTOMATIC)                 nHardwareChannel;
    VAR(uint8,                          AUTOMATIC)                 u8IdxChConfig;
    P2CONST(Icu_eMios_IpConfigType,     AUTOMATIC, ICU_APPL_CONST) peMiosIpChConfig;
    P2CONST(Icu_eMios_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST)  peMiosChannelConfig;

    /*Get eMios Hardware Channel */
    u8IdxChConfig = (*pIpConfig->pIpChannelsConfig)[nChannelNumber].u8IdxChannelConfig;
    peMiosIpChConfig = pIpConfig->peMiosIpConfig;
    peMiosChannelConfig = &(*peMiosIpChConfig->pChannelsConfig)[u8IdxChConfig];
    nHardwareChannel = (Icu_ChannelType)peMiosChannelConfig->nHwChannel;

    Icu_eMios_GetPulseWidth((Icu_eMios_ChannelType)nHardwareChannel);
}
#endif /* (ICU_GET_PULSE_WIDTH_API == STD_ON) && (ICU_SIGNAL_MEASUREMENT_API == STD_ON) */

#define ICU_STOP_SEC_CODE
/**
* @violates @ref ICU_IPW_C_REF_1 Directive 4.10, Precautions shall be taken in order to prevent the contents
* of a header file being included more than once.
*
* @violates @ref ICU_IPW_C_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/
#include "Icu_MemMap.h"

#ifdef __cplusplus
}
#endif
/** @} */
