/**
*   @file           Gpt_eMios_Irq.c
*   @version        1.0.0
*
*   @brief          AUTOSAR Gpt - eMios interrupt handler driver source file.
*   @details        eMios interrupt handling routines.
*
*   @addtogroup     GPT_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : eMios_Stm_Pit
*   Dependencies         : none
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : 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 GPT_EMIOS_IRQ_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 GPT_EMIOS_IRQ_C_REF_2
*     Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed between pointer to void
*     and an arithmetic type.
*     This macro computes the address of any register by using the hardware offset of the controller.
*     The address calculated as an unsigned INT is passed to a macro for initializing the pointer 
*     with that address
*
* @section GPT_EMIOS_IRQ_C_REF_3
*     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.
*
* @section GPT_EMIOS_IRQ_C_REF_4
*     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 GPT_EMIOS_IRQ_C_REF_5
*     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 GPT_EMIOS_IRQ_C_REF_6
*     Violates MISRA 2012 Required Rule 10.8, The value of a composite expression shall not be cast
*     to a different essential type or a wider essential type.
*     The cast is used to access memory mapped registers.
*
*/
/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Gpt_eMios_Irq.h"
#include "Gpt_Ipw_Irq.h"
#include "Reg_eSys_eMios.h"

#ifdef GPT_ENABLE_USER_MODE_SUPPORT
   #define USER_MODE_REG_PROT_ENABLED   GPT_ENABLE_USER_MODE_SUPPORT
   #include "RegLockMacros.h"
#endif

#include "SilRegMacros.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define GPT_EMIOS_IRQ_VENDOR_ID_C                       43

#define GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION_C        4
#define GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION_C        3
#define GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION_C     1
#define GPT_EMIOS_IRQ_SW_MAJOR_VERSION_C                1
#define GPT_EMIOS_IRQ_SW_MINOR_VERSION_C                0
#define GPT_EMIOS_IRQ_SW_PATCH_VERSION_C                0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/

/* Check if current file and Gpt_eMios_Irq.h header file are of the same vendor */
#if (GPT_EMIOS_IRQ_VENDOR_ID_C != GPT_EMIOS_IRQ_VENDOR_ID)
    #error "Gpt_eMios_Irq.c and Gpt_eMios_Irq.h have different vendor ids"
#endif

/* Check if source file and Gpt_eMios_Irq.h are of the same Autosar version */
#if ((GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION_C    != GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION_C    != GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION_C != GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Gpt_eMios_Irq.c and Gpt_eMios_Irq.h are different"
#endif

/* Check if source file and Gpt_eMios_Irq.h are of the same software version */
#if ((GPT_EMIOS_IRQ_SW_MAJOR_VERSION_C != GPT_EMIOS_IRQ_SW_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_MINOR_VERSION_C != GPT_EMIOS_IRQ_SW_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_PATCH_VERSION_C != GPT_EMIOS_IRQ_SW_PATCH_VERSION))
    #error "Software Version Numbers of Gpt_eMios_Irq.c and Gpt_eMios_Irq.h are different"
#endif

/* Check if current file and Reg_eSys_eMios.h file are of the same vendor */
#if (GPT_EMIOS_IRQ_VENDOR_ID_C != REG_ESYS_EMIOS_VENDOR_ID)
    #error "Gpt_eMios_Irq.c and Reg_eSys_eMios.h have different vendor ids"
#endif
/* Check if source file and Reg_eSys_eMios.h file are of the same Autosar version */
#if ((GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION_C    != REG_ESYS_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION_C    != REG_ESYS_EMIOS_AR_RELEASE_MINOR_VERSION)|| \
     (GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Gpt_eMios_Irq.c and Reg_eSys_eMios.h are different"
#endif

/* Check if source file and Reg_eSys_eMios.h file are of the same software version */
#if ((GPT_EMIOS_IRQ_SW_MAJOR_VERSION_C != REG_ESYS_EMIOS_SW_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_MINOR_VERSION_C != REG_ESYS_EMIOS_SW_MINOR_VERSION)|| \
     (GPT_EMIOS_IRQ_SW_PATCH_VERSION_C != REG_ESYS_EMIOS_SW_PATCH_VERSION))
    #error "Software Version Numbers of Gpt_eMios_Irq.c and Reg_eSys_eMios.h are different"
#endif

/* Check if source file and SilRegMacros.h are of the same vendor */
#if (GPT_EMIOS_IRQ_VENDOR_ID_C != SILREGMACROS_VENDOR_ID)
    #error "Gpt_eMios_Irq.c and SilRegMacros.h have different vendor ids"
#endif

/* Check if source file and SilRegMacros.h are of the same Autosar version */
#if ((GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION_C    != SILREGMACROS_AR_RELEASE_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION_C    != SILREGMACROS_AR_RELEASE_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION_C != SILREGMACROS_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Gpt_eMios_Irq.c and SilRegMacros.h are different"
#endif

/* Check if source file and SilRegMacros.h are of the same software version */
#if ((GPT_EMIOS_IRQ_SW_MAJOR_VERSION_C != SILREGMACROS_SW_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_MINOR_VERSION_C != SILREGMACROS_SW_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_PATCH_VERSION_C != SILREGMACROS_SW_PATCH_VERSION))
    #error "Software Version Numbers of Gpt_eMios_Irq.c and SilRegMacros.h are different"
#endif

#if (GPT_EMIOS_IRQ_VENDOR_ID_C != GPT_IPW_IRQ_VENDOR_ID)
    #error "Gpt_eMios_Irq.c and Gpt_Ipw_Irq.h have different vendor ids"
#endif
/* Check if source file and Gpt header file are of the same Autosar version */
#if ((GPT_EMIOS_IRQ_AR_RELEASE_MAJOR_VERSION_C != GPT_IPW_IRQ_AR_RELEASE_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_MINOR_VERSION_C != GPT_IPW_IRQ_AR_RELEASE_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_AR_RELEASE_REVISION_VERSION_C != GPT_IPW_IRQ_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Gpt_eMios_Irq.c and Gpt_Ipw_Irq.h are different"
#endif
/* Check if source file and GPT header file are of the same Software version */
#if ((GPT_EMIOS_IRQ_SW_MAJOR_VERSION_C != GPT_IPW_IRQ_SW_MAJOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_MINOR_VERSION_C != GPT_IPW_IRQ_SW_MINOR_VERSION) || \
     (GPT_EMIOS_IRQ_SW_PATCH_VERSION_C != GPT_IPW_IRQ_SW_PATCH_VERSION) )
    #error "Software Version Numbers of Gpt_eMios_Irq.c and Gpt_Ipw_Irq.h are different"
#endif
/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

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

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

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

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

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

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

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

/*==================================================================================================
*                                       GLOBAL FUNCTIONS
==================================================================================================*/
#define GPT_START_SEC_CODE
/** @violates @ref GPT_EMIOS_IRQ_C_REF_1 MISRA 2012 Required Directive 4.10, the contents of a header 
*   file being included more than once.*/
#include "Gpt_MemMap.h"

#if (GPT_EMIOS_USED == STD_ON)
/**
* @brief   Driver routine to process all the interrupts of eMios.
* @details Non-AutoSar support function used by interrupt service routines to call notification
*          functions if provided and enabled
*
* @param[in]     u8HwChannel      hardware channel index
*
* @violates @ref GPT_EMIOS_IRQ_C_REF_3 MISRA 2012  Advisory Rule 8.7, These functions represent the API 
*   of the driver. External linkage is needed to "export" the API.
*
* @implements  Gpt_eMios_ProcessCommonInterrupt_Activity
*/

FUNC(void, GPT_CODE) Gpt_eMios_ProcessCommonInterrupt (VAR(uint8, AUTOMATIC) u8HwChannel)
{
    VAR(uint8, AUTOMATIC) u8ModuleIdx;   /**< @brief assigned eMios HW module  index */
    VAR(uint8, AUTOMATIC) u8ChannelIdx;  /**< @brief assigned eMios HW channel index */
    VAR(uint32,AUTOMATIC) u32Temp1;
    VAR(uint32,AUTOMATIC) u32Temp2;

    u8ModuleIdx  = (uint8)EMIOS_MODULE_INDEX_U8(u8HwChannel);
    u8ChannelIdx = (uint8)EMIOS_CHANNEL_INDEX_U8(u8HwChannel);
    
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_2 MISRA 2012  Required Rule 11.6, This macro computes the address
    *   of any register by using the hardware offset of the controller.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_5 MISRA 2012 Advisory Rule 11.4, The cast is used to access
    *   memory mapped registers.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_6 MISRA 2012 Advisory Rule 10.8, The cast is used to access
    *   memory mapped registers.*/
    u32Temp1 = REG_READ32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx));
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_2 MISRA 2012  Required Rule 11.6, This macro computes the address
    *   of any register by using the hardware offset of the controller.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_5 MISRA 2012 Advisory Rule 11.4, The cast is used to access
    *   memory mapped registers.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_6 MISRA 2012 Advisory Rule 10.8, The cast is used to access
    *   memory mapped registers.*/
    u32Temp2 = REG_READ32(EMIOS_CCR_ADDR32(u8ModuleIdx, u8ChannelIdx));

    /* Check for spurious interrupts */
    if ((((uint32)CSR_FLAG_MASK_U32 & u32Temp1) == (uint32)CSR_FLAG_MASK_U32)
       && (((uint32)CCR_FEN_MASK_U32 & u32Temp2) == (uint32)CCR_FEN_MASK_U32))
    {
        /* Call GPT upper layer handler */
        Gpt_Ipw_ProcessCommonInterrupt(u8ChannelIdx, (uint8)GPT_EMIOS_MODULE + (uint8)((uint8)GPT_EMIOS_CHANNELS_PER_MODULE_U8 * u8ModuleIdx));
    }

    /* Clear interrupt flag */
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_2 MISRA 2012  Required Rule 11.6, This macro computes the address
    *   of any register by using the hardware offset of the controller.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_5 MISRA 2012 Advisory Rule 11.4, The cast is used to access
    *   memory mapped registers.*/
    /** @violates @ref GPT_EMIOS_IRQ_C_REF_6 MISRA 2012 Advisory Rule 10.8, The cast is used to access
    *   memory mapped registers.*/
    REG_WRITE32(EMIOS_CSR_ADDR32(u8ModuleIdx, u8ChannelIdx), CSR_FLAG_MASK_U32);
}
#endif /*GPT_EMIOS_USED == STD_ON*/

#define GPT_STOP_SEC_CODE
/** @violates @ref GPT_EMIOS_IRQ_C_REF_1 MISRA 2012 Required Directive 4.10, the contents of a header 
*   file being included more than once.*/
/** @violates @ref GPT_EMIOS_IRQ_C_REF_4 MISRA 2012 Advisory Rule 20.1, <MA>_MemMap.h is included
*   after each section define in order to set the current memory section as defined by AUTOSAR.*/
#include "Gpt_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */
