/**
*     @file    Icu_Siu.h
*     @version 1.0.0
*
*     @brief   AUTOSAR Icu - SIU low level driver exported functions.
*     @details Interface between the high level driver (Autosar dependent) and the low level driver(platform dependent).
*
*     @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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef ICU_SIU_H
#define ICU_SIU_H

#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_H_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_H_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_H_REF_3
* Violates MISRA 2012 Advisory Directive 4.9, A function should be used in preference to a function-like macro
* where they are interchangeable.
* Function like macro are used to reduce code complexity.
*
* @section ICU_SIU_H_REF_4
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Define is/might be used in configuration.
*/

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

/*==================================================================================================
                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define ICU_SIU_VENDOR_ID            43
#define ICU_SIU_AR_RELEASE_MAJOR_VERSION     4
#define ICU_SIU_AR_RELEASE_MINOR_VERSION     3
#define ICU_SIU_AR_RELEASE_REVISION_VERSION     1
#define ICU_SIU_SW_MAJOR_VERSION     1
#define ICU_SIU_SW_MINOR_VERSION     0
#define ICU_SIU_SW_PATCH_VERSION     0

/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
/* Check if header file and Icu_Siu_Types.h file are of the same vendor */
#if (ICU_SIU_VENDOR_ID != ICU_SIU_TYPES_VENDOR_ID)
    #error "Icu_Siu.h and Icu_Siu_Types.h have different vendor IDs"
#endif
/* Check if header file and Icu_Siu_Types.h header file are of the same Autosar version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION != ICU_SIU_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         (ICU_SIU_AR_RELEASE_MINOR_VERSION != ICU_SIU_TYPES_AR_RELEASE_MINOR_VERSION) || \
         (ICU_SIU_AR_RELEASE_REVISION_VERSION != ICU_SIU_TYPES_AR_RELEASE_REVISION_VERSION))
        #error "AutoSar Version Numbers of Icu_Siu.h and Icu_Siu_Types.h are different"
    #endif
#endif
/* Check if header file and Icu_Siu_Types.h header file are of the same software version */
#if ((ICU_SIU_SW_MAJOR_VERSION != ICU_SIU_TYPES_SW_MAJOR_VERSION) || \
     (ICU_SIU_SW_MINOR_VERSION != ICU_SIU_TYPES_SW_MINOR_VERSION) || \
     (ICU_SIU_SW_PATCH_VERSION != ICU_SIU_TYPES_SW_PATCH_VERSION))
    #error "Software Version Numbers of Icu_Siu.h and Icu_Siu_Types.h are different"
#endif

/* Check if header file and Icu_Reg_eSys_Siu.h file are of the same vendor */
#if (ICU_SIU_VENDOR_ID != SIU_VENDOR_ID_REG)
    #error "Icu_Siu.h and Icu_Reg_eSys_Siu.h have different vendor IDs"
#endif
/* Check if header file and Icu_Reg_eSys_Siu.h header file are of the same Autosar version */
#if ((ICU_SIU_AR_RELEASE_MAJOR_VERSION != SIU_AR_RELEASE_MAJOR_VERSION_REG) || \
     (ICU_SIU_AR_RELEASE_MINOR_VERSION != SIU_AR_RELEASE_MINOR_VERSION_REG) || \
     (ICU_SIU_AR_RELEASE_REVISION_VERSION != SIU_AR_RELEASE_REVISION_VERSION_REG))
    #error "AutoSar Version Numbers of Icu_Siu.h and Icu_Reg_eSys_Siu.h are different"
#endif
/* Check if header file and Icu_Reg_eSys_Siu.h header file are of the same software version */
#if ((ICU_SIU_SW_MAJOR_VERSION != SIU_SW_MAJOR_VERSION_REG) || \
     (ICU_SIU_SW_MINOR_VERSION != SIU_SW_MINOR_VERSION_REG) || \
     (ICU_SIU_SW_PATCH_VERSION != SIU_SW_PATCH_VERSION_REG))
    #error "Software Version Numbers of Icu_Siu.h and Icu_Reg_eSys_Siu.h are different"
#endif

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

/*==================================================================================================
                                       DEFINES AND MACROS
==================================================================================================*/
/**
* @brief   ICU_SIU_IRQ_CHANNEL_MASK - used for masking IRQ Channels
* @details Beside IRQ Channels, SIU provides also NMI capabilities. In order to not alter NMI settings
         all the operations will be masked.
*/
#define ICU_SIU_IRQ_CHANNEL_MASK            ((uint32)0x0000FFFFU)

/**
* @brief   ICU_SIU_IRQ4_IRQ15_MASK_U32 - used for masking IRQ Channels 4 ..15
* @details In order to not alter NMI settings and channels IRQ0, IRQ1,IRQ2, IRQ3
*        all the operations will be masked.
* @violates @ref ICU_SIU_H_REF_4 Violates Advisory Rule 2.5, A project should not contain unused macro declarations.
*/
#define ICU_SIU_IRQ4_IRQ15_MASK_U32            ((uint32)0x0000FFF0)


/*
* @violates @ref ICU_SIU_H_REF_3 Advisory Directive 4.9, A function should be used in
* preference to a function-like  macro.
*/
#define ICU_SIU_CHANNEL_MASK_U32(nHwChannel)  (((uint32)BIT0 << (uint32)(nHwChannel))  & ICU_SIU_IRQ_CHANNEL_MASK)



/*==================================================================================================
*                                              ENUMS
==================================================================================================*/

/*==================================================================================================
*                                  STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                  GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

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

#include "Icu_MemMap.h"

#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
*/
FUNC(boolean, ICU_CODE) Icu_Siu_GetChInit(CONST(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);
#endif

/**
* @brief      Icu_Siu_Init
* @details    Initialize the ICU Channel
* @param[in]  ParamValue
* @param[in]  nHwChannel - IRQ HW Channel
*/
FUNC (void, ICU_CODE) Icu_Siu_Init
(
    P2CONST(Icu_Siu_IpConfigType,      AUTOMATIC, ICU_APPL_CONST) pSiuIpConfig
);

/**
* @brief      Icu_Siu_DeInit
* @details    Deinitialize the ICU Channel
* @param[in]  nHwChannel   - IRQ HW Channel
*/
FUNC (void, ICU_CODE) Icu_Siu_DeInit
(
    P2CONST(Icu_Siu_IpConfigType,      AUTOMATIC, ICU_APPL_CONST) pSiuIpConfig
);
#if (ICU_SET_MODE_API == STD_ON)
/**
* @brief      Icu_Siu_SetSleepMode
* @details    Sets the ICU Channel mode
* @param[in]  nHwChannel      - IRQ HW Channel
* @param[in]  WakeUpEnabled  - channel wakeup feature is enabled
*/
FUNC (void, ICU_CODE) Icu_Siu_SetSleepMode(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);

/**
* @brief      Icu_Siu_SetNormalMode
* @details    Sets the ICU channel to normal mode
* @param[in]  nHwChannel   - IRQ HW Channel
* @param[in]  NotificationActive          - channel notification is activated
*/
FUNC (void, ICU_CODE) Icu_Siu_SetNormalMode(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);
#endif  /* ICU_SET_MODE_API  */

/**
* @brief      Icu_Siu_SetActivationCondition
* @details    Set the activation condition for the given SIU IRQ Channel
* @param[in]  nHwChannel   - IRQ HW Channel
* @param[in]  Activation       - activation condition
*/
FUNC (void, ICU_CODE) Icu_Siu_SetActivationCondition(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel,
                                                     VAR(Icu_Siu_ActivationType, AUTOMATIC) Activation);

#if (ICU_EDGE_DETECT_API == STD_ON)
FUNC (void, ICU_CODE) Icu_Siu_EnableEdgeDetection(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);
FUNC (void, ICU_CODE) Icu_Siu_DisableEdgeDetection(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);
#endif /* ICU_EDGE_DETECT_API */


#if (ICU_GET_INPUT_STATE_API == STD_ON)
/**
* @brief      Icu_Siu_GetInputState
* @details    Gets the input state of ICU hardware channel
* @param[in]  nHwChannel - IRQ HW Channel
* @retval     ICU_ACTIVE - Icu_InputStateType
* @retval     ICU_IDLE   - Icu_InputStateType
*/
FUNC (boolean, ICU_CODE) Icu_Siu_GetInputState(VAR(Icu_Siu_ChannelType, AUTOMATIC) nHwChannel);
#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    Sets channels prescaler value based on the input mode
* @param[in]  u8FilterPrescaler - digital filter prescaler value
*/
 FUNC (void, ICU_CODE) Icu_Siu_SetClockMode
 (
    VAR(Icu_Siu_GlobalConfigurationType,   AUTOMATIC) nGlobalConfig,
    CONST(uint32,                          AUTOMATIC) Prescaler
 );

#endif  /* ICU_DUAL_CLOCK_MODE_API */

#define ICU_STOP_SEC_CODE
/**
* @violates @ref ICU_SIU_H_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_H_REF_2 Advisory Rule 20.1, #include directives should only be preceded by
* preprocessor directives or comments.
*/
#include "Icu_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif  /* ICU_SIU_H */
/** @} */
