[!/* *** multiple inclusion protection *** */!]
[!IF "not(var:defined('ADC_REGOPERATIONS_M'))"!]
[!VAR "ADC_REGOPERATIONS_M"="'true'"!]
[!NOCODE!][!//
/**
*   @file    Adc_RegOperations.m
*   @version 1.0.0
*
*   @brief   AUTOSAR Adc - version check macro.
*   @details Version checks.
*
*   @addtogroup ADC
*   @{
*/

/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : EQADC
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

[!ENDNOCODE!][!//
[!MACRO "HWRESOURCE" , "SOURCE"!]
    [!NOCODE!]
        [!IF "contains($SOURCE,'RTI')"!]
            [!CODE!][!"num:i(1)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'PIT0')"!]
            [!CODE!][!"num:i(2)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'PIT1')"!]
            [!CODE!][!"num:i(3)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'PIT2')"!]
            [!CODE!][!"num:i(4)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'PIT3')"!]
            [!CODE!][!"num:i(5)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUA28')"!]
            [!CODE!][!"num:i(12)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUA29')"!]
            [!CODE!][!"num:i(13)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUA30')"!]
            [!CODE!][!"num:i(14)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUA31')"!]
            [!CODE!][!"num:i(15)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUB28')"!]
            [!CODE!][!"num:i(16)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUB29')"!]
            [!CODE!][!"num:i(17)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUB30')"!]
            [!CODE!][!"num:i(18)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUB31')"!]
            [!CODE!][!"num:i(19)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUC28')"!]
            [!CODE!][!"num:i(20)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUC29')"!]
            [!CODE!][!"num:i(21)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUC30')"!]
            [!CODE!][!"num:i(22)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eTPUC31')"!]
            [!CODE!][!"num:i(23)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_16')"!]
            [!CODE!][!"num:i(24)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_17')"!]
            [!CODE!][!"num:i(25)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_18')"!]
            [!CODE!][!"num:i(26)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_19')"!]
            [!CODE!][!"num:i(27)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_20')"!]
            [!CODE!][!"num:i(28)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_21')"!]
            [!CODE!][!"num:i(29)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_22')"!]
            [!CODE!][!"num:i(30)"!][!ENDCODE!]
        [!ELSEIF "contains($SOURCE,'eMIOS0_23')"!]
            [!CODE!][!"num:i(31)"!][!ENDCODE!]
        [!ENDIF!]
    
        [!IF "contains($SOURCE,'FIFO0')"!]
            [!IF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eTPUA30')"!]
                [!CODE!][!"num:i(32)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_2')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]

        [!IF "contains($SOURCE,'FIFO1')"!]
            [!IF "contains($SOURCE,'eTPUA7')"!]
                [!CODE!][!"num:i(6)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_3')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]
        
        [!IF "contains($SOURCE,'FIFO2')"!]
            [!IF "contains($SOURCE,'eTPUA14')"!]
                [!CODE!][!"num:i(6)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eTPUA29')"!]
                [!CODE!][!"num:i(32)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_7')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]
        
        [!IF "contains($SOURCE,'FIFO3')"!]
            [!IF "contains($SOURCE,'eTPUA22')"!]
                [!CODE!][!"num:i(6)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eTPUA28')"!]
                [!CODE!][!"num:i(32)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_6')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]
        
        [!IF "contains($SOURCE,'FIFO4')"!]
            [!IF "contains($SOURCE,'eTPUA30')"!]
                [!CODE!][!"num:i(6)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eTPUA27')"!]
                [!CODE!][!"num:i(32)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_5')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]
        
        [!IF "contains($SOURCE,'FIFO5')"!]
            [!IF "contains($SOURCE,'ETRIG0')"!]
                [!CODE!][!"num:i(7)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eTPUA26')"!]
                [!CODE!][!"num:i(32)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'eMIOS1_4')"!]
                [!CODE!][!"num:i(64)"!][!ENDCODE!]
            [!ELSEIF "contains($SOURCE,'ETRIG1')"!]
                [!CODE!][!"num:i(96)"!][!ENDCODE!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDNOCODE!]
[!ENDMACRO!]
[!ENDIF!]

[!MACRO "Adc_Group_Define"!][!//
/**
* @brief          Total number of groups in Config.
*
*/
#define ADC_GROUPS[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]           [!"num:i(count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*))"!]
[!ENDMACRO!]
    
[!MACRO "Adc_Notification_Config"!][!//
[!IF "AdcGeneral/AdcGrpNotifCapability = 'true'"!][!//
/**
* @brief         ADC Notification functions.
* @details       ADC Nofification functions defined inside the Plugin.
*
*/
[!FOR "x" = "0" TO "count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)-1"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*/AdcGroup/*"!][!//
[!IF "$x = AdcGroupId"!][!//
[!IF "node:exists(AdcNotification) and (AdcNotification != 'NULL_PTR')"!][!//
[!IF "text:uniq(../../../../../../AdcConfigSet/AdcHwUnit/*/AdcGroup/*[AdcGroupId <= $x]/AdcNotification, ./AdcNotification)"!][!//
/** @violates @ref Adc_PBcfg_c_REF_3 An external object or function shall be declared once in one and only one file. */
extern void [!"AdcNotification"!](void);
[!ENDIF!][!//
[!ENDIF!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!ENDFOR!][!//
[!ENDIF!][!//
[!ENDMACRO!][!//

[!MACRO "Adc_Group_Assignments"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
/**
* @brief          Group Assignments on ADC Hardware unit [!"$Unit"!][!IF "var:defined('postBuildVariant')"!] [!"$postBuildVariant"!][!ENDIF!].
*
*/
[!FOR "x" = "0" TO "count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)-1"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*/AdcGroup/*"!][!//
[!IF "$x = AdcGroupId"!][!//
[!IF "../../AdcHwUnitId = concat('ADC',string($Unit))"!][!//
static CONST(Adc_ChannelType, ADC_CONST) Adc_Group[!"AdcGroupId"!]_Assignment_[!"$Unit"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][ADC_CFGSET[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_GROUP_[!"AdcGroupId"!]_CHANNELS] =
{
[!VAR "MAX_COUNT" = "count(AdcGroupDefinition/*)-1"!][!//
[!VAR "CRT_COUNT" = "0"!][!//
[!LOOP "AdcGroupDefinition/*"!][!//
[!VAR "CurrAdcChannel" = "."!][!//
[!VAR "CurrAdcChannel1" = "substring-after(substring-after(substring-after(substring-after(substring-after($CurrAdcChannel,'/'),'/'),'/'),'/'),'/')"!][!//
[!LOOP "../../../../AdcChannel/*"!][!//
[!IF "@name = $CurrAdcChannel1"!][!//
    [!"AdcLogicalChannelId"!]U[!IF "$CRT_COUNT < $MAX_COUNT"!],[!ELSE!][!ENDIF!]
[!ENDIF!][!//
[!ENDLOOP!][!//
[!VAR "CRT_COUNT" = "$CRT_COUNT + 1"!][!//
[!ENDLOOP!][!//
};
[!ENDIF!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!ENDFOR!][!//
[!ENDFOR!][!//
[!ENDMACRO!][!//

[!MACRO "Adc_ResultBuffer_Config"!][!//
/**
* @brief          Adc Result Buffer RAM initializations.
* @details        Array for all ADC group result ram buffers.
*/
[!VAR "MAX_NUM"="count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)"!][!//
static P2VAR(Adc_ValueGroupType, ADC_VAR, ADC_APPL_DATA) Adc_ResultsBufferPtr[] =
{
[!FOR "x" = "1" TO "$MAX_NUM"!][!//
    NULL_PTR[!IF "$x<$MAX_NUM"!],[!ENDIF!]
[!ENDFOR!][!//
};
[!ENDMACRO!][!//

[!MACRO "Adc_Channel_Pointer_Config"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
/**
* @brief          Definition of channels's pointer structure [!IF "var:defined('postBuildVariant')"!] [!"$postBuildVariant"!] [!ENDIF!].
*
*/
static P2CONST(Adc_Eqadc_ChannelConfigurationType, ADC_VAR, ADC_APPL_CONST) Adc_ChannelsCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][] =
{
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
[!VAR "UnitExits" = "0"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
[!IF "AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!VAR "UnitExits"="$UnitExits+1"!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!IF "$UnitExits = 0"!][!//
    NULL_PTR[!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ELSE!][!//
    Adc_ChannelsCfg_[!"$Unit"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDIF!][!//
[!ENDFOR!][!//
};
[!ENDMACRO!][!//

[!MACRO "Adc_Channel_LimitChecking_Pointer_Config"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
#if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
/**
* @brief          Definition of channels' limit checking pointer structure.
*
*/
P2CONST(Adc_Eqadc_ChannelLimitCheckingType, ADC_VAR, ADC_APPL_CONST) Adc_aChannelsLimitCheckingCfg[]=
{
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
[!VAR "UnitExits" = "0"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
[!IF "AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!VAR "UnitExits"="$UnitExits+1"!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!IF "$UnitExits = 0"!][!//
    NULL_PTR[!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ELSE!][!//
    Adc_aChannelsLimitCheckingCfg_[!"$Unit"!][!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDIF!][!//
[!ENDFOR!][!//
};
#endif
[!ENDMACRO!][!//

[!MACRO "Adc_HwUnit_Config"!][!//
/**
* @brief          Definition of ADC Hw units for Configuration variant [!IF "var:defined('postBuildVariant')"!] [!"$postBuildVariant"!][!ENDIF!].
*/
static CONST(Adc_Eqadc_HwUnitConfigurationType, ADC_CONST) Adc_HwUnitCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][] =
{
[!VAR "MAX_COUNT"="count(AdcConfigSet/AdcHwUnit/*) - 1"!][!//
[!FOR "Unit" = "0" TO "num:i($MAX_COUNT)"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
[!IF "AdcLogicalUnitId = $Unit"!][!//
[!CODE!][!//
    /**< @brief Hardware Unit [!"AdcHwUnitId"!] */
    {
        /**< @brief Hardware unit id */
        (Adc_HwUnitType)[!"substring-after(string(AdcHwUnitId),'ADC')"!],
        (EQADC_ADC_EN_U16[!IF "node:exists(AdcExternalMultiplexing) and AdcExternalMultiplexing = 'true'"!] | EQADC_ADC_EMUX_U16[!ENDIF!][!IF "node:exists(AdcClockSource) and AdcClockSource = 'CLK_SRC_0'"!]| EQADC_ADC_CLK_PS_[!IF "node:exists(AdcPrescale)"!][!"AdcPrescale"!][!ELSE!]31[!ENDIF!]_U8[!ELSE!] | EQADC_ADC_CLK_SEL_U8[!ENDIF!]),
        /**< @brief Adc resolution */
        [!IF "AdcResolution = 'BITS_8'"!]ADC_BITS_RESOLUTION_8_U8[!ELSEIF "AdcResolution = 'BITS_10'"!]ADC_BITS_RESOLUTION_10_U8[!ELSEIF "AdcResolution = 'BITS_12'"!]ADC_BITS_RESOLUTION_12_U8[!ENDIF!]
#if (ADC_CALIBRATION == STD_ON)
        ,
        (boolean)[!IF "AdcCalibration"!]TRUE[!ELSE!]FALSE[!ENDIF!] /**< @brief calibration is/isn't performed  */
#endif /* (ADC_CALIBRATION == STD_ON) */
#if (ADC_DUAL_CLOCK_MODE == STD_ON)
        ,
        (EQADC_ADC_EN_U16[!IF "node:exists(AdcExternalMultiplexing) and AdcExternalMultiplexing = 'true'"!] | EQADC_ADC_EMUX_U16[!ENDIF!][!IF "node:exists(AdcClockSource) and AdcClockSource = 'CLK_SRC_0'"!]| EQADC_ADC_CLK_PS_[!IF "node:exists(AdcAltPrescale)"!][!"AdcAltPrescale"!][!ELSE!]31[!ENDIF!]_U8[!ELSE!] | EQADC_ADC_CLK_SEL_U8[!ENDIF!])
#endif /* (ADC_DUAL_CLOCK_MODE == STD_ON) */

    }[!IF "$Unit<$MAX_COUNT"!],[!ENDIF!]
[!ENDCODE!][!//
[!BREAK!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!ENDFOR!][!//
};
[!ENDMACRO!][!//

[!MACRO "Adc_Channel_Config"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
[!VAR "LoopVar"="0"!][!//
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
[!VAR "UnitExits" = "0"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
[!IF "AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!VAR "UnitExits"="1"!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!IF "$UnitExits = 1"!][!//
[!VAR "LoopVar"="0"!][!//
/**
* @brief          Definition of channels on ADC Hardware unit for configuration variant [!IF "var:defined('postBuildVariant')"!][!"$postBuildVariant"!][!ENDIF!].
* @details        Array of conversion command messages
*/
static CONST(Adc_Eqadc_ChannelConfigurationType, ADC_CONST) Adc_ChannelsCfg_[!"$Unit"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][] =
{
[!VAR "numChannel" = "num:i(count(AdcConfigSet/AdcHwUnit/*[AdcHwUnitId=concat('ADC',string($Unit))]/AdcChannel/*)-1)"!]
[!FOR "x" = "0" TO "$numChannel"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*[AdcHwUnitId=concat('ADC',string($Unit))]/AdcChannel/*"!][!//
[!VAR "Loop"="num:i($LoopVar)"!][!//
[!IF "../../AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!IF "AdcLogicalChannelId = $Loop"!][!//
    /**< @brief Hardware Unit [!"../../AdcHwUnitId"!]  --  [!"AdcChannelId"!] */
    {
        /**< @brief Adc channel's command */
        (uint32)(EQADC_ADC_CONV_COM_BN[!"num:i($Unit mod 2)"!]_U32 [!IF "AdcChannelCalibration = 'true'"!] | EQADC_ADC_CONV_COM_CAL_U32 [!ENDIF!] | [!IF "node:exists(AdcChannelSampTime)"!][!IF "AdcChannelSampTime = '0'"!]EQADC_ADC_2_CLOCK_CYCLES_U32[!ELSEIF "AdcChannelSampTime = '1'"!]EQADC_ADC_8_CLOCK_CYCLES_U32[!ELSEIF "AdcChannelSampTime = '2'"!]EQADC_ADC_64_CLOCK_CYCLES_U32[!ELSE!]EQADC_ADC_128_CLOCK_CYCLES_U32[!ENDIF!][!ELSE!]EQADC_ADC_128_CLOCK_CYCLES_U32[!ENDIF!]| EQADC_ADC_CONV_COM_FMT_RJU_U32 | ((uint32)ADC_ID_CHANNEL_U8([!"substring-after(AdcChannelId,'AN_')"!])<<8U) | (uint32)[!IF "../../AdcResolution = 'BITS_8'"!]EQADC_8BIT_RES_CONFIG_SEL_U16[!ELSEIF "../../AdcResolution = 'BITS_10'"!]EQADC_10BIT_RES_CONFIG_SEL_U16[!ELSEIF "../../AdcResolution = 'BITS_12'"!]EQADC_12BIT_RES_CONFIG_SEL_U16[!ENDIF!])
    }[!IF "$x < $numChannel"!],[!ENDIF!]
[!ENDIF!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!VAR "LoopVar"="$LoopVar + 1"!][!//
[!ENDFOR!][!//
};
[!ENDIF!][!//
[!ENDFOR!][!//
[!ENDMACRO!][!//

[!MACRO "Adc_Channel_LimitChecking_Config"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
[!VAR "LoopVar"="0"!][!//
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
[!VAR "UnitExits" = "0"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
[!IF "AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!VAR "UnitExits"="$UnitExits+1"!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!IF "$UnitExits = 1"!][!//
[!VAR "LoopVar"="0"!][!//
#if (ADC_ENABLE_LIMIT_CHECK == STD_ON)
/**
* @brief          Definition of channels limit checking on ADC Hardware unit [!"$Unit"!].
*/
static CONST(Adc_Eqadc_ChannelLimitCheckingType, ADC_CONST) Adc_aChannelsLimitCheckingCfg_[!"$Unit"!][] =
{
[!VAR "numChannel" = "num:i(count(AdcConfigSet/AdcHwUnit/*[AdcHwUnitId=concat('ADC',string($Unit))]/AdcChannel/*)-1)"!][!//
[!FOR "x" = "0" TO "$numChannel"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*[AdcHwUnitId=concat('ADC',string($Unit))]/AdcChannel/*"!][!//
[!VAR "Loop"="num:i($LoopVar)"!][!//
[!IF "../../AdcHwUnitId = concat('ADC',string($Unit))"!][!//
[!IF "AdcLogicalChannelId = $Loop"!][!//
    /**< @brief Hardware Unit [!"../../AdcHwUnitId"!]  --  [!"AdcChannelId"!] */
    {
[!IF "node:exists(AdcChannelLimitCheck) and AdcChannelLimitCheck ='true'"!][!//
        /**< @brief limit check enabled */
        (boolean)TRUE,
        /**< @brief range for limit check */
[!IF "node:exists(AdcChannelRangeSelect)"!][!//
        [!"AdcChannelRangeSelect"!],
[!ELSE!][!//
        ADC_RANGE_ALWAYS,
[!ENDIF!][!//
        /**< @brief high limit value */
[!IF "node:exists(AdcChannelHighLimit)"!][!//
        (Adc_ValueGroupType)[!"num:i(AdcChannelHighLimit)"!],
[!ELSE!][!//
        (Adc_ValueGroupType)0,
[!ENDIF!][!//
        /**< @brief low limit value */
[!IF "node:exists(AdcChannelLowLimit)"!][!//
        (Adc_ValueGroupType)[!"num:i(AdcChannelLowLimit)"!]
[!ELSE!][!//
        (Adc_ValueGroupType)0,
[!ENDIF!][!//
[!ELSE!][!//
        /**< @brief limit check disabled */
        (boolean)FALSE,
        /**< @brief range for limit check */
        ADC_RANGE_ALWAYS,
        /**< @brief high limit value */
        (Adc_ValueGroupType)0,
        /**< @brief low limit value */
        (Adc_ValueGroupType)0
[!ENDIF!][!//

    }[!IF "$x < $numChannel"!],[!ELSE!][!ENDIF!]
[!ENDIF!][!//
[!ENDIF!][!//
[!ENDLOOP!][!//
[!VAR "LoopVar"="$LoopVar + 1"!][!//
[!ENDFOR!][!//
};
#endif /* (ADC_ENABLE_LIMIT_CHECK == STD_ON) */
[!ENDIF!][!//
[!ENDFOR!][!//
[!ENDMACRO!][!//


[!MACRO "Adc_HwTriggerSource_Config"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*/AdcGroup/*"!][!//
[!IF "AdcGroupTriggSrc = 'ADC_TRIGG_SRC_HW'"!][!//
/**
* @brief          Hardware trigger sources configured for group [!"AdcGroupId"!]- for configuration variant [!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!].
* 
*/
static CONST(Adc_HwTriggerTimerType, ADC_CONST) Adc_GroupTriggerSource[!"AdcGroupId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][1] =
{
[!IF "node:exists(AdcHwTrigSrc)"!][!//
[!VAR "HWRES"!][!CALL "HWRESOURCE" , "SOURCE" = "AdcHwTrigSrc"!][!ENDVAR!][!//
[!ELSE!][!//
[!IF "node:exists(AdcGroupFifo)"!][!//
[!VAR "HWRES"!][!CALL "HWRESOURCE" , "SOURCE" = "string(ecu:list(concat(concat('Adc.AdcConfigSet.AdcHwUnit.AdcGroup.Fifo',substring-after(string(AdcGroupFifo),'ADC_FIFO_')),'.AdcHwTrigSrc'))[1])"!][!ENDVAR!][!//
[!ELSE!][!//
[!VAR "HWRES"!][!CALL "HWRESOURCE" , "SOURCE" = "'FIFO0_RTI'"!][!ENDVAR!][!//
[!ENDIF!][!//
[!ENDIF!][!//
    (Adc_HwTriggerTimerType)[!"num:i(number($HWRES))"!]U
};
[!ENDIF!][!//
[!ENDLOOP!][!//
[!ENDMACRO!][!//

[!MACRO "Adc_Group_Config"!][!//
[!VAR "LoopVar"="0"!][!//
/**
* @brief          Definition of all ADC groups [!IF "var:defined('postBuildVariant')"!][!"$postBuildVariant"!][!ENDIF!].
*/
static CONST(Adc_GroupConfigurationType, ADC_CONST) Adc_GroupsCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][] =
{
[!FOR "x" = "0" TO "num:i(count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)-1)"!][!//
[!LOOP "AdcConfigSet/AdcHwUnit/*/AdcGroup/*"!][!//
[!VAR "Loop"="num:i($LoopVar)"!][!//
[!IF "AdcGroupId = $Loop"!][!//
    /**< @brief Group[!"AdcGroupId"!] -- Hardware Unit [!"../../AdcHwUnitId"!] */
    {
        /**< @brief Hardware unit configured */
        (Adc_HwUnitType)[!"substring-after(string(../../AdcHwUnitId),'ADC')"!],
        /**< @brief Access mode */
        [!"AdcGroupAccessMode"!],
        /**< @brief Conversion mode */
        [!"AdcGroupConversionMode"!],
        /**< @brief Conversion type */
        [!"AdcGroupConversionType"!],
#if (ADC_PRIORITY_IMPLEMENTATION != ADC_PRIORITY_NONE)
        /**< @brief  Priority configured */
        [!IF "../../../../../AdcGeneral/AdcPriorityImplementation != 'ADC_PRIORITY_NONE'"!]ADC_GROUP_PRIORITY([!"AdcGroupPriority"!]),[!ELSE!]ADC_GROUP_PRIORITY(0U),[!ENDIF!]
#endif /* (ADC_PRIORITY_IMPLEMENTATION != ADC_PRIORITY_NONE) */
        /**< @brief Replacement mode */
        ADC_GROUP_REPL_ABORT_RESTART,
        /**< @brief Trigger source configured */
        [!"AdcGroupTriggSrc"!],
#if (STD_ON==ADC_HW_TRIGGER_API)
        /**< @brief Hardware trigger signal */
        [!IF "(../../../../../AdcGeneral/AdcHwTriggerApi = 'true') and (AdcGroupTriggSrc = 'ADC_TRIGG_SRC_HW') and node:exists(AdcHwTrigSignal)"!][!"AdcHwTrigSignal"!],[!ELSE!]ADC_HW_TRIG_RISING_EDGE,[!ENDIF!]
        /**< @brief Hardware resource for the group */
        [!IF "(../../../../../AdcGeneral/AdcHwTriggerApi = 'true') and (AdcGroupTriggSrc = 'ADC_TRIGG_SRC_HW')"!]Adc_GroupTriggerSource[!"AdcGroupId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],[!ELSE!]NULL_PTR,[!ENDIF!]
#endif /* (STD_ON==ADC_HW_TRIGGER_API) */
#if (STD_ON==ADC_GRP_NOTIF_CAPABILITY)
        /**< @brief Notification function */
[!IF "../../../../../AdcGeneral/AdcGrpNotifCapability = 'true' and node:exists(AdcNotification)"!][!//
        [!IF "AdcNotification != 'NULL_PTR'"!]&[!"AdcNotification"!],[!ELSE!][!"AdcNotification"!],[!ENDIF!]
[!ELSE!]
        NULL_PTR,
[!ENDIF!][!//
#endif /* (STD_ON==ADC_GRP_NOTIF_CAPABILITY) */
        /**< @brief CFIFO used for group */
[!IF "node:exists(AdcGroupFifo)"!][!//
        [!"substring-after(AdcGroupFifo,'ADC_FIFO_')"!]U,
[!ELSE!][!//
        0U,
[!ENDIF!][!//
        /**< @brief ADC Group Result Buffers RAM array */
        Adc_ResultsBufferPtr,
        /**< @brief Group Streaming Buffer Mode */
        [!"AdcStreamingBufferMode"!],
        /**< @brief Number of streaming samples */
        ADC_STREAMING_NUM_SAMPLES([!"AdcStreamingNumSamples"!]),
        /**< @brief Channels assigned to the group */
        Adc_Group[!"AdcGroupId"!]_Assignment_[!"num:i(substring-after(../../AdcHwUnitId, 'ADC'))"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
        /**< @brief Number of channels in the group */
        (Adc_ChannelIndexType)ADC_CFGSET[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_GROUP_[!"AdcGroupId"!]_CHANNELS,
        /**< @brief Enables or Disables the ADC and DMA interrupts */
        (uint8)[!IF "AdcWithoutInterrupts = 'true' "!]STD_ON[!ELSE!]STD_OFF[!ENDIF!]
#ifdef ADC_ENABLE_DOUBLE_BUFFERING
#if (STD_ON == ADC_ENABLE_DOUBLE_BUFFERING)
        ,
        /**< @brief Enables or Disables the ADC double buffering feature */
        (boolean)[!IF "AdcEnableDoubleBuffering"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!],
        /**< @brief Enable/disable half interrupt for group with double bufferring*/
        (boolean)[!IF "AdcEnableHalfInterrupt"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!]
#endif /* (STD_ON == ADC_ENABLE_DOUBLE_BUFFERING) */
#endif /* define ADC_ENABLE_DOUBLE_BUFFERING */
[!ENDIF!][!//
[!ENDLOOP!][!//
    }[!IF "$x < (count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*)-1)"!],[!ELSE!][!ENDIF!]
[!VAR "LoopVar"="$LoopVar + 1"!][!//
[!ENDFOR!][!//
};
[!ENDMACRO!][!//

[!MACRO "Adc_ETimeout_Config"!][!//
CONST(Mcal_DemErrorType, ADC_CONST) Adc_E_TimeoutCfg = 
{
[!IF "node:exists(AdcDemEventParameterRefs/ADC_E_TIMEOUT)"!][!//
    (uint32)STD_ON,
    (uint16)DemConf_DemEventParameter_[!"node:ref(AdcDemEventParameterRefs/ADC_E_TIMEOUT)/@name"!]
[!ELSE!][!//
    (uint32)STD_OFF,
    (uint16)0U
[!ENDIF!][!//
};
[!ENDMACRO!][!//

[!MACRO "Adc_Structure_Config"!][!//
[!VAR "maxUnit"="num:i(ecu:get('Adc.AdcConfigSet.AdcHwUnit'))-1"!][!//
[!VAR "LoopVar"="0"!][!//
/**
* @brief          ADC driver Configuration structure [!IF "var:defined('postBuildVariant')"!][!"$postBuildVariant"!][!ENDIF!].
*/
/** @violates @ref Adc_PBcfg_c_REF_4 An object should be defined at block scope if its identifier
*only appears in a single function.*/
[!IF "(IMPLEMENTATION_CONFIG_VARIANT !='VariantPostBuild' and (variant:size()<=1))"!][!//
CONST(Adc_ConfigType, ADC_CONST) Adc_PBCfgVariantPredefined =
[!ELSE!][!//
CONST(Adc_ConfigType, ADC_CONST) [!"as:name(AdcConfigSet)"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
[!ENDIF!][!//
{
    /**< @brief pointer to Hw unit configurations */
    Adc_HwUnitCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /**< @brief pointer to group configurations */
    Adc_GroupsCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /**< @brief pointer to channel configurations */
    Adc_ChannelsCfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /**< @brief total number of groups */
    (Adc_GroupType)ADC_GROUPS[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
    /**< @brief Miscellaneous configuration parameters. - Adc_Eqadc_MultiConfigType */
    {
        {
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
            [!IF "AdcConfigSet/AdcHwUnit/*/AdcHwUnitId = concat('ADC',$Unit)"!][!"AdcConfigSet/AdcHwUnit/*/AdcHwUnitId[.=concat('ADC',$Unit)]/../AdcTransferType"!][!ELSE!]ADC_INTERRUPT[!ENDIF!][!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDFOR!]
        },
        /**< @brief number of the maximum groups in the current configuration */
        [!"num:i(count(AdcConfigSet/AdcHwUnit/*/AdcGroup/*))"!]U,
        /**< @brief number of the maximum hardware units in the current configuration */
        [!"num:i(count(AdcConfigSet/AdcHwUnit/*))"!]U,
#if(ADC_HW_TRIGGER_API == STD_ON)
        {
            /**< @brief low 8 bits of EQADC_ETDFR for EQADCA */
            [!"num:inttohex(AdcConfigSet/AdcDigitalFilterLength/AdcDigitalFilterLength0)"!]U,
            /**< @brief low 8 bits of EQADC_ETDFR for EQADCB */
            [!"num:inttohex(AdcConfigSet/AdcDigitalFilterLength/AdcDigitalFilterLength1)"!]U
        },
#endif
        {
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
            /**< @brief number of channels of the ADC Hardware unit [!"$Unit"!] */
            [!"num:i(count(AdcConfigSet/AdcHwUnit/*/AdcHwUnitId[.=concat('ADC',$Unit)]/../AdcChannel/*))"!]U[!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDFOR!][!//
        },
[!IF "AdcConfigSet/AdcHwUnit/*/AdcTransferType = 'ADC_DMA'"!][!//
        {
[!FOR "Eqadc" = "0" TO "num:i(ecu:get('Adc.AdcConfigSet.MaxEqadc'))-1"!][!//
            {
[!FOR "Fifo" = "0" TO "num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!][!//
[!NOCODE!][!//
    [!VAR "CFFF_DmaChannelId" = "255"!]
    [!VAR "FISR_DmaChannelId" = "255"!]
    [!LOOP "node:refs('ASPathDataOfSchema:/TS_T2D41M10I0R0/Mcl')/MclConfigSet/*[1]/DMAChannel/*"!]
        [!VAR "DmaHwCh" = "$Eqadc*64 + $Fifo*2"!]
        [!IF "num:i(substring-after(DmaHwChannel,'eDMA_')) = $DmaHwCh"!]
            [!VAR "CFFF_DmaChannelId" = "num:i(MclDMAChannelId)"!]
        [!ELSEIF "num:i(substring-after(DmaHwChannel,'eDMA_')) = ($DmaHwCh + 1)"!]
            [!VAR "FISR_DmaChannelId" = "num:i(MclDMAChannelId)"!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDNOCODE!][!//
                /**< @brief The EQADC_A_CFIFI[!"$Fifo"!]_DMA_CHANNEL number */
                [!"num:i($CFFF_DmaChannelId)"!]U,
                /**< @brief The EQADC_A_RFIFI[!"$Fifo"!]_DMA_CHANNEL number */
                [!"num:i($FISR_DmaChannelId)"!]U[!IF "$Fifo < num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!],[!ENDIF!]
[!ENDFOR!][!//
            }[!IF "$Eqadc < num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!],[!ENDIF!]
[!ENDFOR!][!//
        },
#ifdef ADC_ENABLE_DOUBLE_BUFFERING
#if (STD_ON == ADC_ENABLE_DOUBLE_BUFFERING)
        {
[!FOR "Eqadc" = "0" TO "num:i(ecu:get('Adc.AdcConfigSet.MaxEqadc'))-1"!][!//
            {
[!FOR "Fifo" = "0" TO "num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!][!//
[!NOCODE!][!//
    [!VAR "RFIFO_DmaChannelId" = "255"!]
    [!VAR "DmaHwCh" = "$Eqadc*64 + $Fifo*2"!]
    [!LOOP "node:refs('ASPathDataOfSchema:/TS_T2D41M10I0R0/Mcl')/MclConfigSet/*[1]/DMAChannel/*"!]
        [!VAR "temp"="node:value(MclDmaTransferCompletionNotif)"!][!//
        [!IF "$Eqadc = 0"!]
            [!IF "$temp = concat('Adc_Eqadc_','A','_DmaPopResult',$Fifo)"!]
                [!VAR "RFIFO_DmaChannelId" = "num:i(MclDMAChannelId)"!]
            [!ENDIF!]
        [!ELSEIF "$temp = concat('Adc_Eqadc_','B','_DmaPopResult',$Fifo)"!]
            [!VAR "RFIFO_DmaChannelId" = "num:i(MclDMAChannelId)"!]
        [!ENDIF!]
        [!IF "num:i(substring-after(DmaHwChannel,'eDMA_')) = $DmaHwCh"!]
            [!VAR "RFIFO_DmaChannelId" = "255"!]
        [!ELSEIF "num:i(substring-after(DmaHwChannel,'eDMA_')) = ($DmaHwCh + 1)"!]
            [!VAR "RFIFO_DmaChannelId" = "255"!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDNOCODE!][!//
                /** The DMA channel number for RFIFO[!"$Fifo"!] use double buffering */
                [!"num:i($RFIFO_DmaChannelId)"!]U[!IF "$Fifo < num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!],[!ENDIF!]
[!ENDFOR!][!//
            }[!IF "$Eqadc < num:i(ecu:get('Adc.AdcConfigSet.MaxFifo'))-1"!],[!ENDIF!]
[!ENDFOR!][!//
        },
#endif /* STD_ON == ADC_ENABLE_DOUBLE_BUFFERING */
#endif /* define ADC_ENABLE_DOUBLE_BUFFERING */       
[!ENDIF!][!//
        {
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
            /**< @brief ADC[!"$Unit"!] - ON/OFF */
            (uint8)[!IF "AdcConfigSet/AdcHwUnit/*/AdcHwUnitId = concat('ADC',$Unit)"!]STD_ON[!ELSE!]STD_OFF[!ENDIF!][!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDFOR!][!//
        },
        {
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
            /**< @brief First fifo of ADC[!"$Unit"!] */
            (uint8)[!IF "(AdcConfigSet/AdcHwUnit/*/AdcHwUnitId = concat('ADC',$Unit)) and node:exists(AdcConfigSet/AdcHwUnit/*[AdcHwUnitId = concat('ADC',$Unit)]/AdcGroup/*[1]/AdcGroupFifo)"!][!"AdcConfigSet/AdcHwUnit/*[AdcHwUnitId = concat('ADC',$Unit)]/AdcGroup/*[1]/AdcGroupFifo"!][!ELSE!]0U[!ENDIF!][!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDFOR!][!//
        },
        {
[!FOR "Unit" = "0" TO "num:i($maxUnit)"!][!//
[!NOCODE!][!//
    [!VAR "LogicalUnit"="255"!][!//
    [!LOOP "AdcConfigSet/AdcHwUnit/*"!][!//
        [!IF "AdcHwUnitId = concat('ADC',string($Unit))"!][!//
            [!VAR "LogicalUnit" = "num:i(AdcLogicalUnitId)"!][!//
        [!ENDIF!][!//
    [!ENDLOOP!][!//
[!ENDNOCODE!][!//
[!CODE!][!//
            [!"num:i($LogicalUnit)"!]U[!IF "$Unit < num:i($maxUnit)"!],[!ENDIF!]
[!ENDCODE!][!//
[!ENDFOR!][!//
        }
    }
};
[!ENDMACRO!]

[!MACRO "AdcExportDriverConfiguration"!]
[!NOCODE!][!//
[!VAR "configName" = "as:name(AdcConfigSet)"!][!//
[!IF "var:defined('postBuildVariant')"!][!//
    [!LOOP "variant:all()"!][!//
[!CODE!][!//
extern CONST(Adc_ConfigType, ADC_CONST) [!"$configName"!]_[!"."!];
[!ENDCODE!][!//
    [!ENDLOOP!][!//
[!ELSE!][!//
[!CODE!][!//
extern CONST(Adc_ConfigType, ADC_CONST) [!"$configName"!];
[!ENDCODE!][!//
[!ENDIF!][!//
[!ENDNOCODE!][!//
[!ENDMACRO!]
