/**
*   @file    Gpt_Cfg.h
*   
*   @version 1.0.0
*
*   @brief   AUTOSAR Gpt  - Gpt driver configuration header file.
*   @details GPT driver header file, containing C and XPath constructs for generating Gpt
*            configuration header file.
*
*   @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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef GPT_CFG_H
#define GPT_CFG_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 GPT_CFG_H_REF_1
*     Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
*     Macros that are in <MDL>.h or <MDL>_Cfg.h… that are needed for the client (and are used only 
*     in tests)
*
* @section GPT_CFG_H_REF_2
*     Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its
*     identifier only appears in a single function.
*     This violation is due to exporting the externally configured initialization structure used
*     by the "<MA>_Init" function.
**/
/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
[!NOCODE!][!//
[!INCLUDE "Gpt_VersionCheck_Inc.m"!][!//
[!ENDNOCODE!][!//

#include "Mcal.h"

[!NOCODE!][!//
[!VAR "GptDisableDemReport" = "0"!]
[!IF "node:exists(GptDemEventParameterRefs)"!]
    [!IF "GptDriverConfiguration/GptDisableDemReportErrorStatus = 'true'"!]
    [!VAR "GptDisableDemReport" = "1"!]
  [!ENDIF!]
[!ELSE!]
  [!VAR "GptDisableDemReport" = "1"!]
[!ENDIF!]
[!IF "$GptDisableDemReport = 0"!]
[!CODE!][!//
#include "Dem.h"
[!ENDCODE!][!//
[!ENDIF!]
[!ENDNOCODE!][!//
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/




#define GPT_VENDOR_ID_CFG                    43
#define GPT_AR_RELEASE_MAJOR_VERSION_CFG     4
#define GPT_AR_RELEASE_MINOR_VERSION_CFG     3
#define GPT_AR_RELEASE_REVISION_VERSION_CFG  1
#define GPT_SW_MAJOR_VERSION_CFG             1
#define GPT_SW_MINOR_VERSION_CFG             0
#define GPT_SW_PATCH_VERSION_CFG             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
     /* Check if this header file and Mcal.h file are of the same Autosar version */
    #if ((GPT_AR_RELEASE_MAJOR_VERSION_CFG != MCAL_AR_RELEASE_MAJOR_VERSION) || \
         (GPT_AR_RELEASE_MINOR_VERSION_CFG != MCAL_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Gpt_Cfg.h and Mcal.h are different"
    #endif

[!NOCODE!]
    [!IF "$GptDisableDemReport = 0"!]
        [!CODE!][!//
            /* Check if source file and Dem header file are of the same version */
            #if ((GPT_AR_RELEASE_MAJOR_VERSION_CFG != DEM_AR_RELEASE_MAJOR_VERSION) || \
                (GPT_AR_RELEASE_MINOR_VERSION_CFG != DEM_AR_RELEASE_MINOR_VERSION) \
                )
                #error "AutoSar Version Numbers of Gpt_Cfg.h and Dem.h are different"
            #endif
        [!ENDCODE!][!//
    [!ENDIF!][!//
[!ENDNOCODE!][!//
#endif
/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/

/**
* @brief Gpt Dev error detect switch
*
*/
#define GPT_DEV_ERROR_DETECT ([!IF "GptDriverConfiguration/GptDevErrorDetect"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief Report Wakeup Source switch
*/
#define GPT_REPORT_WAKEUP_SOURCE ([!IF "GptDriverConfiguration/GptReportWakeupSource"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_VERSION_INFO_API switch
*
*/
#define GPT_VERSION_INFO_API ([!IF "GptConfigurationOfOptApiServices/GptVersionInfoApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_DEINIT_API switch
*
*/
#define GPT_DEINIT_API ([!IF "GptConfigurationOfOptApiServices/GptDeinitApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_TIME_ELAPSED_API switch
*
*/
#define GPT_TIME_ELAPSED_API ([!IF "GptConfigurationOfOptApiServices/GptTimeElapsedApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_TIME_REMAINING_API switch
*
*/
#define GPT_TIME_REMAINING_API ([!IF "GptConfigurationOfOptApiServices/GptTimeRemainingApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_ENABLE_DISABLE_NOTIFICATION_API switch
*
*/
#define GPT_ENABLE_DISABLE_NOTIFICATION_API ([!IF "GptConfigurationOfOptApiServices/GptEnableDisableNotificationApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief GPT_WAKEUP_FUNCTIONALITY_API switch
*/
#define GPT_WAKEUP_FUNCTIONALITY_API ([!IF "GptConfigurationOfOptApiServices/GptWakeupFunctionalityApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief Enable/disable support for changing timeout value during timer running
*/
#define GPT_CHANGE_NEXT_TIMEOUT_VALUE ([!IF "GptAutosarExt/GptChangeNextTimeoutValueApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief Enable/disable API for Dual Mode support.
*/
#define GPT_SET_CLOCK_MODE ([!IF "GptAutosarExt/GptEnableDualClockMode"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief Enable/disable API for Chain Mode.
*/
#define GPT_CHAIN_MODE ([!IF "GptAutosarExt/ChainModeApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @brief Support Clock Source Selection for STM Timers
*/
#define GPT_STM_ENABLECLOCKSWITCH   (STD_OFF)

/**
* @brief Support for User mode.
*        If this parameter has been configured to 'TRUE' the GPT driver code can be executed from both supervisor and user mode.
*/
#define GPT_ENABLE_USER_MODE_SUPPORT    ([!IF "GptAutosarExt/GptEnableUserModeSupport"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

#ifndef MCAL_ENABLE_USER_MODE_SUPPORT
 #ifdef GPT_ENABLE_USER_MODE_SUPPORT
  #if (STD_ON == GPT_ENABLE_USER_MODE_SUPPORT)
   #error MCAL_ENABLE_USER_MODE_SUPPORT is not enabled. For running Gpt in user mode the MCAL_ENABLE_USER_MODE_SUPPORT needs to be defined
  #endif /* (STD_ON == GPT_ENABLE_USER_MODE_SUPPORT) */
 #endif /* ifdef GPT_ENABLE_USER_MODE_SUPPORT*/
#endif /* ifndef MCAL_ENABLE_USER_MODE_SUPPORT */

/**
* @brief GPT_PREDEFTIMER_FUNCTIONALITY_API switch
*/
#define GPT_PREDEFTIMER_FUNCTIONALITY_API ([!IF "GptConfigurationOfOptApiServices/GptPredefTimerFunctionalityApi"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

[!CODE!][!//
    /* Gpt Pre Compile Switch */
    [!IF "(IMPLEMENTATION_CONFIG_VARIANT !='VariantPostBuild' and (variant:size()<=1))"!]
        #define GPT_PRECOMPILE_SUPPORT (STD_ON)
    [!ELSE!]
        #define GPT_PRECOMPILE_SUPPORT (STD_OFF)
    [!ENDIF!]
[!ENDCODE!][!//

[!NOCODE!][!//
    [!VAR "MacEmiosUsed"="0"!]
    [!VAR "MacStmUsed"="0"!]
    [!VAR "MacPitUsed"="0"!]
    [!VAR "MacPitRtiUsed"="0"!]
        // Loop on all channels inside the same Configuration Set
        [!LOOP "GptHwConfiguration/*"!][!//
            [!IF "node:value(GptChannelIsUsed) = 'true' and contains(GptIsrHwId, 'EMIOS')"!][!//
                [!VAR "MacEmiosUsed"="1"!]
            [!ELSEIF "node:value(GptChannelIsUsed) = 'true' and contains(GptIsrHwId, 'STM')"!][!//
                [!VAR "MacStmUsed"="1"!]
            [!ELSEIF "node:value(GptChannelIsUsed) = 'true' and contains(GptIsrHwId, 'PIT') and not(contains(GptIsrHwId, 'RTI'))"!][!//
                [!VAR "MacPitUsed"="1"!]
            [!ELSEIF "node:value(GptChannelIsUsed) = 'true' and contains(GptIsrHwId, 'RTI')"!][!//
                [!VAR "MacPitRtiUsed"="1"!]
                [!VAR "MacPitUsed"="1"!]            
            [!ENDIF!][!//
        [!ENDLOOP!][!//
        [!LOOP "GptPredefTimerConfiguration/*"!][!//
            [!IF "contains(GptPredefTimer_1us_16Bit/GptHwChannel, 'STM')"!][!//
                [!VAR "MacStmUsed"="1"!]
            [!ELSEIF "contains(GptPredefTimer_1us_16Bit/GptHwChannel, 'EMIOS')"!][!//
                [!VAR "MacEmiosUsed"="1"!]
            [!ENDIF!][!//
            [!IF "contains(GptPredefTimer_1us_24Bit/GptHwChannel, 'STM')"!][!//
                [!VAR "MacStmUsed"="1"!]
            [!ENDIF!][!//
            [!IF "contains(GptPredefTimer_1us_32Bit/GptHwChannel, 'STM')"!][!//
                [!VAR "MacStmUsed"="1"!]
            [!ENDIF!][!//
            [!IF "contains(GptPredefTimer_100us_32Bit/GptHwChannel, 'STM')"!][!//
                [!VAR "MacStmUsed"="1"!]
            [!ENDIF!][!//
        [!ENDLOOP!][!//
[!ENDNOCODE!][!//

/**
* @brief These defines indicate that at least one channel from each module is used in all configurations.
*/
#define GPT_EMIOS_USED ([!IF "$MacEmiosUsed=1"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])
#define GPT_STM_USED ([!IF "$MacStmUsed=1"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])
#define GPT_PIT_USED ([!IF "$MacPitUsed=1"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_PIT_RTI_USED ([!IF "$MacPitRtiUsed=1"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!])

/**
* @{
* @brief Symbolic names of channels
*/
[!VAR "AlreadyParsedNames"!][!ENDVAR!][!//
[!LOOP "GptChannelConfigSet/GptChannelConfiguration/*"!]
    [!IF "contains($AlreadyParsedNames, concat(node:name(.),'|')) = false()"!][!//
        /** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
        #define GptConf_GptChannelConfiguration_[!"node:name(.)"!]  ([!"GptChannelId"!]U)
        [!VAR "AlreadyParsedNames"="concat($AlreadyParsedNames,node:name(.),'|')"!][!//
    [!ENDIF!]
[!ENDLOOP!]
/*@}*/

/**
* @brief This define is a reserved logical channel name representing a not existing/configured
*        hardware channel.
*
*/
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_CHN_NOT_USED    (255U)

/**
* @{
* @brief IRQ Defines for each channel used
*/
[!NOCODE!][!//
    [!VAR "AlreadyParsedModule"!][!ENDVAR!][!//
    [!LOOP "GptHwConfiguration/*"!][!//
        [!IF "(GptChannelIsUsed = 'true') and (GptIsrEnable = 'true')"!][!//
            [!CODE!][!//
            [!IF "contains(GptIsrHwId,"EMIOS") or contains(GptIsrHwId,"PIT") or contains(GptIsrHwId,"STM_0_CH_0")"!][!//
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
                #define GPT_[!"GptIsrHwId"!]_ISR_USED
            [!ENDIF!][!//        
            [!ENDCODE!][!//
        [!ENDIF!]//
    [!ENDLOOP!][!//
[!ENDNOCODE!][!//
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
    #define GPT_STM_ISR_1_SHARED   

/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_PIT_MODULE_SINGLE_INTERRUPT [!IF "ecu:get('Gpt.GptConfig.Gpt_PIT_ModuleSingleInterrupt')='STD_ON'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!]
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_STM_MODULE_SINGLE_INTERRUPT [!IF "ecu:get('Gpt.GptConfig.Gpt_STM_ModuleSingleInterrupt')='STD_ON'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!]

[!NOCODE!][!//
    [!INCLUDE "Gpt_PluginMacros.m"!]
[!ENDNOCODE!][!//

[!NOCODE!]
[!//PIT and STM channels have a generic FreezeEnable bit. Check that FreezeEnable is consistent.
[!FOR "Index" = "0" TO "num:i(ecu:list('Gpt.Num_Stm_Hw_Modules'))-num:i(1)"!]
    [!CALL "CheckFreeze","ModuleType"="concat(string('STM_'),num:i($Index))"!]
[!ENDFOR!]
[!FOR "Index" = "0" TO "num:i(ecu:list('Gpt.Num_Pit_Hw_Modules'))-num:i(1)"!][!//
    [!CALL "CheckFreeze","ModuleType"="concat(string('PIT_'),num:i($Index))"!][!//
[!ENDFOR!][!//
[!ENDNOCODE!]

/**
* @brief The maxiumum number of HW channels. This is used to allocate memory space for channel runtime info.
*/
#define GPT_HW_CHANNEL_NUM   ([!"num:i(count(GptChannelConfigSet/GptChannelConfiguration/*))"!]U)

[!// Calculate the number of EMIOS HW channels and HW modules
[!NOCODE!][!//
    [!CALL "CalculateModulesNumber","ModuleType"="string('EMIOS')"!]
[!ENDNOCODE!][!//
/* Number of EMIOS modules available on platform */
#define GPT_EMIOS_MODULES_NUM_U8  ([!"num:i($OutModulesNumber)"!]U)
[!// Calculate the number of PIT HW channels and HW modules
[!NOCODE!][!//
    [!CALL "CalculateModulesNumber","ModuleType"="string('PIT')"!]
[!ENDNOCODE!][!//
/* Number of PIT modules available on platform */
#define GPT_PIT_MODULES_NUM_U8  ([!"num:i($OutModulesNumber)"!]U)
[!// Calculate the number of STM HW channels and HW modules
[!NOCODE!][!//
    [!CALL "CalculateModulesNumber","ModuleType"="string('STM')"!]
[!ENDNOCODE!][!//
/* Number of STM modules available on platform */
#define GPT_STM_MODULES_NUM_U8  ([!"num:i($OutModulesNumber)"!]U)

/**
@{
@brief ID for peripheral. This ID need to match the order in the hardware to logic channels mapping table
*      because it is used as a base index.
*/
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_STM_MODULE      (0U)                                                           
#define GPT_PIT_MODULE      (GPT_STM_MODULE + (GPT_STM_CHANNELS_PER_MODULE_U8 * GPT_STM_MODULES_NUM_U8))
#define GPT_EMIOS_MODULE    (GPT_PIT_MODULE + (GPT_PIT_CHANNELS_PER_MODULE_U8 * GPT_PIT_MODULES_NUM_U8))
/** @} */

/**
* @brief The total number of indexes used by the hardware to logic channel map
*/
#define GPT_CHANNEL_IDX_NUM (GPT_EMIOS_MODULE + (GPT_EMIOS_CHANNELS_PER_MODULE_U8 * GPT_EMIOS_MODULES_NUM_U8))

/**
*   @brief Number of Predefined timers supported
*/
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_HW_PREDEFTIMER_NUM (4U)



/** 
* @brief  Switch to enable/disable the production error reporting.
*/
#define GPT_DISABLE_DEM_REPORT_ERROR_STATUS [!IF "$GptDisableDemReport = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!]

/** 
*   @brief  This is a timeout value which is used to wait till PIT_RTI_LDVAL is synchronized into the RTI clock domain
*/
#define GPT_TIMEOUT_COUNTER  ([!"num:i(GptDriverConfiguration/GptTimeout)"!]UL)



[!IF "node:exists(GptDemEventParameterRefs)"!][!//
    [!IF "GptDriverConfiguration/GptDisableDemReportErrorStatus = 'false'"!][!//
#define GPT_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Gpt_MemMap.h"
/** @violates @ref GPT_CFG_H_REF_2 MISRA 2012 Advisory Rule 8.9, This violation is due to exporting
*   the externally configured initialization structure used by the "<MA>_Init" function.*/
extern CONST(Mcal_DemErrorType, GPT_CONST) Gpt_E_TimeoutCfg;

#define GPT_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Gpt_MemMap.h"
    [!ENDIF!][!//
[!ENDIF!][!//

/**
*   @brief export configuration Gpt driver
*/
[!MACRO "GptExportDriverConfiguration"!]
[!NOCODE!][!VAR "configName" = "as:name(GptChannelConfigSet)"!]
    [!CODE!] #define GPT_CONF_PB[!WS"4"!][!ENDCODE!][!//
    [!IF "var:defined('postBuildVariant')"!][!//
        [!VAR "variantIndex"="0"!][!//
        [!VAR "variantNumber"="variant:size()"!][!//
        [!LOOP "variant:all()"!][!VAR "variantIndex"="$variantIndex + 1"!][!//
            [!CODE!][!WS4!]extern CONST(Gpt_ConfigType, GPT_CONST) [!"$configName"!]_[!"."!];[!IF "$variantIndex < $variantNumber"!] \[!ENDIF!][!CR!][!ENDCODE!][!//
        [!ENDLOOP!][!//
    [!ELSE!][!//
            [!CODE!][!WS4!]extern CONST(Gpt_ConfigType, GPT_CONST) [!"$configName"!];[!CR!][!ENDCODE!]
    [!ENDIF!][!//
[!ENDNOCODE!][!//
[!ENDMACRO!]

[!IF "((IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!][!//
    [!CALL "GptExportDriverConfiguration"!][!//
[!ENDIF!]
/*==================================================================================================
*                                             ENUMS
==================================================================================================*/
#if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
/**
* @brief Predef Timer type. Indicates the type of predef timer.
* 
*/
typedef enum
{
    GPT_PREDEF_TIMER_1US_16BIT = 0x0U,
    GPT_PREDEF_TIMER_1US_24BIT,
    GPT_PREDEF_TIMER_1US_32BIT,
    GPT_PREDEF_TIMER_100US_32BIT
}Gpt_PredefTimerType;
#endif

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

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

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

#ifdef __cplusplus
}
#endif

#endif  /* GPT_CFG_H */

/** @} */
