[!AUTOSPACING!]
[!CODE!]
/**
*   @file           Pwm_PBcfg.c
*   @implements     Pwm_PBcfg.c_Artifact
*   @version        1.0.0
*
*   @brief          AUTOSAR Pwm - PWM post-build configuration file.
*   @details        Post-build configuration structure instances.
*
*   @addtogroup     PWM_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : eMios
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/
[!NOCODE!]

    [!INCLUDE "Pwm_VersionCheck_Src.m"!]

    /* Variable storing number of eMIOS Modules available on the current platform */
    [!VAR "numeMiosModules" = "ecu:get('Pwm.Num_eMios_Hw_Modules')"!]
    [!VAR "numeMiosChannelsPerModule" = "ecu:get('Pwm.Num_eMios_Hw_Channels')"!]
    [!VAR "numeMiosChannels" = "($numeMiosModules * $numeMiosChannelsPerModule)"!]

    
    
/*====================================== eMIOS ==================================================*/
    
    /* Function to generate master bus period in ticks if input value is in seconds */
    [!MACRO "GenerateeMiosMasterbusPeriodInTicks", "MotorFreq"!]
    [!NOCODE!]
        [!VAR "MasterPrescalerVal" = "substring-after(MasterBusPrescaler,'DIV_')"!]
        [!VAR "MasterPeriod" = "MasterBusPeriodDefault"!]
        [!VAR "MasterPeriodMax" = "16777215"!]

        [!IF "MasterBusPeriodInTicks"!]
            [!VAR "OutMasterPeriodTicks" = "$MasterPeriod"!]
        [!ELSE!]
            [!VAR "OutMasterPeriodTicks" = "$MasterPeriod * ($MotorFreq div $MasterPrescalerVal)"!]
        [!ENDIF!]

        [!IF "num:i($OutMasterPeriodTicks) < 1"!]
            [!ERROR!]
The configured period/ticks for master bus [!"PwmeMiosMasterBus"!] on [!"../../PwmeMiosModule"!] in channel config set [!"name(../../../../.)"!] is smaller than 1 tick: [!"$OutMasterPeriodTicks"!]
The plugin performs the conversion from Period to ticks if requested.
To solve this problem change the configured Period/ticks or change the Pwm Channel clock tree settings.
            [!ENDERROR!]
        [!ENDIF!]

        [!IF "num:i($OutMasterPeriodTicks) > $MasterPeriodMax"!]
            [!ERROR!]
The configured period/ticks for master bus [!"PwmeMiosMasterBus"!] on [!"../../PwmeMiosModule"!] in channel config set [!"name(../../../../.)"!] is larger than [!"$MasterPeriodMax"!] ticks: [!"$MasterPeriod"!]
The plugin performs the conversion from Period to ticks if requested.
To solve this problem change the configured Period/ticks or change the Pwm Channel clock tree settings.
            [!ENDERROR!]
        [!ENDIF!]
        
    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    
    
    /* Get master bus counter mode for given channel */
    [!MACRO "GetMasterMode", "parameMiosBus", "parameMiosChannel"!]
    [!NOCODE!]
        [!IF "($parameMiosBus = 'PWM_BUS_A_U32')"!]
            [!VAR "eMiosMaster" = "23"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_F_U32')"!]
            [!VAR "eMiosMaster" = "22"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_DIVERSE_U32')"!]
            [!IF "($parameMiosChannel < 8)"!]
                [!VAR "eMiosMaster" = "0"!]
            [!ELSEIF "($parameMiosChannel < 16)"!]
                [!VAR "eMiosMaster" = "8"!]
            [!ELSEIF "($parameMiosChannel < 24)"!]
                [!VAR "eMiosMaster" = "16"!]
            [!ELSE!]
                [!VAR "eMiosMaster" = "24"!]
            [!ENDIF!]
        [!ENDIF!]

        [!IF "($parameMiosBus = 'PWM_BUS_INTERNAL_COUNTER_U32')"!]
            [!VAR "MasterBusMode" = "(num:i(0))"!]
        [!ELSE!]
            [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
                [!VAR "MastereMiosIdx" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

                [!IF "(num:i($eMiosMaster) = $MastereMiosIdx)"!]
                    [!VAR "MasterBusMode" = "MasterModeSelect"!]
                [!ENDIF!]
            [!ENDLOOP!]
        [!ENDIF!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Get master bus period */
    [!MACRO "GetMasterPeriod", "parameMiosBus", "parameMiosChannel", "paramClockRef"!]
    [!NOCODE!]
        [!IF "($parameMiosBus = 'PWM_BUS_A_U32')"!]
            [!VAR "eMiosMaster" = "23"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_F_U32')"!]
            [!VAR "eMiosMaster" = "22"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_DIVERSE_U32')"!]
            [!IF "($parameMiosChannel < 8)"!]
                [!VAR "eMiosMaster" = "0"!]
            [!ELSEIF "($parameMiosChannel < 16)"!]
                [!VAR "eMiosMaster" = "8"!]
            [!ELSEIF "($parameMiosChannel < 24)"!]
                [!VAR "eMiosMaster" = "16"!]
            [!ELSE!]
                [!VAR "eMiosMaster" = "24"!]
            [!ENDIF!]
        [!ENDIF!]

        [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
            [!VAR "MastereMiosIdx" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

            [!IF "(num:i($eMiosMaster) = $MastereMiosIdx)"!]
                [!VAR "PrescalerVal" = "substring-after(MasterBusPrescaler,'DIV_')"!]

                [!CALL "GenerateeMiosMasterbusPeriodInTicks", "MotorFreq" = "$paramClockRef"!]

                [!VAR "OutPeriod" = "$OutMasterPeriodTicks"!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Get master bus alternative period */
    [!MACRO "GetMasterPeriod_Alternate", "parameMiosBus", "parameMiosChannel"!]
    [!NOCODE!]
        [!VAR "eMiosMaster" = "30"!]

        [!IF "($parameMiosBus = 'PWM_BUS_A_U32')"!]
            [!VAR "eMiosMaster" = "23"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_F_U32')"!]
            [!VAR "eMiosMaster" = "22"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_DIVERSE_U32')"!]
            [!IF "($parameMiosChannel < 8)"!]
                [!VAR "eMiosMaster" = "0"!]
            [!ELSEIF "($parameMiosChannel < 16)"!]
                [!VAR "eMiosMaster" = "8"!]
            [!ELSEIF "($parameMiosChannel < 24)"!]
                [!VAR "eMiosMaster" = "16"!]
            [!ELSE!]
                [!VAR "eMiosMaster" = "24"!]
            [!ENDIF!]
        [!ENDIF!]

        [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
            [!VAR "MastereMiosIdx" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

            [!IF "(num:i($eMiosMaster) = $MastereMiosIdx)"!]
                [!VAR "PrescalerVal_Alternate" = "substring-after(MasterBusPrescaler_Alternate,'DIV_')"!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Macro used to validate the period of DAOC channel with master bus */
    [!MACRO "ValidatePwmDaocModulo"!]
    [!NOCODE!]
        [!LOOP "PwmChannel/*"!]
            [!IF "(contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC'))"!]
                [!IF "((contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_A')) or (contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_F')) or (contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_DIVERSE')))"!]
                    [!VAR "McuClockRefValue" = "node:ref(PwmMcuClockReferencePoint)/McuClockReferencePointFrequency"!]

                    [!CALL "GenerateeMiosChannelPeriodInTicks", "MotorFreq" = "$McuClockRefValue"!]

                    [!VAR "DefaultPeriod" = "$OutPeriodTicks"!]
                    [!VAR "MaceMiosBus" = "node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!]
                    [!VAR "parameMiosChannel" = "substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]
                    [!VAR "eMiosChannelId" = "PwmChannelId"!]
                    [!VAR "PwmChannelName" = "node:name(.)"!]

                    [!IF "($MaceMiosBus = 'PWM_BUS_A_U32')"!]
                        [!VAR "eMiosMaster" = "23"!]
                    [!ELSEIF "($MaceMiosBus = 'PWM_BUS_F_U32')"!]
                        [!VAR "eMiosMaster" = "22"!]
                    [!ELSEIF "($MaceMiosBus = 'PWM_BUS_DIVERSE_U32')"!]
                        [!IF "($parameMiosChannel < 8)"!]
                            [!VAR "eMiosMaster" = "0"!]
                        [!ELSEIF "($parameMiosChannel < 16)"!]
                            [!VAR "eMiosMaster" = "8"!]
                        [!ELSEIF "($parameMiosChannel < 24)"!]
                            [!VAR "eMiosMaster" = "16"!]
                        [!ELSE!]
                            [!VAR "eMiosMaster" = "24"!]
                        [!ENDIF!]
                    [!ENDIF!]

                    [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
                        [!VAR "MastereMiosIdx" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

                        [!IF "(num:i($MastereMiosIdx) = $eMiosMaster)"!]
                            [!CALL "GenerateeMiosMasterbusPeriodInTicks", "MotorFreq" = "$McuClockRefValue"!]

                            [!VAR "MasterPeriod" = "$OutMasterPeriodTicks"!]

                            [!IF "(num:i($DefaultPeriod)) > (num:i($MasterPeriod))"!]
                                [!ERROR!]
For eMios Channel_[!"$eMiosChannelId"!] of logical channel [!"$PwmChannelName"!] use DAOC mode with external bus, but default period is greater than the period of master bus
                                [!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ENDLOOP!]
                [!ENDIF!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    
    
    /* Get modulo in DAOC mode */
    [!MACRO "GetDaocModulo", "parameMiosBus", "parameMiosChannel", "paramClockRef"!]
    [!NOCODE!]
        [!IF "($parameMiosBus = 'PWM_BUS_A_U32')"!]
            [!VAR "eMiosMaster" = "23"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_F_U32')"!]
            [!VAR "eMiosMaster" = "22"!]
        [!ELSEIF "($parameMiosBus = 'PWM_BUS_DIVERSE_U32')"!]
            [!IF "($parameMiosChannel < 8)"!]
                [!VAR "eMiosMaster" = "0"!]
            [!ELSEIF "($parameMiosChannel < 16)"!]
                [!VAR "eMiosMaster" = "8"!]
            [!ELSEIF "($parameMiosChannel < 24)"!]
                [!VAR "eMiosMaster" = "16"!]
            [!ELSE!]
                [!VAR "eMiosMaster" = "24"!]
            [!ENDIF!]
        [!ENDIF!]

        [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
            [!VAR "MastereMiosIdx" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

            [!IF "(num:i($eMiosMaster) = $MastereMiosIdx)"!]
                [!CALL "GenerateeMiosMasterbusPeriodInTicks", "MotorFreq" = "$paramClockRef"!]

                [!VAR "PwmDaocModulo" = "$OutMasterPeriodTicks"!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Macro used to validate the eMIOS configured bus selection */
    [!MACRO "ValidatePwmBusSelection"!]
    [!NOCODE!]
        [!FOR "mIdx" = "0" TO "num:i($numeMiosModules) - 1"!]
            [!LOOP "PwmChannel/*"!]
                [!VAR "MatchBus_A_Config" = "0"!]
                [!VAR "MatchBus_B_Config" = "0"!]
                [!VAR "MatchBus_C_Config" = "0"!]
                [!VAR "MatchBus_D_Config" = "0"!]
                [!VAR "MatchBus_E_Config" = "0"!]
                [!VAR "MatchBus_F_Config" = "0"!]
                [!VAR "PwmChannelName" = "node:name(.)"!]

                [!LOOP "node:ref(PwmeMiosChannel)/../../PwmeMiosMasterBus/*"!]
                    [!VAR "MastereMiosChannel" = "substring-after(PwmeMiosMasterBus,'Channel_')"!]

                    [!IF "($MastereMiosChannel = 23)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_A_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_A_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_A_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_A_Config" = "2"!]
                        [!ENDIF!]
                    [!ELSEIF "($MastereMiosChannel = 0)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_B_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_B_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_B_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_B_Config" = "2"!]
                        [!ENDIF!]
                    [!ELSEIF "($MastereMiosChannel = 8)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_C_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_C_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_C_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_C_Config" = "2"!]
                        [!ENDIF!]
                    [!ELSEIF "($MastereMiosChannel = 16)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_D_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_D_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_D_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_D_Config" = "2"!]
                        [!ENDIF!]
                    [!ELSEIF "($MastereMiosChannel = 24)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_E_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_E_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_E_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_E_Config" = "2"!]
                        [!ENDIF!]
                    [!ELSEIF "($MastereMiosChannel = 22)"!]
                        [!IF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_COUNTER_U32')"!]
                            [!VAR "MatchBus_F_Config" = "3"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_COUNTER_U32')"!]
                            [!VAR "MatchBus_F_Config" = "4"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_F_Config" = "1"!]
                        [!ELSEIF "contains(MasterModeSelect, 'MASTER_MODE_UP_BUFFERED_COUNTER_U32')"!]
                            [!VAR "MatchBus_F_Config" = "2"!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDLOOP!]

                [!VAR "MaceMiosModule"  = "substring-after(node:ref(PwmeMiosChannel)/../../PwmeMiosModule,'eMios_')"!]
                [!VAR "MaceMiosChannel" = "substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]

                [!IF "(num:i($MaceMiosModule) = $mIdx)"!]
                    [!IF "contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_A_U32')"!]
                        [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                            [!IF "($MatchBus_A_Config = 2) or ($MatchBus_A_Config = 3) or ($MatchBus_A_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 23 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_A_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS A, but EMIOS channel 23 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                            [!IF "($MatchBus_A_Config = 2) or ($MatchBus_A_Config = 1) or ($MatchBus_A_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 23 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_A_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS A, but EMIOS channel 23 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                            [!IF "($MatchBus_A_Config = 1) or ($MatchBus_A_Config = 3) or ($MatchBus_A_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , thus EMIOS channel 23 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_A_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS A, but EMIOS channel 23 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                            [!IF "($MatchBus_A_Config = 1) or ($MatchBus_A_Config = 3) or ($MatchBus_A_Config = 2)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , but EMIOS channel 23 has been configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_A_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS A, but EMIOS channel 23 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ELSEIF "contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_F_U32')"!]
                        [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                            [!IF "($MatchBus_F_Config = 2) or ($MatchBus_F_Config = 3) or ($MatchBus_F_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 22 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_F_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS F, but EMIOS channel 22 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                            [!IF "($MatchBus_F_Config = 2) or ($MatchBus_F_Config = 1) or ($MatchBus_F_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 22 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_F_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS F, but EMIOS channel 22 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                            [!IF "($MatchBus_F_Config = 1) or ($MatchBus_F_Config = 3) or ($MatchBus_F_Config = 4)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 22 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_F_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS F, but EMIOS channel 22 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                            [!IF "($MatchBus_F_Config = 1) or ($MatchBus_F_Config = 3) or ($MatchBus_F_Config = 2)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 22 should be configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                            [!ELSEIF "($MatchBus_F_Config = 0)"!]
                                [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS F, but EMIOS channel 22 has not been configured[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ELSEIF "contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_DIVERSE_U32')"!]
                        [!IF "($MaceMiosChannel < 8)"!]
                            [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_B_Config = 2) or ($MatchBus_B_Config = 3) or ($MatchBus_B_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 0 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_B_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS B, but EMIOS channel 0 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_B_Config = 2) or ($MatchBus_B_Config = 1) or ($MatchBus_B_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 0 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_B_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS B, but EMIOS channel 0 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                                [!IF "($MatchBus_B_Config = 1) or ($MatchBus_B_Config = 3) or ($MatchBus_B_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 0 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_B_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS B, but EMIOS channel 0 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                                [!IF "($MatchBus_B_Config = 1) or ($MatchBus_B_Config = 3) or ($MatchBus_B_Config = 2)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 0 should be configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_B_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS B, but EMIOS channel 0 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ELSEIF "($MaceMiosChannel < 16)"!]
                            [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_C_Config = 2) or ($MatchBus_C_Config = 3) or ($MatchBus_C_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 8 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_C_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS C, but EMIOS channel 8 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_C_Config = 2) or ($MatchBus_C_Config = 1) or ($MatchBus_C_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 8 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_C_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS C, but EMIOS channel 8 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                                [!IF "($MatchBus_C_Config = 1) or ($MatchBus_C_Config = 3) or ($MatchBus_C_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 8 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_C_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS C, but EMIOS channel 8 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                                [!IF "($MatchBus_C_Config = 1) or ($MatchBus_C_Config = 3) or ($MatchBus_C_Config = 2)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 8 should be configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_C_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS C, but EMIOS channel 8 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ELSEIF "($MaceMiosChannel < 24)"!]
                            [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_D_Config = 2) or ($MatchBus_D_Config = 3) or ($MatchBus_D_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 16 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_D_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS D, but EMIOS channel 16 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_D_Config = 2) or ($MatchBus_D_Config = 1) or ($MatchBus_D_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 16 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_D_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS D, but EMIOS channel 16 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                                [!IF "($MatchBus_D_Config = 1) or ($MatchBus_D_Config = 3) or ($MatchBus_D_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 16 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_D_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS D, but EMIOS channel 16 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                                [!IF "($MatchBus_D_Config = 1) or ($MatchBus_D_Config = 3) or ($MatchBus_D_Config = 2)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 16 should be configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_D_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS D, but EMIOS channel 16 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_E_Config = 2) or ($MatchBus_E_Config = 3) or ($MatchBus_E_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 24 should be configured to MASTER_MODE_UP_DOWN_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_E_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS E, but EMIOS channel 24 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_LEAD_DEADTIME')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMC_TRAIL_DEADTIME')))"!]
                                [!IF "($MatchBus_E_Config = 2) or ($MatchBus_E_Config = 1) or ($MatchBus_E_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 24 should be configured to MASTER_MODE_UP_DOWN_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_E_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS E, but EMIOS channel 24 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')))"!]
                                [!IF "($MatchBus_E_Config = 1) or ($MatchBus_E_Config = 3) or ($MatchBus_E_Config = 4)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 24 should be configured to MASTER_MODE_UP_BUFFERED_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_E_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS E, but EMIOS channel 24 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ELSEIF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                                [!IF "($MatchBus_E_Config = 1) or ($MatchBus_E_Config = 3) or ($MatchBus_E_Config = 2)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!] mode , so EMIOS channel 24 should be configured to MASTER_MODE_UP_COUNTER_U32[!ENDERROR!]
                                [!ELSEIF "($MatchBus_E_Config = 0)"!]
                                    [!ERROR!]Logical channel [!"$PwmChannelName"!] use BUS E, but EMIOS channel 24 has not been configured[!ENDERROR!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ENDLOOP!]
        [!ENDFOR!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Macro used to validate the offset of channel that using PWM_FIXED_PERIOD class */
    [!MACRO "ValidateOffsetPwmFixedPeriod"!]
    [!NOCODE!]
        [!LOOP "PwmChannel/*"!]
            [!IF "node:exists('PwmChannelClass')"!]
                [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMT')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
                    [!VAR "PwmChannelName" = "node:name(.)"!]
                    [!VAR "ChannelClass" = "PwmChannelClass"!]

                    [!IF "($ChannelClass = 'PWM_FIXED_PERIOD')"!]
                        [!VAR "Offset" = "node:ref(PwmeMiosChannel)/PwmOffset"!]

                        [!IF "($Offset != 0)"!]
                            [!ERROR!]
For PwmChannel_[!"$PwmChannelName"!] use PWM_FIXED_PERIOD class, so the offset phase shift must be equal 0
                            [!ENDERROR!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]


    
    /* Macro used to generate the value of the default period attribute of a PWM channel using
       eMIOS. The unit measure requested by AUTOSAR for the Default Period attribute is 'second'.
       The plug-in allows the user to introduce it either in seconds or, if plug-in field PwmPeriodInTicks
       is checked, directly in ticks. In both cases, the value is converted to ticks, because 
       this is the format used internally by the driver */
    [!MACRO "GenerateeMiosChannelPeriodInTicks", "MotorFreq"!]
    [!NOCODE!]
        [!IF "(contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_INTERNAL_COUNTER_U32') or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC')))"!]
            [!VAR "PrescalerVal" = "substring-after(node:ref(PwmeMiosChannel)/PwmPrescaler,'DIV_')"!]
            [!VAR "Period"="PwmPeriodDefault"!]
            [!VAR "PeriodMax"="65534"!]

            [!IF "PwmPeriodInTicks"!]
                [!VAR "OutPeriodTicks"="num:i($Period)"!]
            [!ELSE!]
                [!VAR "OutPeriodTicks"="num:i(num:f($Period) * ($MotorFreq div $PrescalerVal))"!]
            [!ENDIF!]

            [!IF "num:i($OutPeriodTicks) < 1"!]
                [!ERROR!]
The configured period/ticks for channel: [!"@name"!]  is smaller than 1 tick: [!"$OutPeriodTicks"!]
The plugin performs the conversion from Period to ticks if requested.
To solve this problem change the configured Period/ticks or change the Pwm Channel clock tree settings.
                [!ENDERROR!]
            [!ENDIF!]

            [!IF "num:i($OutPeriodTicks) > $PeriodMax"!]
                [!ERROR!]
The configured period/ticks for channel: [!"@name"!]  is larger than [!"$PeriodMax"!] ticks: [!"$OutPeriodTicks"!]
The plugin performs the conversion from Period to ticks if requested.
To solve this problem change the configured Period/ticks or change the Pwm Channel clock tree settings.
                [!ENDERROR!]
            [!ENDIF!]
        [!ELSE!]
            [!VAR "BusSelect"="node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!]
            [!VAR "eMiosChannel"="substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]

            [!CALL "GetMasterPeriod", "parameMiosBus" = "$BusSelect", "parameMiosChannel" = "$eMiosChannel","paramClockRef" = "$MotorFreq"!]

            [!VAR "OutPeriodTicks"="$OutPeriod"!]
        [!ENDIF!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    

    /* Macro used to generate the correspondence (translation) table between all eMios available
       channels and the indexes of channels in the array of PWM channels configured to use eMios */
    [!MACRO "GenerateeMiosHwToLogicMap", "parameMiosModule"!]
    [!NOCODE!]
        [!VAR "OutVarHwToLogicArray" = "''"!]

        [!CODE!]
        /*---------------------eMIOS_[!"num:i($parameMiosModule)"!]---------------------------*/
        [!ENDCODE!]

        [!FOR "MacCurModChannel" = "0" TO "$numeMiosChannelsPerModule - 1"!]

            /* Limit max number of configured channels to 255 */
            [!VAR "MacVarChTranslationIndex" = "255"!]

            /* Loop through all PWM channels configured to use eMIOS IP */
            [!LOOP "PwmChannel/*"!]
                /* Get indexes of EMIOS Module and Channel of current looped PWM channel */
                [!VAR "MaceMiosModule"  = "substring-after(node:ref(PwmeMiosChannel)/../../PwmeMiosModule,'eMios_')"!]
                [!VAR "MaceMiosChannel" = "substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]

                /* Check the match with the module id received as parameter */
                [!IF "num:i($MaceMiosModule) = num:i($parameMiosModule)"!]

                    /* Check the match with the channel loop var */
                    [!IF "num:i($MaceMiosChannel) = $MacCurModChannel"!]

                        /* Keep the index of the channel in the array of configured PWM channels */
                        [!VAR "MacVarChTranslationIndex" = "PwmChannelId"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ENDLOOP!]

            /* If no configured PWM channel is using the current eMIOS channel in module  */
            [!CODE!]
        (Pwm_ChannelType)[!"num:i($MacVarChTranslationIndex)"!][!//
            [!ENDCODE!]

            [!IF "($MacCurModChannel < $numeMiosChannelsPerModule - 1) or ($parameMiosModule < $numeMiosModules - 1)"!]
                [!CODE!],[!//
                [!ENDCODE!]
            [!ENDIF!]

            [!IF "$MacVarChTranslationIndex < 255"!]
                [!CODE!]
            /* eMIOS_[!"num:i($parameMiosModule)"!]_[!"num:i($MacCurModChannel)"!] */
                [!ENDCODE!]
            [!ELSE!]
                [!CODE!]
            /* eMIOS_[!"num:i($parameMiosModule)"!]_[!"num:i($MacCurModChannel)"!] unused */
                [!ENDCODE!]
            [!ENDIF!]
        [!ENDFOR!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    
    
    /* Macro used to validate each channels from an eMios module must have the same PwmMcuClockReferencePoint setting  */
    [!MACRO "ValidateMcuClockRef"!]
    [!NOCODE!]
        [!VAR "eMios_0_Clk" = "0"!]
        [!VAR "eMios_1_Clk" = "0"!]
        [!VAR "eMios_2_Clk" = "0"!]

        [!LOOP "PwmChannel/*"!]
            [!VAR "eMiosModule" = "node:ref(PwmeMiosChannel)/../../PwmeMiosModule"!]

            [!IF "$eMiosModule = 'eMios_0'"!]
                [!IF "($eMios_0_Clk != 0) and ($eMios_0_Clk != PwmMcuClockReferencePoint) "!]
                    [!ERROR!]
PwmMcuClockReferencePoint is not uniformity in eMios module 0.
Each channel from an eMios module must have the same PwmMcuClockReferencePoint setting
                    [!ENDERROR!]
                [!ELSEIF "$eMios_0_Clk = 0"!]
                    [!VAR "eMios_0_Clk" = "PwmMcuClockReferencePoint"!]
                [!ENDIF!]
            [!ENDIF!]

            [!IF "$eMiosModule = 'eMios_1'"!]
                [!IF "($eMios_1_Clk != 0) and ($eMios_1_Clk != PwmMcuClockReferencePoint) "!]
                    [!ERROR!]
PwmMcuClockReferencePoint is not uniformity in eMios module 1.
Each channel from an eMios module must have the same PwmMcuClockReferencePoint setting
                    [!ENDERROR!]
                [!ELSEIF "$eMios_1_Clk = 0"!]
                    [!VAR "eMios_1_Clk" = "PwmMcuClockReferencePoint"!]
                [!ENDIF!]
            [!ENDIF!]

            [!IF "$eMiosModule = 'eMios_2'"!]
                [!IF "($eMios_2_Clk != 0) and ($eMios_2_Clk != PwmMcuClockReferencePoint) "!]
                [!ERROR!]
PwmMcuClockReferencePoint is not uniformity in eMios module 2.
Each channel from an eMios module must have the same PwmMcuClockReferencePoint setting
                [!ENDERROR!]
                [!ELSEIF "$eMios_2_Clk = 0"!]
                    [!VAR "eMios_2_Clk" = "PwmMcuClockReferencePoint"!]
                [!ENDIF!]
            [!ENDIF!]
        [!ENDLOOP!]

    [!ENDNOCODE!]
    [!ENDMACRO!]
    
    
    
    /* Macro used to count and validate the configured PWM channels */
    [!MACRO "ValidatePwmConfiguration"!]
    [!NOCODE!]
        [!VAR "OutNumPwmChannels" = "num:i(count(PwmChannel/*))"!]
        [!VAR "OutNumPwmChannelsUsingeMios" = "0"!]
        
        [!VAR "MacOuterLoopCounter" = "0"!]
        
        [!LOOP "PwmChannel/*"!]
            [!VAR "MacOuterLoopCounter" = "$MacOuterLoopCounter + 1"!]
            
            /* Check if there are no eMIOS hardware channels referenced multiple times by same logic channels */
            [!VAR "MacInnerLoopCounter" = "0"!]
            [!VAR "MacMatchcounter" = "0"!]
            [!VAR "MacOutereMiosChannelPath" = "node:path(node:ref(./PwmeMiosChannel))"!]
            
            [!LOOP "../../../*[@index]/PwmChannel/*"!]
                [!VAR "MacInnerLoopCounter" = "$MacInnerLoopCounter + 1"!]
                
                [!IF "$MacOuterLoopCounter >= $MacInnerLoopCounter"!]
                    [!VAR "MacInnereMiosChannelPath" = "node:path(node:ref(./PwmeMiosChannel))"!]
                    
                    [!IF "($MacInnereMiosChannelPath = $MacOutereMiosChannelPath)"!]
                        [!VAR "MacMatchcounter" = "$MacMatchcounter + 1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ENDLOOP!]
            
            [!IF "$MacMatchcounter > 1"!]
                [!ERROR!]
eMIOS channel [!"$MacInnereMiosChannelPath"!] is referenced by more than one logic PWM channel.
                [!ENDERROR!] 
            [!ENDIF!]
            
            /* Update variables storing number of PWM channels using eMIOS IP */
            [!VAR "OutNumPwmChannelsUsingeMios" = "$OutNumPwmChannelsUsingeMios + 1"!]
            
        [!ENDLOOP!]
        
    [!ENDNOCODE!]
    [!ENDMACRO!]

[!ENDNOCODE!]

#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 Pwm_PBCfg_c_REF_1
* 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 Pwm_PBCfg_c_REF_2
* 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 Pwm_PBcfg_c_REF_3
* Violates MISRA 2012 Required Rule 8.4, A compatible declaration shall be visible when an object or function 
* with external linkage is defined.
*
* @section Pwm_PBcfg_c_REF_4
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its identifier only appears 
* in a single function.
*
* @section Pwm_PBcfg_c_REF_5
* 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 Pwm_PBcfg_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.
* These functions represent the API of the driver. External linkage is needed to "export" the API.
*
* @section Pwm_PBcfg_c_REF_7
* Violates MISRA 2012 Required Rule 8.5, An external object or function shall be declared once in one
* and only one file.
*
*/



/*==================================================================================================
*                                         INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/

#include "Pwm.h"

#include "Reg_eSys_eMios.h"

#include "eMios_Common_Types.h"



/*==================================================================================================
*                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/

/**
* @{
* @file           Pwm_PBcfg.c
*/
#define PWM_PB_CFG_VENDOR_ID_C                      43
#define PWM_PB_CFG_AR_RELEASE_MAJOR_VERSION_C       4
#define PWM_PB_CFG_AR_RELEASE_MINOR_VERSION_C       3
#define PWM_PB_CFG_AR_RELEASE_REVISION_VERSION_C    1
#define PWM_PB_CFG_SW_MAJOR_VERSION_C               1
#define PWM_PB_CFG_SW_MINOR_VERSION_C               0
#define PWM_PB_CFG_SW_PATCH_VERSION_C               0
/**@}*/



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

#if (PWM_PB_CFG_VENDOR_ID_C != PWM_VENDOR_ID)
    #error "Pwm_PBcfg.c and Pwm.h have different vendor ids"
#endif

#if ((PWM_PB_CFG_AR_RELEASE_MAJOR_VERSION_C    != PWM_AR_RELEASE_MAJOR_VERSION) || \
     (PWM_PB_CFG_AR_RELEASE_MINOR_VERSION_C    != PWM_AR_RELEASE_MINOR_VERSION) || \
     (PWM_PB_CFG_AR_RELEASE_REVISION_VERSION_C != PWM_AR_RELEASE_REVISION_VERSION))
    #error "AUTOSAR version numbers of Pwm_PBcfg.c and Pwm.h are different"
#endif

#if ((PWM_PB_CFG_SW_MAJOR_VERSION_C != PWM_SW_MAJOR_VERSION) || \
     (PWM_PB_CFG_SW_MINOR_VERSION_C != PWM_SW_MINOR_VERSION) || \
     (PWM_PB_CFG_SW_PATCH_VERSION_C != PWM_SW_PATCH_VERSION))
    #error "Software version numbers of Pwm_PBcfg.c and Pwm.h are different"
#endif


#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Reg_eSys_eMios.h header file are of the same vendor */
    #if (PWM_PB_CFG_VENDOR_ID_C != REG_ESYS_EMIOS_VENDOR_ID)
        #error "Pwm_PBcfg.c and Reg_eSys_eMios.h have different vendor ids"
    #endif

    /* Check if header file and Reg_eSys_eMios.h header file are of the same AUTOSAR version */
    #if ((PWM_PB_CFG_AR_RELEASE_MAJOR_VERSION_C    != REG_ESYS_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
         (PWM_PB_CFG_AR_RELEASE_MINOR_VERSION_C    != REG_ESYS_EMIOS_AR_RELEASE_MINOR_VERSION) || \
         (PWM_PB_CFG_AR_RELEASE_REVISION_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_REVISION_VERSION))
        #error "AUTOSAR version numbers of Pwm_PBcfg.c and Reg_eSys_eMios.h are different"
    #endif

    /* Check if header file and Reg_eSys_eMios.h header file are of the same software version */
    #if ((PWM_PB_CFG_SW_MAJOR_VERSION_C != REG_ESYS_EMIOS_SW_MAJOR_VERSION) || \
         (PWM_PB_CFG_SW_MINOR_VERSION_C != REG_ESYS_EMIOS_SW_MINOR_VERSION) || \
         (PWM_PB_CFG_SW_PATCH_VERSION_C != REG_ESYS_EMIOS_SW_PATCH_VERSION))
        #error "Software version numbers of Pwm_PBcfg.c and Reg_eSys_eMios.h are different"
    #endif

    /* Check if source file and eMios_Common_Types.h are of the same vendor */
    #if (PWM_PB_CFG_VENDOR_ID_C != EMIOS_COMMON_TYPES_VENDOR_ID )
        #error "Pwm_PBcfg.c and eMios_Common_Types.h have different vendor ids"
    #endif
    
    /* Check if source file and eMios_Common_Types.h are of the same AUTOSAR version */
    #if ((PWM_PB_CFG_AR_RELEASE_MAJOR_VERSION_C != EMIOS_COMMON_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         (PWM_PB_CFG_AR_RELEASE_MINOR_VERSION_C != EMIOS_COMMON_TYPES_AR_RELEASE_MINOR_VERSION) || \
         (PWM_PB_CFG_AR_RELEASE_REVISION_VERSION_C != EMIOS_COMMON_TYPES_AR_RELEASE_REVISION_VERSION))
        #error "AUTOSAR Version Numbers of Pwm_PBcfg.c and eMios_Common_Types.h are different"
    #endif
    
    /* Check if source file and eMios_Common_Types.h are of the same software version */
    #if ((PWM_PB_CFG_SW_MAJOR_VERSION_C != EMIOS_COMMON_TYPES_SW_MAJOR_VERSION) || \
         (PWM_PB_CFG_SW_MINOR_VERSION_C != EMIOS_COMMON_TYPES_SW_MINOR_VERSION) || \
         (PWM_PB_CFG_SW_PATCH_VERSION_C != EMIOS_COMMON_TYPES_SW_PATCH_VERSION))
        #error "Software Version Numbers of Pwm_PBcfg.c and eMios_Common_Types.h are different"
    #endif
#endif



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

#define PWM_START_SEC_CODE
/*
* @violates @ref Pwm_PBCfg_c_REF_2 This violation is not fixed since the inclusion
*                of Pwm_MemMap.h is as per AUTOSAR requirement 
* @violates @ref Pwm_PBCfg_c_REF_1 Pwm_MemMap.h is included after each section define
*                in order to set the current memory section as defined by AUTOSAR
*/
#include "Pwm_MemMap.h"

/* Check if source file and Pwm_MemMap.h are of the same AUTOSAR version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((PWM_PB_CFG_AR_RELEASE_MAJOR_VERSION_C != PWM_MEMMAP_AR_RELEASE_MAJOR_VERSION) || \
     (PWM_PB_CFG_AR_RELEASE_MINOR_VERSION_C != PWM_MEMMAP_AR_RELEASE_MINOR_VERSION))
    #error "AUTOSAR version numbers of Pwm_Ipw.h and Pwm_MemMap.h are different."
#endif
#endif /* DISABLE_MCAL_INTERMODULE_ASR_CHECK */

[!SELECT "PwmChannelConfigSet"!]
[!NOCODE!]

[!INCLUDE "Pwm_NotifyCheck_Src.m"!]
[!IF "../PwmGeneral/PwmNotificationSupported"!]
    [!CALL "GeneratePwmNotifications"!]
[!ENDIF!]
[!ENDNOCODE!]

#define PWM_STOP_SEC_CODE
/*
* @violates @ref Pwm_PBCfg_c_REF_2 This violation is not fixed since the inclusion
*                of Pwm_MemMap.h is as per AUTOSAR requirement 
* @violates @ref Pwm_PBCfg_c_REF_1 Pwm_MemMap.h is included after each section define
*                in order to set the current memory section as defined by AUTOSAR
*/
#include "Pwm_MemMap.h"



/*==================================================================================================
*                                       LOCAL DEFINES
==================================================================================================*/
[!NOCODE!]
    [!CALL "ValidatePwmConfiguration"!]
    
    [!CALL "ValidateOffsetPwmFixedPeriod"!]
    [!CALL "ValidatePwmBusSelection"!]
    [!CALL "ValidatePwmDaocModulo"!]
    [!CALL "ValidateMcuClockRef"!]
    
    [!VAR "PwmChannels" = "num:i(count(PwmChannel/*))"!]    
[!ENDNOCODE!]

/**
* @brief        Total number of configured PWM channels
*
*/
#define PWM_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]           ((uint8)[!"num:i($PwmChannels)"!]U)

/**
* @brief        Number of configured eMIOS channels
*
*/
#define PWM_EMIOS_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]     ((uint8)[!"num:i($OutNumPwmChannelsUsingeMios)"!]U)



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

#define PWM_START_SEC_CONFIG_DATA_UNSPECIFIED
/*
* @violates @ref Pwm_PBCfg_c_REF_2 This violation is not fixed since the inclusion
*                of Pwm_MemMap.h is as per AUTOSAR requirement 
* @violates @ref Pwm_PBCfg_c_REF_1 Pwm_MemMap.h is included after each section define
*                in order to set the current memory section as defined by AUTOSAR
*/
#include "Pwm_Memmap.h"

/*================================= Configuration for eMIOS ======================================*/

/**
* @brief        Configurations for PWM channels using eMIOS
*
*/
static CONST (Pwm_eMios_ChannelConfigType, PWM_CONST) Pwm_eMios_ChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][PWM_EMIOS_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]] =
{
    [!VAR "comma" = "1"!]
    [!FOR "varCounter" = "0" TO "$PwmChannels"!]
        [!LOOP "PwmChannel/*"!]
            [!IF "PwmChannelId = $varCounter"!]
    /* [!"node:name(.)"!] */
    {
                [!VAR "EmiosMod"     = "substring-after(node:ref(PwmeMiosChannel)/../../PwmeMiosModule,'eMios_')"!]
                [!VAR "EmiosChannel" = "substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]
        /** @brief  PWM channel polarity */
        [!"PwmPolarity"!],
        /** @brief  PWM channel idle state */
        [!"PwmIdleState"!],
        /** @brief  Default duty cycle value */
        (uint16)[!"num:inttohex(PwmDutycycleDefault,4)"!]U,
                [!VAR "McuClockRefValue"="node:ref(PwmMcuClockReferencePoint)/McuClockReferencePointFrequency"!]
                [!CALL "GenerateeMiosChannelPeriodInTicks", "MotorFreq" = "$McuClockRefValue"!]
        /** @brief  Default period value */
        (Pwm_PeriodType)[!"num:i($OutPeriodTicks)"!]U,
        /** @brief  eMIOS hardware module and channel */
        EMIOS_[!"$EmiosMod"!]_CH_[!"$EmiosChannel"!],
        /** @brief  eMIOS channel configuration parameters */
                [!IF "(contains(node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect,'PWM_BUS_INTERNAL_COUNTER_U32'))"!]
                    [!VAR "PrescalerVal" = "substring-after(node:ref(PwmeMiosChannel)/PwmPrescaler,'DIV_')"!]
                    [!IF "../../../PwmGeneral/PwmEnableDualClockMode"!]
                        [!VAR "PrescalerVal_Alternate" = "substring-after(node:ref(PwmeMiosChannel)/PwmPrescaler_Alternate,'DIV_')"!]
                    [!ENDIF!]
                [!ELSE!]
                    [!VAR "BusSelect"="node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!]
                    [!VAR "eMiosChannel"="substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!]
                    [!CALL "GetMasterPeriod", "parameMiosBus" = "$BusSelect", "parameMiosChannel" = "$eMiosChannel", "paramClockRef" = "$McuClockRefValue"!]
                    [!IF "../../../PwmGeneral/PwmEnableDualClockMode"!]
                        [!CALL "GetMasterPeriod_Alternate", "parameMiosBus" = "$BusSelect", "parameMiosChannel" = "$eMiosChannel"!]
                    [!ENDIF!]
                [!ENDIF!]
        (Pwm_eMios_ControlType)([!"node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!] | [!"node:ref(PwmeMiosChannel)/PwmModeSelect"!][!//
                [!IF "node:ref(PwmeMiosChannel)/PwmFreezeEnable"!] | PWM_FREEZE_ENABLE_U32[!ENDIF!][!//
                [!IF "../../../PwmGeneral/PwmEnableDualClockMode"!]
                    [!IF "num:i($PrescalerVal_Alternate) = 1"!] | (PWM_PRES_1_U32 >> 0x3U)[!//
                    [!ELSEIF "num:i($PrescalerVal_Alternate) = 2"!] | (PWM_PRES_2_U32 >> 0x3U)[!//
                    [!ELSEIF "num:i($PrescalerVal_Alternate) = 3"!] | (PWM_PRES_3_U32 >> 0x3U)[!//
                    [!ELSEIF "num:i($PrescalerVal_Alternate) = 4"!] | (PWM_PRES_4_U32 >> 0x3U)[!//
                    [!ELSE!] | 0UL[!//
                    [!ENDIF!]
                [!ENDIF!]
                [!IF "num:i($PrescalerVal) = 1"!] | (PWM_PRES_1_U32)[!//
                [!ELSEIF "num:i($PrescalerVal) = 2"!] | (PWM_PRES_2_U32)[!//
                [!ELSEIF "num:i($PrescalerVal) = 3"!] | (PWM_PRES_3_U32)[!//
                [!ELSEIF "num:i($PrescalerVal) = 4"!] | (PWM_PRES_4_U32)[!//
                [!ELSE!] | 0UL[!//
                [!ENDIF!] ),
        /** @brief  Offset value for OPWMB and OPWM mode */
                [!IF "((contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMB')) or (contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWM_')))"!]
        (Pwm_PeriodType)[!"node:ref(PwmeMiosChannel)/PwmOffset"!]U,
                [!ELSE!]
        (Pwm_PeriodType)0U,
                [!ENDIF!]
        /** @brief  Master mode used */
                [!VAR "BusSelect"="node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!][!//
                [!VAR "eMiosChannel"="substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!][!//
                [!CALL "GetMasterMode", "parameMiosBus" = "$BusSelect", "parameMiosChannel" = "$eMiosChannel"!]
        (uint8)[!"$MasterBusMode"!],
#if (PWM_FEATURE_DAOC == STD_ON)
        /** @brief  Default period value for DAOC mode */
                [!IF "(contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'DAOC'))"!]
                    [!VAR "BusSelect"="node:ref(PwmeMiosChannel)/EmiosUnifiedChannelBusSelect"!][!//
                    [!VAR "eMiosChannel"="substring-after(node:ref(PwmeMiosChannel)/PwmeMiosChannel,'Channel_')"!][!//
                    [!CALL "GetDaocModulo", "parameMiosBus" = "$BusSelect", "parameMiosChannel" = "$eMiosChannel", "paramClockRef" = "$McuClockRefValue"!]
        (Pwm_PeriodType)[!"num:i($PwmDaocModulo)"!]U,
                [!ELSE!]
        (Pwm_PeriodType)0U,
                [!ENDIF!]
#endif
#if (PWM_FEATURE_OPWMT == STD_ON)
        /** @brief  Trigger delay value for OPWMT mode */
        (Pwm_PeriodType)0U,
#endif
#if (PWM_FEATURE_OPWMCB == STD_ON)
        /** @brief  Deadtime value for OPWMCB mode */
                [!IF "(contains(node:ref(PwmeMiosChannel)/PwmModeSelect,'OPWMCB'))"!]
        (uint16)[!"node:ref(PwmeMiosChannel)/Pwm_Deadtime"!]U,
                [!ELSE!]
        (uint16)0U,
                [!ENDIF!]
#endif
        /** @brief  Offset recalculated when master bus changed, for OPWMB and OPWM mode */
        (boolean)[!IF "node:ref(PwmeMiosChannel)/OffsetDelayAdjust"!]TRUE[!ELSE!]FALSE[!ENDIF!][!CR!]
    }[!IF "(num:i($comma))<(num:i($OutNumPwmChannelsUsingeMios))"!],[!ENDIF!][!CR!][!VAR "comma"="$comma + 1"!]
            [!ENDIF!]
        [!ENDLOOP!]
    [!ENDFOR!]
};



/**
* @brief        eMIOS IP configuration
*
*/
static CONST (Pwm_eMios_IpConfigType, PWM_CONST) Pwm_eMios_IpConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
{
    /** @brief  Number of eMIOS channels in the PWM configuration */
    (uint8)[!"num:i($OutNumPwmChannelsUsingeMios)"!]U,
    /** @brief  Pointer to the array of eMIOS enabled PWM channel configurations */
    &Pwm_eMios_ChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!]
};



/*============================== IP Wrapper configuration ===================================*/

/**
* @brief        Array of configured PWM channels 
*
*/
static CONST (Pwm_ChannelConfigType, PWM_CONST) Pwm_Channels_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][PWM_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]] =
{
[!NOCODE!]
    [!FOR "PwmChIndex" = "0" TO "$PwmChannels - 1"!]
        [!LOOP "PwmChannel/*"!]
            [!VAR "ChannelName" = "node:name(.)"!]

            [!IF "$PwmChIndex = PwmChannelId"!]
                [!IF "node:exists(PwmChannelClass)"!]
                    [!VAR "ChannelClass" = "node:value(PwmChannelClass)"!]
                [!ELSE!]
                    [!VAR "ChannelClass" = "'PWM_FIXED_PERIOD'"!]
                [!ENDIF!]

                [!IF "(node:exists('PwmNotification')) and ((PwmNotification != '"NULL_PTR"') and (PwmNotification != 'NULL_PTR') and (PwmNotification != '"NULL"') and (PwmNotification != 'NULL'))"!]
                    [!VAR "NotifFunc" = "concat('&', PwmNotification)"!]
                [!ELSE!]
                    [!VAR "NotifFunc" = "'NULL_PTR'"!]
                [!ENDIF!]

                [!BREAK!]
            [!ENDIF!]
        [!ENDLOOP!]

[!CODE!]
    /* [!"$ChannelName"!] */
    {
        /** @brief  Channel class */
        [!"$ChannelClass"!]
#if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
        ,
        /** @brief  PWM notification function */
        [!"$NotifFunc"!]
#endif
        [!IF "$PwmChIndex < $PwmChannels - 1"!]
    },
        [!ELSE!]
    }
        [!ENDIF!]
[!ENDCODE!]

    [!ENDFOR!]
[!ENDNOCODE!]
};



/**
* @brief        PWM channels IP related configuration array
*
*/
static CONST (Pwm_IpChannelConfigType, PWM_CONST) Pwm_IpChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][PWM_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]] =
{
    [!VAR "curPwmChannelUsingeMios" = "0"!]
    [!VAR "comma" = "1"!]
    [!VAR "MaxChCount" = "(count(PwmChannel/*))"!]
    [!FOR "varCounter" = "0" TO "num:i($MaxChCount)"!]
        [!LOOP "PwmChannel/*"!]
            [!IF "PwmChannelId = $varCounter"!]
    /* [!"@name"!] */
    {
        /** @brief  Index in the configuration table of the eMIOS channels */
        (uint8)[!"num:i($curPwmChannelUsingeMios)"!]
                [!VAR "curPwmChannelUsingeMios" = "$curPwmChannelUsingeMios + 1"!]
    }[!IF "(num:i($comma))<(num:i($MaxChCount))"!],[!ENDIF!][!VAR "comma"="$comma + 1"!][!CR!]
            [!ENDIF!]
        [!ENDLOOP!]
    [!ENDFOR!]
};



/*============================== High level configuration ===================================*/

/**
* @brief        PWM high level configuration structure
*
*/
[!IF "((../IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (../IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!]
/*
* @violates @ref Pwm_PBcfg_c_REF_6 Objects need external linkage in order to be called
*                as callbacks from the external (e.g. MCL) module.
*/
CONST(Pwm_ConfigType, Pwm_CONST) [!"as:name(.)"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
[!ELSE!]
/*
* @violates @ref Pwm_PBcfg_c_REF_3 A compatible declaration shall be visible when an object or function 
*                with external linkage is defined
* @violates @ref Pwm_PBcfg_c_REF_4 An object should be defined at block scope if its identifier only appears 
*                in a single function 
* @violates @ref Pwm_PBcfg_c_REF_6 Objects need external linkage in order to be called
*                as callbacks from the external (e.g. MCL) module.
*/
CONST(Pwm_ConfigType, Pwm_CONST) Pwm_PBCfgVariantPredefined =
[!ENDIF!]
{
    /** @brief  Number of configured PWM channels */
    (Pwm_ChannelType)PWM_CONF_CHANNELS_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /** @brief  Pointer to array of PWM channels */
    &Pwm_Channels_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /** @brief  IP specific configuration */
    {
        /** @brief  Pointer to the structures containing eMIOS configuration */
        &Pwm_eMios_IpConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
        /** @brief  Pointer to array containing channel IP related information */
        &Pwm_IpChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!]
    }
#if (PWM_NOTIFICATION_SUPPORTED == STD_ON)
    ,
    /** @brief  Hardware to logic channel map. Array containing a number of elements
                equal to total number of available channels on all IP. */
    {
[!FOR "idx" = "0" TO "$numeMiosModules - 1"!]
    [!CALL "GenerateeMiosHwToLogicMap", "parameMiosModule" = "$idx"!]
    [!"$OutVarHwToLogicArray"!]
[!ENDFOR!][!CR!]
    }
#endif
};

[!ENDSELECT!]

#define PWM_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/*
* @violates @ref Pwm_PBCfg_c_REF_2 This violation is not fixed since the inclusion
*                of Pwm_MemMap.h is as per AUTOSAR requirement 
* @violates @ref Pwm_PBCfg_c_REF_1 Pwm_MemMap.h is included after each section define
*                in order to set the current memory section as defined by AUTOSAR
*/
#include "Pwm_Memmap.h"



#ifdef __cplusplus
}
#endif

/** @} */

[!ENDCODE!]
