/**
*     @file        Icu_Siu.c
*     @version 1.0.0
*
*     @brief   AUTOSAR Icu - SIU source file support for ICU driver.
*     @details SIU source file, containing the variables and functions that are exported by the SIU 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_SIU_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_SIU_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_SIU_C_REF_3
* Violates MISRA 2012 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type.
* The cast is used to access memory mapped registers.
*
* @section ICU_SIU_C_REF_4
* Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type.
* The cast is used to access memory mapped registers.
*
* @section ICU_SIU_C_REF_5
* Violates MISRA 2012 Required Rule 10.8, The value of a composite expression shall no be cast to a different essential type category or a wider essential type.
* The cast is used to access memory mapped registers.
*
* @section ICU_SIU_C_REF_6
* 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.
* Function used in interrupt reading a static variable. External linkage is needed to "export".
*
* @section ICU_SIU_C_REF_7
* Violates MISRA 2012 Advisory Rule 12.3, The comma operator should not be used.
*
*/

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

#include "Icu_Cfg.h"
#define USER_MODE_REG_PROT_ENABLED   ICU_ENABLE_USER_MODE_SUPPORT
#include "SilRegMacros.h"

#include "Icu_Reg_eSys_Siu.h"
#include "Icu_Siu.h"

#include "Icu_Ipw_Types.h"

/*==================================================================================================
 *                                  SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define ICU_SIU_VENDOR_ID_C         43
#define ICU_SIU_AR_RELEASE_MAJOR_VERSION_C  4
#define ICU_SIU_AR_RELEASE_MINOR_VERSION_C  3
#define ICU_SIU_AR_RELEASE_REVISION_VERSION_C  1
#define ICU_SIU_SW_MAJOR_VERSION_C  1
#define ICU_SIU_SW_MINOR_VERSION_C  0
#define ICU_SIU_SW_PATCH_VERSION_C  0

/*==================================================================================================
*                                       FILE VERSION CHECKS
==================================================================================================*/
/* Check if source file and Std_Types.h file are of the same Autosar version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION_C != STD_AR_RELEASE_MAJOR_VERSION) || \
         (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != STD_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Icu_Siu.c and Std_Types.h are different"
    #endif
#endif

#if (ICU_SIU_VENDOR_ID_C != ICU_VENDOR_ID_CFG)
    #error "Icu_Siu.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_SIU_AR_RELEASE_MAJOR_VERSION_C != ICU_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != ICU_AR_RELEASE_MINOR_VERSION_CFG) || \
     (ICU_SIU_AR_RELEASE_REVISION_VERSION_C != ICU_AR_RELEASE_REVISION_VERSION_CFG))
    #error "AutoSar Version Numbers of Icu_Cfg.h and Icu_Siu.c are different"
#endif
/* Check if source file and Icu_Cfg header file are of the same Software version */
#if ((ICU_SIU_SW_MAJOR_VERSION_C != ICU_SW_MAJOR_VERSION_CFG) || \
     (ICU_SIU_SW_MINOR_VERSION_C != ICU_SW_MINOR_VERSION_CFG) || \
     (ICU_SIU_SW_PATCH_VERSION_C != ICU_SW_PATCH_VERSION_CFG))
    #error "Software Version Numbers of Icu_Cfg.h and Icu_Siu.c are different"
#endif

/* Check if source file and Icu_Siu.h file are of the same vendor */
#if (ICU_SIU_VENDOR_ID_C != ICU_SIU_VENDOR_ID)
    #error "Icu_Siu.c and Icu_Siu.h have different vendor IDs"
#endif
/* Check if source file and Icu_Siu.h header file are of the same Autosar version */
#if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION_C != ICU_SIU_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != ICU_SIU_AR_RELEASE_MINOR_VERSION) || \
     (ICU_SIU_AR_RELEASE_REVISION_VERSION_C != ICU_SIU_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Icu_Siu.c and Icu_Siu.h are different"
#endif
/* Check if source file and Icu_Siu.h header file are of the same Software version */
#if ((ICU_SIU_SW_MAJOR_VERSION_C != ICU_SIU_SW_MAJOR_VERSION) || \
     (ICU_SIU_SW_MINOR_VERSION_C != ICU_SIU_SW_MINOR_VERSION) || \
     (ICU_SIU_SW_PATCH_VERSION_C != ICU_SIU_SW_PATCH_VERSION))
    #error "Software Version Numbers of Icu_Siu.c and Icu_Siu.h are different"
#endif

/* Check if source file and Icu_Reg_eSys_Siu.h file are of the same vendor */
#if (ICU_SIU_VENDOR_ID_C != SIU_VENDOR_ID_REG)
    #error "Icu_Siu.c and Icu_Reg_eSys_Siu.h have different vendor IDs"
#endif
#if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION_C != SIU_AR_RELEASE_MAJOR_VERSION_REG) || \
     (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != SIU_AR_RELEASE_MINOR_VERSION_REG) || \
     (ICU_SIU_AR_RELEASE_REVISION_VERSION_C != SIU_AR_RELEASE_REVISION_VERSION_REG))
    #error "AutoSar Version Numbers of Icu_Siu.c and Icu_Reg_eSys_Siu.h are different"
#endif
/* Check if source file and Icu_Reg_eSys_Siu.h header file are of the same Software version */
#if ((ICU_SIU_SW_MAJOR_VERSION_C != SIU_SW_MAJOR_VERSION_REG) || \
     (ICU_SIU_SW_MINOR_VERSION_C != SIU_SW_MINOR_VERSION_REG) || \
     (ICU_SIU_SW_PATCH_VERSION_C != SIU_SW_PATCH_VERSION_REG))
    #error "Software Version Numbers of Icu_Siu.c and Icu_Reg_eSys_Siu.h are different"
#endif

/* Check if source file and Icu_Ipw_Types.h file are of the same vendor */
#if (ICU_SIU_VENDOR_ID_C != ICU_IPW_TYPES_VENDOR_ID)
    #error "Icu_Siu.c and Icu_Ipw_Types.h have different vendor IDs"
#endif
/* Check if source file and Icu_Ipw_Types header file are of the same Autosar version */
#if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION_C != ICU_IPW_TYPES_AR_RELEASE_MAJOR_VERSION) || \
     (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != ICU_IPW_TYPES_AR_RELEASE_MINOR_VERSION) || \
     (ICU_SIU_AR_RELEASE_REVISION_VERSION_C != ICU_IPW_TYPES_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Icu_Siu.c and Icu_Ipw_Types.h are different"
#endif
/* Check if source file and Icu_Ipw_Types header file are of the same Software version */
#if ((ICU_SIU_SW_MAJOR_VERSION_C != ICU_IPW_TYPES_SW_MAJOR_VERSION) || \
     (ICU_SIU_SW_MINOR_VERSION_C != ICU_IPW_TYPES_SW_MINOR_VERSION) || \
     (ICU_SIU_SW_PATCH_VERSION_C != ICU_IPW_TYPES_SW_PATCH_VERSION))
    #error "Software Version Numbers of Icu_Siu.c and Icu_Ipw_Types.h are different"
#endif

/* Check if source file and SilRegMacros.h file are of the same Autosar version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION_C != SILREGMACROS_AR_RELEASE_MAJOR_VERSION) || \
         (ICU_SIU_AR_RELEASE_MINOR_VERSION_C != SILREGMACROS_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Icu_Siu.c and SilRegMacros.h are different"
    #endif
#endif
/*==================================================================================================
*                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

/*=================================================================================================
*                                       LOCAL MACROS
=================================================================================================*/

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

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

#define ICU_START_SEC_VAR_INIT_32
/**
* @violates @ref ICU_SIU_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_SIU_C_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/

#include "Icu_MemMap.h"

static VAR(uint32, ICU_VAR) Icu_Siu_u32ChInit = (uint32)0;

#define ICU_STOP_SEC_VAR_INIT_32
/**
* @violates @ref ICU_SIU_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_SIU_C_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/
#include "Icu_MemMap.h"
/*==================================================================================================
*                                        GLOBAL CONSTANTS
==================================================================================================*/


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

/*==================================================================================================
*                                    LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
#define ICU_START_SEC_CODE
/**
* @violates @ref ICU_SIU_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_SIU_C_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/
#include "Icu_MemMap.h"

#if ((ICU_SET_MODE_API == STD_ON) ||(ICU_EDGE_DETECT_API == STD_ON))
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Siu_EnableInterrupt(VAR(uint32, AUTOMATIC) u32ChannelMask);
#endif

LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Siu_DisableInterrupt(VAR(uint32, AUTOMATIC) u32ChannelMask);

/*==================================================================================================
                                       LOCAL FUNCTIONS
==================================================================================================*/

#if ((ICU_SET_MODE_API == STD_ON) ||(ICU_EDGE_DETECT_API == STD_ON))
/*================================================================================================*/
/**
* @brief      Icu driver function that enables the interrupt of SIU channel
* @details    This function enables SIU Channel Interrupt
*
* @param[in]  u32ChannelMask - Channel's Bit Mask
*
* @return void
*
*/
/*================================================================================================*/
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Siu_EnableInterrupt(VAR(uint32, AUTOMATIC) u32ChannelMask)
{
    SchM_Enter_Icu_ICU_EXCLUSIVE_AREA_09();
    {
        /* Enable interrupt */
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

        REG_BIT_SET32(ICU_SIU_DIRER_ADDR32, u32ChannelMask);

        /* Clear pending flag */
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

        REG_WRITE32(ICU_SIU_EISR_ADDR32, u32ChannelMask);
    }
    SchM_Exit_Icu_ICU_EXCLUSIVE_AREA_09();
}
#endif /*((ICU_SET_MODE_API == STD_ON) || (ICU_EDGE_DETECT_API == STD_ON))*/

/*================================================================================================*/
/**
* @brief      Icu driver function that disables the interrupt of SIU channel
* @details    This function disables SIU Channel Interrupt
*
* @param[in]  u32ChannelMask - Channel's Bit Mask
*
* @return void
*
*/
/*================================================================================================*/
LOCAL_INLINE FUNC (void, ICU_CODE) Icu_Siu_DisableInterrupt(VAR(uint32, AUTOMATIC) u32ChannelMask)
{
    SchM_Enter_Icu_ICU_EXCLUSIVE_AREA_10();
    {
        /* Disable interrupt */
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

        REG_BIT_CLEAR32(ICU_SIU_DIRER_ADDR32, u32ChannelMask);

        /* Clear pending flag */
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

        REG_WRITE32(ICU_SIU_EISR_ADDR32, u32ChannelMask);
    }
    SchM_Exit_Icu_ICU_EXCLUSIVE_AREA_10();
}



/*==================================================================================================
                                       GLOBAL FUNCTIONS
==================================================================================================*/
#if ((defined ICU_IRQ_CH_0_ISR_USED)  || (defined ICU_IRQ_CH_1_ISR_USED) \
    || (defined ICU_IRQ_CH_2_ISR_USED) || (defined ICU_IRQ_CH_3_ISR_USED) \
    || (defined ICU_IRQ_CH_4_ISR_USED) || (defined ICU_IRQ_CH_5_ISR_USED) \
    || (defined ICU_IRQ_CH_6_ISR_USED) || (defined ICU_IRQ_CH_7_ISR_USED) \
    || (defined ICU_IRQ_CH_8_ISR_USED) || (defined ICU_IRQ_CH_9_ISR_USED) \
    || (defined ICU_IRQ_CH_10_ISR_USED) || (defined ICU_IRQ_CH_11_ISR_USED) \
    || (defined ICU_IRQ_CH_12_ISR_USED) || (defined ICU_IRQ_CH_13_ISR_USED) \
    || (defined ICU_IRQ_CH_14_ISR_USED) || (defined ICU_IRQ_CH_15_ISR_USED))

/**
* @brief      Icu_Siu_GetChInit
* @details    Returns if the current channel was initialized or not
*
* @param[in]      Channel  - The index of ICU channel for current configuration structure
*
* @return         Channel state initialization
* @retval         TRUE  channel was initialized
* @retval         FALSE channel was not initialized
*
* @violates @ref ICU_SIU_C_REF_6 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_Siu_GetChInit(CONST(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    return ((Icu_Siu_u32ChInit  & (BIT0 << nHwChannel)) == (BIT0 << nHwChannel)) ? \
                                           (boolean)TRUE : (boolean)FALSE;
}
#endif

/*================================================================================================*/
/**
* @brief      Icu driver function that disables the interrupt of SIU channel
* @details    This function disables SIU Channel Interrupt
*              - Disables interrupt.
*              - Sets Interrupt filter enable register
*              - Sets Interrupt Filter Clock Prescaler Register
*              - Sets Activation Condition
*
* @param[in]  ParamValue IRQ Param value
* @param[in]  nHwChannel IRQ HW Channel
*
* @return void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_Init
(
    P2CONST(Icu_Siu_IpConfigType,      AUTOMATIC, ICU_APPL_CONST) pSiuIpConfig
)
{
    /* @brief Pointer to Siu channel specific configuration */
    P2CONST(Icu_Siu_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST) pSiuChannelConfig;

    /* logical channel */
    VAR(Icu_Siu_ChannelType, AUTOMATIC)   nCounter;
    VAR(Icu_Siu_ChannelType, AUTOMATIC)   nHwChannel;
    VAR(uint32,              AUTOMATIC)   u32ChannelMask;

    VAR(Icu_Siu_GlobalConfigurationType, AUTOMATIC) nGlobalConfig;
    nGlobalConfig = pSiuIpConfig->Icu_GlobalConfiguration;

    /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
    /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/
    REG_WRITE32(ICU_SIU_IDFR_ADDR32,(nGlobalConfig & ICU_SIU_IDER_DFL_MASK_U32));

    for (nCounter=0U; nCounter < pSiuIpConfig->nNumChannels; nCounter++)
    {
        /* only handle SIU channels */
        pSiuChannelConfig = &(*pSiuIpConfig->pChannelsConfig)[nCounter];
        u32ChannelMask = (uint32)0U;
        nHwChannel = (Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(pSiuChannelConfig->nHwChannel);
        u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32(nHwChannel);

        /* Disable IRQ Interrupt */
        Icu_Siu_DisableInterrupt(u32ChannelMask);

        /* Set Activation Condition */
        Icu_Siu_SetActivationCondition(
                                          nHwChannel,
                                          pSiuChannelConfig->nDefaultStartEdge
                                      );

        Icu_Siu_u32ChInit |= (uint32) (BIT0 << nHwChannel);
    }
}

/*================================================================================================*/
/**
* @brief      Driver function that de-initializes SIU hardware channel.
* @details    This function:
*              - Disables interrupt.
*              - Clears edge event enable registers
*              - Clears Interrupt Filter Enable Register
*              - Clears Interrupt Filter Clock Prescaler Register
*
* @param[in]  nHwChannel   - IRQ HW Channel
*
* @return void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_DeInit
(
    P2CONST(Icu_Siu_IpConfigType,      AUTOMATIC, ICU_APPL_CONST) pSiuIpConfig
)
{
    /* @brief Pointer to Siu channel specific configuration */
    P2CONST(Icu_Siu_ChannelConfigType,AUTOMATIC,ICU_APPL_CONST) pSiuChannelConfig;

    /* logical channel */
    VAR(Icu_Siu_ChannelType, AUTOMATIC)   nCounter;
    VAR(Icu_Siu_ChannelType, AUTOMATIC)   nHwChannel;
    VAR(uint32,              AUTOMATIC)   u32ChannelMask;

    SchM_Enter_Icu_ICU_EXCLUSIVE_AREA_11();
    {
        for (nCounter=0U; nCounter < pSiuIpConfig->nNumChannels; nCounter++)
        {
            /* only handle SIU channels */
            pSiuChannelConfig = &(*pSiuIpConfig->pChannelsConfig)[nCounter];
            u32ChannelMask = (uint32)0U;
            nHwChannel = (Icu_Siu_ChannelType)ICU_IRQ_CHANNELS(pSiuChannelConfig->nHwChannel);
            u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32(nHwChannel);

            /* Disable IRQ Interrupt */
            Icu_Siu_DisableInterrupt(u32ChannelMask);
            /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
            /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/
            REG_BIT_CLEAR32(ICU_SIU_IREER_ADDR32, u32ChannelMask);

            /* Clear Interrupt Filter Enable Register */
            /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
            /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

            REG_BIT_CLEAR32(ICU_SIU_IFEER_ADDR32, u32ChannelMask);

            /* Clear config of channel */
            Icu_Siu_u32ChInit &= (uint32)(~(BIT0 << nHwChannel));
        }
    }
    SchM_Exit_Icu_ICU_EXCLUSIVE_AREA_11();
    /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
    /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

    REG_WRITE32(ICU_SIU_IDFR_ADDR32, 0U);
}

#if (ICU_SET_MODE_API == STD_ON)
/*================================================================================================*/
/**
* @brief      Driver function that sets SIU hardware channel into SLEEP mode.
* @details    This function enables the interrupt if wakeup is enabled for corresponding SIU channel
*
* @param[in]  nHwChannel       - IRQ HW Channel
* @param[in]  WakeUpEnabled   - channel wakeup feature is enabled
*
* @return void
*
*/
/*================================================================================================*/

FUNC (void, ICU_CODE) Icu_Siu_SetSleepMode(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);

    /* Disable IRQ Interrupt */
    Icu_Siu_DisableInterrupt(u32ChannelMask);
}


/*================================================================================================*/
/**
* @brief      Driver function that sets SIU hardware channel into NORMAL mode.
* @details    This function enables the interrupt if Notification is enabled for corresponding
*             SIU channel
*
* @param[in]  nHwChannel           - IRQ HW Channel
* @param[in]  NotificationActive  - channel notification is activated
*
* @return void
*
*/
/*================================================================================================*/

FUNC (void, ICU_CODE) Icu_Siu_SetNormalMode(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);

    /* Enable IRQ Interrupt */
    Icu_Siu_EnableInterrupt(u32ChannelMask);
}
#endif  /* ICU_SET_MODE_API */


/*================================================================================================*/
/**
* @brief      Driver function that sets activation condition of SIU channel
* @details    This function enables the requested activation condition(rising, falling or
*             both edges) for corresponding SIU channels.
*
* @param[in]  nHwChannel -  Hardware channel
* @param[in]  Activation - Activation condition
*
* @return void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_SetActivationCondition(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel,
                                                     VAR(Icu_Siu_ActivationType, AUTOMATIC) Activation)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);

    SchM_Enter_Icu_ICU_EXCLUSIVE_AREA_12();
    {
        switch (Activation)
        {
            case SIU_RISING_EDGE:
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_SET32(ICU_SIU_IREER_ADDR32, u32ChannelMask);
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_CLEAR32(ICU_SIU_IFEER_ADDR32, u32ChannelMask);
            break;

            case SIU_FALLING_EDGE:
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_CLEAR32(ICU_SIU_IREER_ADDR32, u32ChannelMask);
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_SET32(ICU_SIU_IFEER_ADDR32, u32ChannelMask);
            break;

            default:
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_SET32(ICU_SIU_IREER_ADDR32, u32ChannelMask);
                /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
                /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

                REG_BIT_SET32(ICU_SIU_IFEER_ADDR32, u32ChannelMask);
            break;
        }
    }
    SchM_Exit_Icu_ICU_EXCLUSIVE_AREA_12();
}


#if (ICU_EDGE_DETECT_API == STD_ON)
/*================================================================================================*/
/**
* @brief      Icu_Siu_EnableEdgeDetection
* @details    This function enables the interrupt corresponding to the SIU channel.
*
* @param[in]  nHwChannel - IRQ HW Channel
*
* @return void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_EnableEdgeDetection(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);

    /* Enable IRQ Interrupt */
    Icu_Siu_EnableInterrupt(u32ChannelMask);
}
#endif /* ICU_EDGE_DETECT_API */


#if (ICU_EDGE_DETECT_API == STD_ON)
/*================================================================================================*/
/**
* @brief      Icu_Siu_DisableEdgeDetection
* @details    This function disables the interrupt corresponding to the SIU channel.
*
* @param[in]  nHwChannel - IRQ HW Channel
*
* @return void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_DisableEdgeDetection(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);

    /* Disable IRQ Interrupt */
    Icu_Siu_DisableInterrupt(u32ChannelMask);
}
#endif /* ICU_EDGE_DETECT_API */


#if (ICU_GET_INPUT_STATE_API == STD_ON)
/*================================================================================================*/
/**
* @brief      Icu driver function that gets the input state of SIU channel.
* @details    This function:
*             - Checks if interrupt flags for corresponding SIU channel is set then
*             it clears the interrupt flag and returns the value as true.
*
* @param[in]  nHwChannel - IRQ HW Channel
*
* @return     boolean
* @retval     true       channel is Active
* @retval     false      channel is Idle
*
*/
/*================================================================================================*/
FUNC (boolean, ICU_CODE) Icu_Siu_GetInputState(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel)
{
    CONST(uint32, ICU_CONST) u32ChannelMask = ICU_SIU_CHANNEL_MASK_U32((uint32)nHwChannel);
    VAR(boolean, AUTOMATIC) bStatus = (boolean)FALSE;
    /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
    /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/


    VAR(uint32, AUTOMATIC) u32RegSiuEISR  = REG_BIT_GET32(ICU_SIU_EISR_ADDR32, u32ChannelMask);
    /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
    /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

    VAR(uint32, AUTOMATIC) u32RegSiuDIRER = REG_BIT_GET32(ICU_SIU_DIRER_ADDR32, u32ChannelMask);

    /* Interrupt condition activated (ISR), interrupt not enabled (IRER) */
    if ((0x0U !=  u32RegSiuEISR) && (0x0U == u32RegSiuDIRER))
    {
        /* Clear IRQ Flag */
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/

        REG_WRITE32(ICU_SIU_EISR_ADDR32, u32ChannelMask);
        bStatus = (boolean)TRUE;
    }

    return bStatus;
}
#endif  /* ICU_GET_INPUT_STATE_API */

#if (ICU_DUAL_CLOCK_MODE_API == STD_ON)
/*================================================================================================*/
/**
* @brief      Icu driver function that sets the prescaler value of SIU channel.
* @details    This function:
*             - Sets channels prescaler value based on the input mode
*
* @param[in]  u8FilterPrescaler - digital filter prescaler value
*
* @return     void
*
*/
/*================================================================================================*/
FUNC (void, ICU_CODE) Icu_Siu_SetClockMode
(
    VAR(Icu_Siu_GlobalConfigurationType,   AUTOMATIC) nGlobalConfig,
    CONST(uint32,                          AUTOMATIC) Prescaler
)
{
    if(SIU_ICU_NORMAL_CLOCK_MODE == Prescaler)
    {
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/
        /* @violates @ref ICU_SIU_C_REF_5 Required Rule 10.8, The value of a composite expression shall no be cast to a different essential type category or a wider essential type.*/

        REG_WRITE32(ICU_SIU_IDFR_ADDR32, (nGlobalConfig & ICU_SIU_INT_FILTER_CLOCK_PRESCALER_GC_MASK) >> \
                                                                    ICU_SIU_INT_FILTER_CLOCK_PRESCALER_GC_SHIFT);
    }
    else
    {
        /* @violates @ref ICU_SIU_C_REF_3 Advisory Rule 11.4, A conversion should not be performed between a pointer to object and an integer type. */
        /* @violates @ref ICU_SIU_C_REF_4 Required Rule 11.6, A cast shall not be performed between pointer to void and an arithmetic type*/
        /* @violates @ref ICU_SIU_C_REF_5 Required Rule 10.8, The value of a composite expression shall no be cast to a different essential type category or a wider essential type.*/

        REG_WRITE32(ICU_SIU_IDFR_ADDR32, (nGlobalConfig & ICU_SIU_INT_ALTERNATE_FILTER_CLOCK_PRESCALER_GC_MASK) >> \
                                                                    ICU_SIU_INT_ALTERNATE_FILTER_CLOCK_PRESCALER_GC_SHIFT);
    }
 }
#endif

#define ICU_STOP_SEC_CODE
/**
* @violates @ref ICU_SIU_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_SIU_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
/** @} */

