[!AUTOSPACING!]
[!NOCODE!]

/**
*   @file    Gpt_PluginMacros.m
*   @version 1.0.0
*
*   @brief   AUTOSAR Gpt - Macros used to generate code template for GPT driver.
*   @details Macros used to generate code template for GPT driver.
*
*   @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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/


[!/* Avoid multiple inclusion */!]
[!IF "not(var:defined('GPT_PLUGIN_MACRO_M'))"!][!//
[!VAR "GPT_PLUGIN_MACRO_M" = "'true'"!][!//

[!MACRO "IndexChannelList", "ModuleType", "ModuleId"!][!//
    [!VAR "ChannelPrefix" = "concat($ModuleType, '_', $ModuleId, '_CH_')"!][!//
    [!VAR "IndexList" = "text:replaceAll(text:join(text:grep(ecu:list('Gpt.GptChannelConfigSet.GptChannelConfiguration.GptHwChannel'), concat($ChannelPrefix,'.*'))), $ChannelPrefix, '')"!][!//
    [!"$IndexList"!][!//
[!ENDMACRO!][!//
[!MACRO "AllChannelsUsedUnique", "AllChannelsUnion"!][!//
    [!VAR "AllChannelsUnique" = "''"!][!//
    [!FOR "index" = "0" TO "num:i(count(text:split($AllChannelsUnion)))"!][!//
        [!IF "not(text:contains(text:split($AllChannelsUnique), text:split($AllChannelsUnion)[$index + 1]))"!][!//
            [!VAR "AllChannelsUnique" = "concat($AllChannelsUnique, ' ', text:split($AllChannelsUnion)[$index + 1])"!][!//
        [!ENDIF!][!//
    [!ENDFOR!][!//
    [!"$AllChannelsUnique"!][!//
[!ENDMACRO!][!//
[!//This macros is used to calculate the number of timer channel Ids and number of timer hw modules.
[!MACRO "CalculateModulesNumber", "ModuleType"!][!//
        [!VAR "OutModulesNumber" = "0"!][!//
        [!VAR "OutModuleChannelsNumber" = "0"!][!//
        [!IF "$ModuleType = 'EMIOS'"!][!//
            [!VAR "MacMaxModuleId" = "num:i(ecu:list('Gpt.Num_eMios_Hw_Modules'))"!] [!//max id of the hardware unit available for this family i.e. 0,1,2,3 etc
        [!ELSEIF "$ModuleType = 'PIT'"!][!//
            [!VAR "MacMaxModuleId" = "num:i(ecu:list('Gpt.Num_Pit_Hw_Modules'))"!] [!//max id of the hardware unit available for this family i.e. 0,1,2,3 etc
        [!ELSEIF "$ModuleType = 'STM'"!][!//
            [!VAR "MacMaxModuleId" = "num:i(ecu:list('Gpt.Num_Stm_Hw_Modules'))"!] [!//max id of the hardware unit available for this family i.e. 0,1,2,3 etc
        [!ENDIF!][!//
        [!VAR "MaxChannelsNumber" = "0"!][!//
        [!IF "$MacMaxModuleId > 0"!][!//
        [!VAR "ModuleTypeAll" = "''"!]
            [!FOR "MacModuleId" = "0" TO "num:i($MacMaxModuleId) - 1"!][!//
                [!VAR "TempChannelList"!][!CALL "IndexChannelList", "ModuleType" = "$ModuleType", "ModuleId" = "$MacModuleId"!][!ENDVAR!]
                [!VAR "ModuleTypeAll" = "concat($ModuleTypeAll, ' ', $TempChannelList)"!]
            [!ENDFOR!][!//
        [!VAR "UsedChannels"!][!CALL "AllChannelsUsedUnique", "AllChannelsUnion" = "$ModuleTypeAll"!][!ENDVAR!]
        [!FOR "x" = "0" TO "num:i($MacMaxModuleId) - 1"!][!//
                [!VAR "ChannelsNumber" = "num:i(text:split($UsedChannels)[last()] + 1)"!][!//
                [!IF "$ChannelsNumber > 0"!][!//
                    [!IF "$ModuleType = 'PIT'"!][!//
                        [!VAR "ChannelsNumber" = "$ChannelsNumber + 1"!][!// +PIT_RTI extra channel
                    [!ENDIF!][!//
                    [!VAR "OutModulesNumber" = "$x+1"!][!//
[!CODE!]
/* The real number of channels in [!"$ModuleType"!]_[!"$x"!] */
/** @violates @ref GPT_CFG_H_REF_1 MISRA 2012 Required Rule 2.5, this macro was used in test */
#define GPT_[!"$ModuleType"!]_[!"$x"!]_NUM_CHANNEL_U8 ([!"num:i($ChannelsNumber)"!]U)[!//
[!ENDCODE!][!//
                    [!VAR "OutModuleChannelsNumber" = "$OutModuleChannelsNumber + $ChannelsNumber"!][!//
                [!ENDIF!][!//
                [!IF "$ChannelsNumber > $MaxChannelsNumber"!][!//
                    [!VAR "MaxChannelsNumber" = "$ChannelsNumber"!][!//
                [!ENDIF!][!//
        [!ENDFOR!][!//
        [!IF "$OutModulesNumber = 0"!][!//
            [!ERROR !][!//
                [!"$Name"!][!" '-OutModulesNumber should be > 0 at this stage because at least 1 module exists ' "!][!//
            [!ENDERROR!][!//
        [!ENDIF!][!//
        [!ENDIF!][!//
[!CODE!]
/* The maximum number of channels per module for [!"$ModuleType"!] */
#define GPT_[!"$ModuleType"!]_CHANNELS_PER_MODULE_U8 ([!"num:i($MaxChannelsNumber)"!]U)
        [!ENDCODE!][!//
[!ENDMACRO!][!//
[!MACRO "CheckFreeze" , "ModuleType"!]
    [!SELECT "GptChannelConfigSet"!]
     [!VAR "MacNumChannels" = "0"!][!//
     [!VAR "MacFreezeEnabledChannels" = "0"!][!//
     [!LOOP "GptChannelConfiguration/*/GptHwChannel[contains(., $ModuleType)]/.."!]
         [!IF "GptFreezeEnable"!] [!VAR "MacFreezeEnabledChannels" = "$MacFreezeEnabledChannels + 1"!][!ENDIF!][!//
         [!VAR "MacNumChannels" = "$MacNumChannels + 1"!][!//
     [!ENDLOOP!]
     [!IF "not($MacNumChannels = $MacFreezeEnabledChannels) and not($MacFreezeEnabledChannels = 0)"!]
         [!ERROR!][!//
             Module [!"$ModuleType"!] has channels configured with different values for FreezeEnable. Please select the same value for FreezeEnable accross all [!"$ModuleType"!] channels
         [!ENDERROR!][!//
     [!ENDIF!]
    [!ENDSELECT!]
[!ENDMACRO!]


[!//This macros is used to build the hardware to logic map table
[!MACRO "BuildChannelMap" , "ModuleType", "LastModule"!]
    [!IF "$ModuleType = 'STM'"!]
        [!VAR "MacMaxModules" = "num:i(ecu:list('Gpt.Num_Stm_Hw_Modules'))"!][!//
    [!ELSEIF "$ModuleType = 'PIT'"!][!//
        [!VAR "MacMaxModules" = "num:i(ecu:list('Gpt.Num_Pit_Hw_Modules'))"!][!//
    [!ELSEIF "$ModuleType = 'EMIOS'"!][!//
       [!VAR "MacMaxModules" = "num:i(ecu:list('Gpt.Num_eMios_Hw_Modules'))"!][!//
    [!ENDIF!][!//
    [!VAR "ModuleTypeAll" = "''"!]
    [!FOR "MacModuleId" = "0" TO "num:i($MacMaxModules) - 1"!][!//
        [!VAR "TempChannelList"!][!CALL "IndexChannelList", "ModuleType" = "$ModuleType", "ModuleId" = "$MacModuleId"!][!ENDVAR!]
        [!VAR "ModuleTypeAll" = "concat($ModuleTypeAll, ' ', $TempChannelList)"!]
    [!ENDFOR!][!//
[!//Hardware to logic channel mapping
    [!VAR "UsedChannels"!][!CALL "AllChannelsUsedUnique", "AllChannelsUnion" = "$ModuleTypeAll"!][!ENDVAR!]
    [!VAR "MacMaxChannelId" = "num:i(text:split($UsedChannels)[last()] + 1)"!][!//
        [!IF "$ModuleType = 'PIT'"!][!//PIT_RTI extra channel
            [!VAR "MacMaxChannelId" = "$MacMaxChannelId + 1"!][!//
        [!ENDIF!][!//      
        [!FOR "MacModuleId" = "0" TO "num:i($MacMaxModules)-1"!][!//
          [!FOR "MacChannelId" = "0" TO "num:i($MacMaxChannelId)-1"!][!//
            [!VAR "MacChannelUsed"="0"!][!//
            [!FOR "MacLogicChannel" = "0" TO "num:i(count(GptChannelConfigSet/GptChannelConfiguration/*))"!][!//
                [!SELECT "GptChannelConfigSet/GptChannelConfiguration/*/GptChannelId[.=$MacLogicChannel]/.."!][!//
                [!IF "$ModuleType = 'PIT'"!]
                    [!IF "num:i($MacChannelId) = 0"!]
                        [!IF "GptHwChannel = concat($ModuleType,'_',num:i($MacModuleId),'_CH_RTI')"!][!//
                            [!CODE!]
        GptConf_GptChannelConfiguration_[!"node:name(.)"!][!ENDCODE!][!//
                            [!VAR "MacChannelUsed"="1"!][!//
                        [!ENDIF!][!//
                    [!ELSE!]
                        [!IF "GptHwChannel = concat($ModuleType,'_',num:i($MacModuleId),'_CH_',num:i($MacChannelId)-1)"!][!//
                            [!CODE!]
        GptConf_GptChannelConfiguration_[!"node:name(.)"!][!ENDCODE!][!//
                            [!VAR "MacChannelUsed"="1"!][!//
                        [!ENDIF!][!//
                    [!ENDIF!][!//
                [!ELSE!]
                    [!IF "GptHwChannel = concat($ModuleType,'_',num:i($MacModuleId),'_CH_',num:i($MacChannelId))"!][!//
                        [!CODE!]
        GptConf_GptChannelConfiguration_[!"node:name(.)"!][!ENDCODE!][!//
                        [!VAR "MacChannelUsed"="1"!][!//
                    [!ENDIF!][!//
                [!ENDIF!][!//
                [!ENDSELECT!][!//
            [!ENDFOR!][!//

            [!IF "$MacChannelUsed=0"!][!//
                [!CODE!]
        GPT_CHN_NOT_USED[!ENDCODE!][!//
            [!ENDIF!][!//
            [!IF "$MacModuleId = (num:i($MacMaxModules - 1)) and $MacChannelId = (num:i($MacMaxChannelId - 1)) and $LastModule = 'TRUE'"!]
            [!ELSE!]
                [!CODE!],[!ENDCODE!][!//
            [!ENDIF!][!//

            [!IF "$ModuleType = 'STM'"!]
                [!CODE!] /*mapping of [!"concat($ModuleType,'_',num:i($MacModuleId),'_CH_',num:i(text:split($UsedChannels)[$MacChannelId + 1]))"!]*/[!ENDCODE!][!//           
            [!ELSEIF "$ModuleType = 'PIT'"!]
                [!IF "$MacChannelId > 0"!]
                    [!CODE!] /*mapping of [!"concat($ModuleType,'_',num:i($MacModuleId),'_CH_',num:i($MacChannelId - 1))"!]*/[!ENDCODE!][!//   
                [!ELSEIF "$MacChannelId = 0"!]
                    [!CODE!] /*mapping of [!"concat($ModuleType,'_',num:i($MacModuleId),'_CH_RTI')"!]*/[!ENDCODE!][!//
                [!ENDIF!][!//
            [!ELSEIF "$ModuleType = 'EMIOS'"!]
                    [!CODE!] /*mapping of [!"concat($ModuleType,'_',num:i($MacModuleId),'_CH_',num:i($MacChannelId))"!]*/[!ENDCODE!][!//
            [!ENDIF!][!//
          [!ENDFOR!][!//
        [!ENDFOR!][!//
[!ENDMACRO!]

[!//This macros is used to check parameters
[!MACRO "CheckParameter" , "ModuleType", "param"!]
    [!IF "$ModuleType = 'STM'"!]
        [!VAR "MacMaxModules"="num:i(ecu:list('Gpt.Num_Stm_Hw_Modules'))"!]
    [!ELSEIF "$ModuleType = 'PIT'"!]
        [!VAR "MacMaxModules"="num:i(ecu:list('Gpt.Num_Pit_Hw_Modules'))"!]
    [!ELSEIF "$ModuleType = 'EMIOS'"!]
        [!VAR "MacMaxModules" = "num:i(ecu:list('Gpt.Num_eMios_Hw_Modules'))"!]
    [!ENDIF!][!//  
        
    [!VAR "MacErrorFlag" = "string('Invalid')"!][!//
    
    [!FOR "idx" = "0" TO "num:i($MacMaxModules)"!][!//
        [!VAR "MacErrorFlag" = "string('Invalid')"!][!//
        [!FOR "x" = "0" TO "num:i(count(GptChannelConfiguration/*))"!][!//
        [!SELECT "GptChannelConfiguration/*/GptChannelId[.=$x]/.."!][!//
            [!IF "contains(GptHwChannel, concat($ModuleType, '_', $idx)) and node:exists($param)"!][!//
                [!IF "($MacErrorFlag = string('Invalid'))"!][!//
                    [!VAR "MacErrorFlag" = "string(node:value($param))"!][!//
                [!ELSE!][!//
                    [!IF "($MacErrorFlag = string(node:value($param)))"!][!//
                    [!ELSE!][!//
                        [!ERROR!][!//
                        [!"concat('For the ',$ModuleType, '_', $idx,' module all the channels must have the same value for the ', $param, ' parameter, because this module has one general clock prescaler for all its counter channels.')"!][//
                        [!ENDERROR!][!//
                    [!ENDIF!][!//
                [!ENDIF!][!//  
            [!ENDIF!][!//  
        [!ENDSELECT!][!//
        [!ENDFOR!]
    [!ENDFOR!]
[!ENDMACRO!]

[!//This macros is used to build the configuration structure for a config set.
[!MACRO "BuildConfigSet"!]
    [!SELECT "GptChannelConfigSet"!]
    [!CALL "CheckParameter","ModuleType"="string('STM')", "param"="string('GptChannelTickFrequency')"!][!//
    [!CALL "CheckParameter","ModuleType"="string('STM')", "param"="string('GptChannelClkSrcRef')"!][!//
        [!IF "node:value(../GptAutosarExt/GptEnableDualClockMode)"!][!//
            [!CALL "CheckParameter", "ModuleType" = "string('STM')", "param" = "string('GptChannelPrescalerAlternate')"!][!//
        [!ENDIF!]
    [!ENDSELECT!]
[!FOR "x" = "0" TO "num:i(count(GptChannelConfigSet/GptChannelConfiguration/*))"!][!//
    [!SELECT "GptChannelConfigSet/GptChannelConfiguration/*/GptChannelId[.=$x]/.."!][!//
        [!CODE!][!WS"4"!]{   /*[!"node:name(.)"!] configuration data*/[!CR!][!ENDCODE!]
        
        [!IF "GptEnableWakeup"!][!//
            [!CODE!][!WS"8"!](boolean)TRUE, /* Wakeup capability */[!CR!][!ENDCODE!]
        [!ELSE!][!//
            [!CODE!][!WS"8"!](boolean)FALSE, /* Wakeup capability */[!CR!][!ENDCODE!]
        [!ENDIF!]
        
        [!IF "node:exists(GptNotification)"!][!//
            [!IF "(GptNotification != '') and (GptNotification != 'NULL_PTR') and (GptNotification != 'NULL')"!][!//
                [!CODE!][!WS"8"!]&[!"GptNotification"!], /* Channel notification */[!CR!][!ENDCODE!]
            [!ELSE!][!//
                [!CODE!][!WS"8"!]NULL_PTR, /* Channel notification */[!CR!][!ENDCODE!]
            [!ENDIF!][!//    
        [!ELSE!][!//
            [!CODE!][!WS"8"!]NULL_PTR, /* Channel notification */[!CR!][!ENDCODE!]
        [!ENDIF!]
        
        [!CODE!]#if ((GPT_WAKEUP_FUNCTIONALITY_API == STD_ON) && (GPT_REPORT_WAKEUP_SOURCE == STD_ON))[!CR!][!ENDCODE!]
        [!IF "node:exists(GptWakeupConfiguration)"!][!//
            [!CODE!][!WS"8"!](EcuM_WakeupSourceType)((uint32)((uint32)1 << [!"as:ref(GptWakeupConfiguration/GptWakeupSourceRef)/EcuMWakeupSourceId"!])), /* Wakeup information */[!CR!][!ENDCODE!]
        [!ELSE!][!//
            [!CODE!][!WS"8"!](EcuM_WakeupSourceType)0U, /* Wakeup information */[!CR!][!ENDCODE!]
        [!ENDIF!]        
        [!CODE!]#endif[!CR!][!ENDCODE!]
        
        [!CODE!][!WS"8"!](Gpt_ValueType)([!"num:i(GptChannelTickValueMax)"!]U), /* Maximum ticks value*/
        ([!"GptChannelMode"!]), /* Timer mode:continous/one-shot */[!CR!][!ENDCODE!]    
            
        [!CODE!][!WS"8"!]{[!CR!][!ENDCODE!]
            [!CODE!][!WS"12"!](uint8)([!"GptHwChannel"!]), /* GPT physical channel no. */[!CR!][!ENDCODE!]
            [!CODE!][!WS"12"!](uint8)(GPT_[!"substring-before(GptHwChannel, '_')"!]_MODULE), /* hardware module ID */[!CR!][!ENDCODE!]
            [!CODE!][!WS"12"!][!IF "GptFreezeEnable"!](boolean)TRUE[!ELSE!](boolean)(FALSE)[!ENDIF!], /* Freeze Enable */[!CR!][!ENDCODE!]           
            
    [!VAR "MacChannelFreq" = "num:i( contains(GptHwChannel,'PIT'))* noderef:value(concat(noderef:ref(noderef:value(concat(noderef:ref(GptChannelClkSrcRef), '/GptClockReference'))), '/McuClockReferencePointFrequency')) + [!//
                              num:i(contains(GptHwChannel,'STM')) *(noderef:value(concat(noderef:ref(noderef:value(concat(noderef:ref(GptChannelClkSrcRef), '/GptClockReference'))), '/McuClockReferencePointFrequency')) div (num:i(not(contains(node:fallback(GptHwChannel,'STM'),'STM')))+GptChannelPrescaler)) + [!//
                              num:i(contains(GptHwChannel,'EMIOS')) *(noderef:value(concat(noderef:ref(noderef:value(concat(noderef:ref(GptChannelClkSrcRef), '/GptClockReference'))), '/McuClockReferencePointFrequency')) div (num:i(not(contains(node:fallback(GptHwChannel,'EMIOS'),'EMIOS')))+GptChannelPrescaler))"!][!// 
    [!VAR "MacChannelFreq" = "$MacChannelFreq"!]
    [!IF "num:f(GptChannelTickFrequency)!=num:f($MacChannelFreq)"!]
        [!ERROR!]
                The value configured for GptChannelTickFrequency parameter is not compliant with MCU clock tree settings.
                To solve this problem change the configured channel ticks frequency from "[!"num:f(GptChannelTickFrequency)"!]" to "[!"num:f($MacChannelFreq)"!]".
        [!ENDERROR!]
    [!ENDIF!][!//
    [!IF "contains(GptHwChannel, 'STM')"!][!//
[!CODE!][!//
            (Gpt_PrescalerType)([!"num:i(number(GptChannelPrescaler)-1)"!]U) /* STM Clock divider */[!CR!][!ENDCODE!]
    [!ELSEIF "contains(GptHwChannel, 'PIT')"!][!//
[!CODE!][!//
            (uint8)(0U) /* Not used for PIT */[!CR!][!ENDCODE!]
    [!ELSEIF "contains(GptHwChannel, 'EMIOS')"!][!//
[!CODE!][!//
            (Gpt_PrescalerType)([!"num:i(number(GptChannelPrescaler)-1)"!]U) /* EMIOS Clock divider */[!CR!][!ENDCODE!]
    [!ENDIF!][!//

        [!IF "../../../GptAutosarExt/GptEnableDualClockMode"!][!//
            [!CODE!]#if (GPT_SET_CLOCK_MODE == STD_ON) [!CR!][!ENDCODE!][!//
                [!IF "contains(GptHwChannel, 'STM')"!][!//
                    [!CODE!][!WS"12"!],(Gpt_PrescalerType)([!"num:i(number(GptChannelPrescalerAlternate) - 1)"!]U) /* STM Alternate Clock divider */[!CR!][!ENDCODE!]
                [!ELSEIF "contains(GptHwChannel, 'PIT')"!][!//
                    [!CODE!][!WS"12"!],(uint8)(0U) /* PIT Alternate Clock divider - Unused */[!CR!][!ENDCODE!]
                [!ELSE!][!//
                    [!CODE!][!WS"12"!],(Gpt_PrescalerType)([!"num:i(number(GptChannelPrescalerAlternate) - 1)"!]U) /* EMIOS Alternate Clock divider */[!CR!][!ENDCODE!]
                [!ENDIF!][!//
            [!CODE!]#endif [!CR!][!ENDCODE!][!//
        [!ENDIF!][!//    
        
        [!CODE!]#if (GPT_CHAIN_MODE == STD_ON)[!CR!][!ENDCODE!]
            [!IF "contains(GptHwChannel, 'PIT')"!][!//
                [!CODE!][!WS"12"!],[!IF "((GptChainMode = 'true') and ((contains(GptHwChannel,'PIT_0_CH_1') = 'true') or (contains(GptHwChannel,'PIT_0_CH_2') = 'true') or (contains(GptHwChannel,'PIT_0_CH_3') = 'true')))"!](boolean)TRUE[!ELSE!](boolean)(FALSE)[!ENDIF!] /* Chain Mode Enable */[!CR!][!ENDCODE!]
            [!ELSE!][!//
                [!CODE!][!WS"12"!],(boolean)FALSE, /* Chain Mode not used for STM, EMIOS */[!CR!][!ENDCODE!]
            [!ENDIF!][!//
        [!CODE!]#endif[!CR!][!ENDCODE!]          
        [!CODE!][!WS"8"!]}[!CR!][!ENDCODE!][!//

        [!CODE!][!WS"4"!]}[!CR!][!ENDCODE!][!//
        
    [!ENDSELECT!][!//

        [!CODE!][!IF "$x < num:i(count(GptChannelConfigSet/GptChannelConfiguration/*)) - 1"!],[!CR!][!ENDIF!][!ENDCODE!][!//

[!ENDFOR!][!//
[!ENDMACRO!][!//

[!MACRO "PredefTimerStmConsistencyCheck"!]
[!VAR "MacCurrentModule" = "substring-before(GptHwChannel,'_PREDEF')"!]
[!VAR "MacGptChannelClkSrcRef" = "GptChannelClkSrcRef"!]
[!VAR "MacGptChannelPrescaler" = "GptChannelPrescaler"!]
[!VAR "MacGptFreezeEnable" = "GptFreezeEnable"!]
[!LOOP "../*"!]
     [!IF "substring-before(GptHwChannel,'_PREDEF') = $MacCurrentModule"!]
        [!IF "GptChannelClkSrcRef != $MacGptChannelClkSrcRef"!]
            [!ERROR!]
                GptChannelClkSrcRef of predeftimer [!"$MacCurrentModule"!] is not consistency with other predeftimer channel
            [!ENDERROR!]
        [!ENDIF!]
        [!IF "GptChannelPrescaler != $MacGptChannelPrescaler"!]
            [!ERROR!]
                GptChannelPrescaler of predeftimer [!"$MacCurrentModule"!] is not consistency with other predeftimer channel
            [!ENDERROR!]
        [!ENDIF!]
        [!IF "GptFreezeEnable != $MacGptFreezeEnable"!]
            [!ERROR!]
                GptFreezeEnable of predeftimer [!"$MacCurrentModule"!] is not consistency with other predeftimer channel
            [!ENDERROR!]
        [!ENDIF!]
    [!ENDIF!]
[!ENDLOOP!]
[!LOOP "../../GptChannelConfigSet/GptChannelConfiguration/*"!]
    [!IF "substring-before(GptHwChannel,'_CH_') = $MacCurrentModule"!]
        [!IF "GptChannelClkSrcRef != $MacGptChannelClkSrcRef"!]
            [!ERROR!]
                GptChannelClkSrcRef of predeftimer [!"$MacCurrentModule"!] is not consistency with Gpt channel [!"GptChannelId"!]
            [!ENDERROR!]
        [!ENDIF!]
        [!IF "GptChannelPrescaler != $MacGptChannelPrescaler"!]
            [!ERROR!]
                GptChannelPrescaler of predeftimer [!"$MacCurrentModule"!] is not consistency with Gpt channel [!"GptChannelId"!]
            [!ENDERROR!]
        [!ENDIF!]
        [!IF "GptFreezeEnable != $MacGptFreezeEnable"!]
            [!ERROR!]
                GptFreezeEnable of predeftimer [!"$MacCurrentModule"!] is not consistency with Gpt channel [!"GptChannelId"!]
            [!ENDERROR!]
        [!ENDIF!]
    [!ENDIF!]
[!ENDLOOP!]
[!ENDMACRO!]

[!//This macros is used to build the Predef timer configuration structure.
[!MACRO "BuildHwchannelPredefTimer", "predefType"!]
[!NOCODE!]

[!VAR "path_temp" = "'GptPredefTimer_1us_16Bit'"!][!//
[!IF "$predefType = 'PREDEF_TIMER_1US_16BIT'"!][!//
    [!VAR "path_temp" = "'GptPredefTimer_1us_16Bit'"!][!//
[!ELSEIF "$predefType = 'PREDEF_TIMER_1US_24BIT'"!][!//
    [!VAR "path_temp" = "'GptPredefTimer_1us_24Bit'"!][!//
[!ELSEIF "$predefType = 'PREDEF_TIMER_1US_32BIT'"!][!//
    [!VAR "path_temp" = "'GptPredefTimer_1us_32Bit'"!][!//
[!ELSE!][!//
    [!VAR "path_temp" = "'GptPredefTimer_100us_32Bit'"!][!//
[!ENDIF!][!//

[!VAR "path_predef" = "concat('GptPredefTimerConfiguration/',$path_temp)"!]
[!SELECT "node:ref($path_predef)"!]
    [!IF "contains(GptHwChannel,'STM')"!][!//
        [!CALL "PredefTimerStmConsistencyCheck"!][!//
    [!ENDIF!][!//
    [!CODE!][!WS"4"!](uint8)([!"GptHwChannel"!]), /* GPT physical channel no. */[!CR!][!ENDCODE!]
    [!CODE!][!WS"4"!](uint8)(GPT_[!"substring-before(GptHwChannel, '_')"!]_MODULE), /* hardware module ID */[!CR!][!ENDCODE!]
    [!IF "GptFreezeEnable"!][!//
        [!CODE!][!WS"4"!](boolean)TRUE, /* Freeze Enable */[!CR!][!ENDCODE!]
    [!ELSE!][!//
        [!CODE!][!WS"4"!](boolean)(FALSE), /* Freeze Disable */[!CR!][!ENDCODE!]
    [!ENDIF!][!//
    [!IF "contains(GptHwChannel, 'STM')"!][!//
        [!CODE!][!WS"4"!](Gpt_PrescalerType)([!"num:i(number(GptChannelPrescaler) - 1)"!]U), /* STM Clock divider */[!CR!][!ENDCODE!]
    [!ELSE!][!//
        [!CODE!][!WS"4"!](Gpt_PrescalerType)([!"num:i(number(GptChannelPrescaler) - 1)"!]U), /* EMIOS Clock divider */[!CR!][!ENDCODE!]
    [!ENDIF!][!//
[!ENDSELECT!][!//
[!ENDNOCODE!][!//
[!ENDMACRO!][!//
[!ENDIF!] /* Avoid multiple inclusion ENDIF */
[!ENDNOCODE!]