[!AUTOSPACING!]
[!CODE!]
/**
*   @file       Ocu_PBcfg.c
*   @implements Ocu_PBcfg.c_Artifact
*   @version    1.0.0
*
*   @brief      AUTOSAR Ocu - Ocu post-build configuration file.
*   @details    Post-build configuration structure instances.
*
*   @addtogroup OCU_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!]

/* Variable storing number of Emios Modules available on the current platform */
[!VAR "numeMiosModules" = "num:i(ecu:get('Ocu.Num_eMios_Hw_Modules'))"!]
[!VAR "numeMiosChanPerModule" = "num:i(ecu:get('Ocu.Num_eMios_Hw_Channels'))"!]

/* Macro used to generate the correspondence (translation) table between all eMios available 
channels and the indexes of channels in the array of Ocu channels configured to use eMios */
/* Macro used to generate the correspondence (translation) table between all eMios available 
channels and the indexes of channels in the array of Ocu channels configured to use eMios */
[!MACRO "GenerateeMiosHwToLogicMap", "parameMiosModule"!]
    [!NOCODE!]
    [!VAR "OutVarHwToLogicArray" = "''"!]
    [!VAR "OutVarHwToLogicComment" = "''"!]
   
    /* Loop through all channels of eMios module received as parameter */
    [!FOR "MacCurModChannel" = "0" TO "31"!]
        /* Limit max number of configured channels to 255 */
        [!VAR "MacVarChTranslationIndex" = "255"!] 
        
        /* Loop through all Ocu channels configured to use eMios IP */
        [!LOOP "OcuChannel/*"!]

            /* Build the comment for the current Module */
            [!VAR "OutVarHwToLogicComment" = "concat('/* Idx of channels 0 - ', num:i(31), ' of eMios Module ', num:i($parameMiosModule), ' in the array of logic Ocu channels */')"!]
                
            /* Get indexes of eMios Module and Channel of current looped Ocu channel */
            [!VAR "MaceMiosModule"  = "num:i(substring-before(substring-after(OcuAssignedHardwareChannel,'EMIOS_'),'_CH_'))"!]
            [!VAR "MaceMiosChannel" = "num:i(substring-after(OcuAssignedHardwareChannel,'_CH_'))"!]    
            /* Check the match with the module received as parameter */
            [!IF "$MaceMiosModule = $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 Ocu channels */
                    [!VAR "MacVarChTranslationIndex" = "OcuChannelId"!]
                [!ENDIF!]
            [!ENDIF!]
        [!ENDLOOP!]
        
        /* If no configured Ocu channel is using the current eMios channel in Module  */
        [!IF "$MacVarChTranslationIndex = 255"!]
            [!VAR "OutVarHwToLogicArray" = "concat($OutVarHwToLogicArray, '(Ocu_ChannelType)255')"!]
        [!ELSE!]
            [!VAR "OutVarHwToLogicArray" = "concat($OutVarHwToLogicArray, '(Ocu_ChannelType)', $MacVarChTranslationIndex)"!]
        [!ENDIF!]
        
        [!IF "$MacCurModChannel < num:i(31)"!]
             [!VAR "OutVarHwToLogicArray" = "concat($OutVarHwToLogicArray, ', ')"!]
        [!ENDIF!]
    [!ENDFOR!]
    [!ENDNOCODE!]
[!ENDMACRO!]

[!ENDNOCODE!]

[!MACRO "GET_PRESCALER_INTERNAL_BUS"!]
        /*get hw information: prescaler*/
        [!IF "(node:exists('OcuHWSpecificSettings/OcuPrescaler'))"!]   
                [!VAR "Prescaler" = "concat('(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)',OcuHWSpecificSettings/OcuPrescaler,' << OCU_EMIOS_CLOCK_DIV_SHIFT)')"!]
        [!ELSE!]
            [!VAR "Prescaler" = "(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_PRESCALER_DIVIDE_1 << OCU_EMIOS_CLOCK_DIV_SHIFT)"!]
        [!ENDIF!]
        
         /*get hw information: alternate prescaler*/
        [!IF "(node:exists('OcuHWSpecificSettings/OcuPrescaler_Alternate'))"!]
                [!VAR "AltPrescaler" = "concat('(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)',OcuHWSpecificSettings/OcuPrescaler_Alternate,' << OCU_EMIOS_CLOCK_DIV_SHIFT)')"!]        
        [!ELSE!]
            [!VAR "AltPrescaler" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_PRESCALER_DIVIDE_1 << OCU_EMIOS_CLOCK_DIV_SHIFT)')"!]
        [!ENDIF!]
[!ENDMACRO!]


[!MACRO "GET_PRESCALER_MASTER_BUS", "MasterBus"!]
        [!VAR "NameBus" = "substring-after(OcuHWSpecificSettings/OcuEmiosBusSelect,'EMIOS_')"!]
        [!VAR "hwMatched" = "0"!]
        [!LOOP "../../OcueMiosMasterBus/*"!]
            [!IF "eMiosMasterBus = $MasterBus"!]
                [!VAR "EMiosCountBusID" = "substring-after($MasterBus,'CH_')"!]
                [!VAR "Prescaler" = "concat('(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)',MasterBusPrescaler,' << OCU_EMIOS_CLOCK_DIV_SHIFT)')"!]
                [!VAR "AltPrescaler" = "concat('(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)',MasterBusPrescaler_Alternate,' << OCU_EMIOS_CLOCK_DIV_SHIFT)')"!]
                [!VAR "hwMatched"="$hwMatched + 1"!]
            [!ENDIF!]
        [!ENDLOOP!]
        
        [!IF "(num:i($hwMatched)) = 0"!]
            [!ERROR!][!//
            [!"$NameBus"!] - EMIOS_[!"$EMiosModId"!]_[!"$MasterBus"!] is used but not install yet.
            [!ENDERROR!][!//
        [!ENDIF!]   
[!ENDMACRO!]

    
[!MACRO "CHECK_ERROR_CONFIG_MAXCOUNT_BUS", "MasterBusID"!]
           [!IF "($MasterBusID = 0)"!]
                [!IF "($TempBUSB = 0)"!]
                    [!VAR "TempBUSB"="1"!]
                    [!VAR "MaxCounterBUSB" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSB)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSEIF "($MasterBusID = 8)"!]
                [!IF "($TempBUSC = 0)"!]
                    [!VAR "TempBUSC"="1"!]
                    [!VAR "MaxCounterBUSC" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSC)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSEIF "($MasterBusID = 16)"!]
                [!IF "($TempBUSD = 0)"!]
                    [!VAR "TempBUSD"="1"!]
                    [!VAR "MaxCounterBUSD" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSD)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSEIF "($MasterBusID = 22)"!]
                [!IF "($TempBUSF = 0)"!]
                    [!VAR "TempBUSD"="1"!]
                    [!VAR "MaxCounterBUSF" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSF)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSEIF "($MasterBusID = 23)"!]
                [!IF "($TempBUSA = 0)"!]
                    [!VAR "TempBUSA"="1"!]
                    [!VAR "MaxCounterBUSA" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSA)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSEIF "($MasterBusID = 24)"!]
                [!IF "($TempBUSE = 0)"!]
                    [!VAR "TempBUSE"="1"!]
                    [!VAR "MaxCounterBUSE" = "$MaxCounterValue"!]
                [!ELSE!]
                    [!IF "($MaxCounterValue = $MaxCounterBUSE)"!]
                    [!ELSE!]
                        [!VAR "ErrorMaxCountBus" = "1"!]
                    [!ENDIF!]
                [!ENDIF!]
            [!ELSE!]
            [!ENDIF!]
    
    [!IF "$ErrorMaxCountBus = 1"!]
        [!ERROR!][!//
            [!"node:name(.)"!] EMIOS_[!"$EMiosModId"!]_CH_[!"$EMiosChannelID"!] use Master Bus must to same OcuMaxCounter Value all channel which used master bus is EMIOS_[!"$EMiosModId"!]_[!"$MasterBus"!] .
        [!ENDERROR!][!//
    [!ENDIF!]  
[!ENDMACRO!]

#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 Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1
* Violates MISRA 2012 Required Rule 4.10, Precautions shall be taken in order to prevent the contents of a header file 
* being included more than once
*
* @section Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2
* 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 Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_3
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused define declarations.
*
* @section Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_4
* 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.
* External linkage is needed to "export" the configuration structure to driver high layer.
*
* @section Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_5
* Violates MISRA 2012 Required Rule 8.5, Functions and objects shall be declared once in one and only one file 
* Declaration of notification functions might be multiple existing in multiple configuration variants
*
* @section Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_6
* Violates MISRA 2012 Required Rule 8.4, A compatible declaration shall be visible when an object or function 
* with external linkage is defined. 
*
* @section Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_7
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its identifier only appears 
* in a single function.
* For generated configuration structures: This violation is due to exporting the externally configured initialization
* structure used by the "<MA>_Init" function.
*/

/*==================================================================================================
*                                         INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Ocu.h"

#include "Reg_eSys_eMios.h"

/*==================================================================================================
*                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @{
* @file           Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c
*/
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_VENDOR_ID_C                      43

/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_3
* Violates Advisory Rule 2.5, A project should not contain unused define declarations.
*/
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_MODULE_ID_C                      125
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MAJOR_VERSION_C       4
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MINOR_VERSION_C       3
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_REVISION_VERSION_C    1

#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MAJOR_VERSION_C               1
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MINOR_VERSION_C               0
#define OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_PATCH_VERSION_C               0
/**@}*/

/*==================================================================================================
*                                      FILE VERSION CHECKS
==================================================================================================*/
#if (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_VENDOR_ID_C != OCU_VENDOR_ID)
    #error "Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Ocu.h have different vendor ids"
#endif

#if ((OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MAJOR_VERSION_C != OCU_AR_RELEASE_MAJOR_VERSION) || \
     (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MINOR_VERSION_C != OCU_AR_RELEASE_MINOR_VERSION) || \
     (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_REVISION_VERSION_C != OCU_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Ocu.h are different"
#endif

#if ((OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MAJOR_VERSION_C != OCU_SW_MAJOR_VERSION) || \
     (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MINOR_VERSION_C != OCU_SW_MINOR_VERSION)  || \
     (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_PATCH_VERSION_C != OCU_SW_PATCH_VERSION))
    #error "Software Version Numbers of Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Ocu.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_VENDOR_ID_C != REG_ESYS_EMIOS_VENDOR_ID)
        #error "Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Reg_eSys_eMios.h have different vendor ids"
    #endif

    #if ((OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MAJOR_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_MAJOR_VERSION) || \
         (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MINOR_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_MINOR_VERSION) || \
         (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_REVISION_VERSION_C != REG_ESYS_EMIOS_AR_RELEASE_REVISION_VERSION ))
        #error "AutoSar Version Numbers of Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Reg_eSys_eMios.h are different"
    #endif

    #if ((OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MAJOR_VERSION_C != REG_ESYS_EMIOS_SW_MAJOR_VERSION) || \
         (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MINOR_VERSION_C != REG_ESYS_EMIOS_SW_MINOR_VERSION) || \
         (OCU[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_PATCH_VERSION_C != REG_ESYS_EMIOS_SW_PATCH_VERSION))
        #error "Software Version Numbers of Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and Reg_eSys_eMios.h are different"
    #endif
#endif


/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

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

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

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

#define OCU_START_SEC_CONFIG_DATA_UNSPECIFIED
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"
[!NOCODE!]
[!VAR "OutNumOcuChannels" = "num:i(count(OcuConfigSet/OcuChannel/*))"!]

[!SELECT "OcuConfigSet"!]

[!VAR "OutNumOcuChannelsInCfg" = "num:i(count(OcuChannel/*))"!]
[!CODE!]

/** 
* @brief Number of configured Ocu channels 
*/
#define OCU_CONF_CHANNELS_PB           [!"num:i($OutNumOcuChannelsInCfg)"!]

/** 
* @brief Number of configured EMIOS channels
*/
#define OCU_EMIOS_CONF_CHANNELS_PB     [!"num:i($OutNumOcuChannelsInCfg)"!]

[!ENDCODE!]

/** @brief counter direction */

[!IF "node:exists(OcuCountdirection)"!]
    [!IF "(OcuCountdirection = 'OCU_DOWNCOUNTING')"!]
            [!VAR "EMiosCountDir" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)OCU_DOWNCOUNTING << OCU_EMIOS_COUNT_DIR_SHIFT)'"!]
    [!ELSE!]
            [!VAR "EMiosCountDir" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)OCU_UPCOUNTING << OCU_EMIOS_COUNT_DIR_SHIFT)'"!]
    [!ENDIF!]       
[!ELSE!]
        [!VAR "EMiosCountDir" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)OCU_UPCOUNTING << OCU_EMIOS_COUNT_DIR_SHIFT)'"!]
[!ENDIF!]

/***************************** Configuration for eMios ********************/\

[!CODE!]
/* @brief Configurations for Ocu channels using EMIOS 
 */
static CONST(Ocu_eMios_ChannelConfigType, OCU_CONST) Ocu_eMios_ChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][OCU_EMIOS_CONF_CHANNELS_PB] =
{
[!ENDCODE!]

    [!LOOP "OcuChannel/*"!]
    
        [!VAR "hwChannelMatched" = "0"!]
        [!VAR "EMiosRefModId"     = "num:i(substring-before(substring-after(OcuAssignedHardwareChannel,'EMIOS_'),'_CH_'))"!]
        [!VAR "EMiosRefChannelID" = "num:i(substring-after(OcuAssignedHardwareChannel,'_CH_'))"!] 
        [!VAR "NameOcuChannel" = "node:name(.)"!] 
    
        [!LOOP "../../OcueMios/*/OcueMiosChannels/*"!]
            [!VAR "EMiosModId"     = "num:i(substring-after(../../OcueMiosModule,'EMIOS_'))"!]
            [!VAR "EMiosChannelID" = "num:i(substring-after(./OcueMiosChannel,'CH_'))"!]
        
            [!IF "($EMiosModId = $EMiosRefModId) and ($EMiosRefChannelID = $EMiosChannelID)"!]
                [!VAR "hwChannelMatched"="$hwChannelMatched + 1"!]
            [!ENDIF!]
        [!ENDLOOP!]
        [!IF "(num:i($hwChannelMatched)) = 0"!]
            [!ERROR!][!//
            [!"$NameOcuChannel"!] [!"OcuAssignedHardwareChannel"!] configured in OcuAssignedHardwareChannel needs to also exist in the Ocu eMios container.
            [!ENDERROR!][!//
        [!ENDIF!]
    [!ENDLOOP!]
   
    [!VAR "comma" = "1"!]
    [!VAR "varCounter" = "0"!] 
    [!VAR "EMiosModId" = "255"!]
    [!LOOP "OcueMios/*/OcueMiosChannels/*"!] 
        [!VAR "channelMatched" = "0"!]
        [!IF "($EMiosModId =num:i(substring-after(../../OcueMiosModule,'EMIOS_')))"!]
        [!ELSE!]
            [!VAR "EMiosModId" = "num:i(substring-after(../../OcueMiosModule,'EMIOS_'))"!]
                [!VAR "TempBUSA" = "0"!]
                [!VAR "TempBUSB" = "0"!]
                [!VAR "TempBUSC" = "0"!]
                [!VAR "TempBUSD" = "0"!]
                [!VAR "TempBUSE" = "0"!]
                [!VAR "TempBUSF" = "0"!]
                [!VAR "ErrorMaxCountBus" = "0"!]
                [!VAR "MaxCounterBUSA" = "16777215"!]
                [!VAR "MaxCounterBUSB" = "16777215"!]
                [!VAR "MaxCounterBUSC" = "16777215"!]
                [!VAR "MaxCounterBUSD" = "16777215"!]
                [!VAR "MaxCounterBUSE" = "16777215"!]
                [!VAR "MaxCounterBUSF" = "16777215"!]
        [!ENDIF!]
        [!VAR "EMiosChannelID" = "num:i(substring-after(./OcueMiosChannel,'CH_'))"!]
        [!VAR "EMiosCountBusID" = "$EMiosChannelID"!]
        /*get hw information: BusSelect*/
        [!IF "(node:exists('OcuHWSpecificSettings/OcuEmiosBusSelect'))"!]   
            [!IF "OcuHWSpecificSettings/OcuEmiosBusSelect = 'EMIOS_BUS_A'"!] 
                [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_23'"!]
                [!VAR "BusSelect" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_BUS_A << OCU_EMIOS_BUS_SELECT_PARAM_SHIFT)'"!]
            [!ELSEIF "OcuHWSpecificSettings/OcuEmiosBusSelect = 'EMIOS_BUS_F'"!]
                [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_22'"!]
                [!VAR "BusSelect" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_BUS_F << OCU_EMIOS_BUS_SELECT_PARAM_SHIFT)'"!]
            [!ELSEIF "OcuHWSpecificSettings/OcuEmiosBusSelect = 'EMIOS_BUS_DIVERSE'"!]
                [!IF "($EMiosChannelID < 8)"!]  
                    [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_0'"!]
                [!ELSEIF "($EMiosChannelID < 16)"!]
                    [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_8'"!]
                [!ELSEIF "($EMiosChannelID < 24)"!]
                    [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_16'"!]
                [!ELSE!]
                    [!CALL "GET_PRESCALER_MASTER_BUS", "MasterBus" = "'CH_24'"!]
                [!ENDIF!]   
                [!VAR "BusSelect" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_BUS_DIVERSE << OCU_EMIOS_BUS_SELECT_PARAM_SHIFT)'"!]
            [!ELSE!]
                [!VAR "BusSelect" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_BUS_INTERNAL_COUNTER << OCU_EMIOS_BUS_SELECT_PARAM_SHIFT)'"!]
                [!CALL "GET_PRESCALER_INTERNAL_BUS"!]
            [!ENDIF!]
        [!ELSE!]
            [!VAR "BusSelect" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)EMIOS_BUS_A << OCU_EMIOS_BUS_SELECT_PARAM_SHIFT)'"!]
        [!ENDIF!]

        /*get hw information: debug information*/
        [!IF "(OcueMiosDebugSettings/OcuEmiosFreeze = 'TRUE')"!]
            [!VAR "DebugCfg" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)CCR_FREN_ENABLE_U32 << OCU_EMIOS_DBG_INFO_SHIFT)'"!]
        [!ELSE!]
            [!VAR "DebugCfg" = "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)CCR_FREN_DISABLE_U32 << OCU_EMIOS_DBG_INFO_SHIFT)'"!] 
        [!ENDIF!]
        
        [!LOOP "../../../../OcuChannel/*"!]
            [!VAR "EMiosRefModId"     = "num:i(substring-before(substring-after(OcuAssignedHardwareChannel,'EMIOS_'),'_CH_'))"!]
            [!VAR "EMiosRefChannelID" = "num:i(substring-after(OcuAssignedHardwareChannel,'_CH_'))"!] 
            [!VAR "DefaultThreshold" = "num:i(OcuDefaultThreshold)"!]
            [!VAR "MaxCounterValue" = "num:i(OcuMaxCounterValue)"!]

            [!VAR "PinUsed" = "OcuOuptutPinUsed"!]
            [!VAR "PinState" = "'((Ocu_eMios_ControlType)(Ocu_eMios_ControlType)(OCU_EMIOS_OUTPUT_DISABLED) << OCU_EMIOS_OUTPIN_USED_SHIFT)'"!]
            [!VAR "PinAction" = "'(Ocu_eMios_ControlType)0'"!]

            [!IF "($PinUsed = 'true')"!]

                [!IF "(node:exists('OcuOutputPinDefaultState'))"!]
                    [!IF "(OcuOutputPinDefaultState = 'OCU_HIGH')"!]
                        [!VAR "PinState"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_EMIOS_OUTPUT_ENABLE) << OCU_EMIOS_OUTPIN_USED_SHIFT) | (Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_HIGH) << OCU_EMIOS_PIN_STATE_SHIFT)'"!]
                    [!ELSE!]
                        [!VAR "PinState"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_EMIOS_OUTPUT_ENABLE) << OCU_EMIOS_OUTPIN_USED_SHIFT) | (Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_LOW) << OCU_EMIOS_PIN_STATE_SHIFT)'"!]
                    [!ENDIF!]
                [!ELSE!]
                    [!VAR "PinState"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_EMIOS_OUTPUT_ENABLE) << OCU_EMIOS_OUTPIN_USED_SHIFT)'"!]
                [!ENDIF!]

                [!IF "(node:exists('OcuOutputPinAction'))"!]       
                    [!IF "(OcuOutputPinAction = 'OCU_SET_HIGH')"!] 
                        [!VAR "PinAction"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_SET_HIGH) << OCU_EMIOS_PIN_ACTION_SHIFT)'"!]
                    [!ELSEIF "(OcuOutputPinAction = 'OCU_TOGGLE')"!]
                        [!VAR "PinAction"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_TOGGLE) << OCU_EMIOS_PIN_ACTION_SHIFT)'"!]
                    [!ELSEIF "(OcuOutputPinAction = 'OCU_DISABLE')"!] 
                        [!VAR "PinAction"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_DISABLE) << OCU_EMIOS_PIN_ACTION_SHIFT)'"!]
                    [!ELSE!]
                         [!VAR "PinAction"= "'(Ocu_eMios_ControlType)((Ocu_eMios_ControlType)(OCU_SET_LOW) << OCU_EMIOS_PIN_ACTION_SHIFT)'"!] 
                    [!ENDIF!]
                [!ENDIF!]
            [!ENDIF!]

            [!IF "($EMiosModId = $EMiosRefModId) and ($EMiosRefChannelID = $EMiosChannelID)"!]
            [!VAR "channelMatched"="$channelMatched + 1"!]
            [!IF "($EMiosRefChannelID = $EMiosCountBusID) and ($MaxCounterValue < 16777215)"!]
                [!ERROR!][!//
                    [!"node:name(.)"!] EMIOS_[!"$EMiosModId"!]_CH_[!"$EMiosChannelID"!] used EMIOS_BUS_INTERNAL_COUNTER not support OcuMaxCounterValue < 16777215.
                [!ENDERROR!][!//
            [!ENDIF!]
            
            [!CALL "CHECK_ERROR_CONFIG_MAXCOUNT_BUS", "MasterBusID" = "$EMiosCountBusID"!]      
[!CODE!]
       
    /* @brief [!"node:name(.)"!] -> EMIOS_[!"$EMiosRefModId"!]_CH_[!"$EMiosRefChannelID"!] */
    {
[!ENDCODE!]

[!CODE!]
        /** @brief Ocu Hw Channel */
        EMIOS_[!"$EMiosRefModId"!]_CH_[!"$EMiosRefChannelID"!],
        /** @brief Ocu Default treshold: [!"$DefaultThreshold"!] */
        (uint32)[!"num:inttohex($DefaultThreshold,8)"!]U,
        /** @brief Ocu max counter value: [!"$MaxCounterValue"!]  */
        (uint32)[!"num:inttohex(num:i($MaxCounterValue),8)"!]U,
[!ENDCODE!]
        [!IF "(../../../OcuGeneral/OcuEnableDualClockMode = 'true')"!]
[!CODE!]
#if (OCU_SET_CLOCK_MODE_API == STD_ON)
        /** @brief eMios alternative Control Value */
        (Ocu_eMios_ControlType)[!"$AltPrescaler"!],
#endif
[!ENDCODE!]
        [!ENDIF!]
[!CODE!]
        /** @brief eMios Control Value */
        (Ocu_eMios_ControlType)
        (
        [!WS "12"!][!"$BusSelect"!] | /* Counter select bits for the given channel */
        [!WS "12"!][!"$PinState"!] |  /* Output Pin Enable and default state */
        [!WS "12"!][!"$PinAction"!] |  /* Output Pin default action */
        [!WS "12"!][!"$DebugCfg"!] |  /* Timer debug config */
        [!WS "12"!][!"$EMiosCountDir"!] |  /*Timer count direction */
        [!WS "12"!][!"$Prescaler"!]  /* Timer clock prescaler configuration */    
        ),
        /** @brief Ocu Hw Channel of counter BUS */
        EMIOS_[!"$EMiosRefModId"!]_CH_[!"$EMiosCountBusID"!], 
[!ENDCODE!]

[!CODE!]
    }[!IF "(num:i($comma))<(num:i($OutNumOcuChannels))"!],[!ENDIF!][!CR!][!VAR "comma"="$comma + 1"!]
[!ENDCODE!]
            [!ENDIF!]
        [!ENDLOOP!]
        [!IF "(num:i($channelMatched)) = 0"!]
        [!ERROR!][!//
        Hardware channel EMIOS_[!"$EMiosModId"!]_CH_[!"$EMiosChannelID"!] configured in the Ocu eMios container needs to match a logical's channel OcuAssignedHardwareChannel.
        [!ENDERROR!][!//
        [!ENDIF!]
        [!VAR "varCounter"="$varCounter + 1"!]
    [!ENDLOOP!]

[!CODE!]
};
[!ENDCODE!]

[!CODE!]
/**
@brief EMIOS IP configuration
*/
static CONST(Ocu_eMios_IpConfigType, OCU_CONST) Ocu_eMios_IpConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!] =
{
    /** @brief Number of EMIOS channels in the Ocu configuration */
    (uint8)[!"num:i($OutNumOcuChannels)"!],
    /** @brief Pointer to the array of EMIOS enabled Ocu channel configurations */
    &Ocu_eMios_ChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!]
};
[!ENDCODE!]

[!LOOP "OcuChannel/*"!]
[!IF "node:exists('OcuNotification')"!]
        [!IF "(OcuNotification = '') or (OcuNotification = 'NULL_PTR') or (OcuNotification = 'NULL')"!]
        [!ELSE!]
        [!CODE!]
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_5 Rule 8.5, Functions and objects shall be declared once in one and only one file  */
extern FUNC (void, OCU_CODE) [!"OcuNotification"!](void);
        [!ENDCODE!]
        [!ENDIF!]
    [!ENDIF!]
[!ENDLOOP!]

[!CODE!]

/* @brief Array of configured Ocu channels */
static CONST(Ocu_ChannelConfigType, OCU_CONST) Ocu_Channels_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!][OCU_CONF_CHANNELS_PB] =
{
[!ENDCODE!]
    [!VAR "comma" = "1"!]
    [!FOR "varCounter" = "0" TO "$OutNumOcuChannels"!]
        [!LOOP "OcuChannel/*"!]
            [!IF "OcuChannelId = $varCounter"!]
            [!CODE!]        
    /* @brief [!"@name"!] */
    {    
        /* @brief OcuOuptutPinUsed */
    [!IF "OcuOuptutPinUsed = 'true'"!]
        [!WS "8"!](boolean)TRUE,
    [!ELSE!]
        [!WS "8"!](boolean)FALSE,
    [!ENDIF!]
#if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
        /** @brief Ocu notification function */
        [!ENDCODE!]    
    [!IF "node:exists('OcuNotification')"!]
        [!IF "(OcuNotification = '') or (OcuNotification = 'NULL_PTR') or (OcuNotification = 'NULL')"!]
        [!CODE!][!WS "8"!]NULL_PTR [!ENDCODE!][!CR!]    
        [!ELSE!]
        [!CODE!]
        [!WS "8"!]
        [!WS "8"!]&[!"OcuNotification"!]
        [!ENDCODE!]    
        [!ENDIF!]
    [!ELSE!]
        [!CODE!][!WS "8"!]NULL_PTR[!ENDCODE!][!CR!]
    [!ENDIF!]
    [!CODE!]
#endif

    }[!IF "(num:i($comma))<(num:i($OutNumOcuChannels))"!],[!ENDIF!][!VAR "comma"="$comma + 1"!][!CR!]
            [!ENDCODE!]        
            [!ENDIF!]            
        [!ENDLOOP!]
    [!ENDFOR!]
[!CODE!]  
};
[!ENDCODE!]

[!CODE!]  
/**
@brief   Ocu channels IP related configuration array
*/
static CONST(Ocu_IpChannelConfigType, OCU_CONST) Ocu_IpChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!][OCU_CONF_CHANNELS_PB] =
{
  [!VAR "curOcuChannelUsingeMios" = "0"!]
  [!VAR "comma" = "1"!]
  [!FOR "varCounter" = "0" TO "$OutNumOcuChannels"!]
    [!LOOP "OcuChannel/*"!]
      [!IF "OcuChannelId = $varCounter"!]
    /** @brief [!"@name"!] */
    {
        /* @brief Index in the configuration table of the EMIOS channels */
        (uint8)[!"num:i($curOcuChannelUsingeMios)"!],
        [!VAR "curOcuChannelUsingeMios" = "$curOcuChannelUsingeMios + 1"!]
    }[!IF "(num:i($comma))<(num:i($OutNumOcuChannels))"!],[!ENDIF!][!VAR "comma"="$comma + 1"!][!CR!]    
      [!ENDIF!]
    [!ENDLOOP!]
  [!ENDFOR!]
};
#if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
static CONST(Ocu_ChannelType, OCU_CONST)  Ocu_InitHWMap_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][OCU_HW_CHANNELS_NO]=
    /** @brief Hw to logic channel map. Array containing a number of elements
    equal to total number of available channels on EMIOS IPV */
    {
[!FOR "idx" = "0" TO "$numeMiosModules - 1"!]
        [!CALL "GenerateeMiosHwToLogicMap", "parameMiosModule" = "$idx"!]
        [!"$OutVarHwToLogicComment"!]
        [!"$OutVarHwToLogicArray"!][!IF "$idx < num:i($numeMiosModules)"!],[!ENDIF!][!CR!]
[!ENDFOR!]
    };
#endif /* (OCU_NOTIFICATION_SUPPORTED == STD_ON) */  
[!ENDCODE!]


[!IF "../IMPLEMENTATION_CONFIG_VARIANT='VariantPreCompile' and  variant:size()<=1"!]
    [!CODE!]
/**
@brief   Ocu high level configuration structure for a single precompile variant
*/
/**
* @violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_4 Functions and objects should not be defined with external linkage if
* they are referenced in only one translation unit.
*
* @violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_6 A compatible declaration shall be visible when an object or function 
*                with external linkage is defined
*
* @violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_7 This violation is due to exporting the externally 
*                configured initialization structure used by the "<MA>_Init" function.
*/
CONST(Ocu_ConfigType, OCU_CONST) Ocu_PBCfgVariantPredefined =
    [!ENDCODE!]
[!ELSE!]
    [!CODE!]
/**
@brief   Ocu high level configuration structure
*/
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_4 Functions and objects should not be defined with external linkage if
* they are referenced in only one translation unit.
*/
CONST(Ocu_ConfigType, OCU_CONST) [!"as:name(.)"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
    [!ENDCODE!]
[!ENDIF!]
[!CODE!]
{
    /** @brief Number of configured Ocu channels */
    (Ocu_ChannelType)OCU_CONF_CHANNELS_PB,
    /** @brief Pointer to array of Ocu channels */
    &Ocu_Channels_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!],
    /** @brief IP specific configuration */
    {
        /* @brief Pointer to the structure containing EMIOS configuration */
        &Ocu_eMios_IpConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!],
        /* @brief Pointer to Array containing channe IP related information */
        &Ocu_IpChannelConfig_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!]
    }
#if (OCU_NOTIFICATION_SUPPORTED == STD_ON)
    ,
    &Ocu_InitHWMap_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][!CR!]
#endif /* (OCU_NOTIFICATION_SUPPORTED == STD_ON) */  
};
[!ENDCODE!]
[!ENDSELECT!]
[!ENDNOCODE!]
#define OCU_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Precautions shall be taken in order to prevent the contents 
   of a header file being included more than once */
/**@violates @ref Ocu[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2 #include directives should only be preceded by preprocessor directives or comments. */
#include "Ocu_MemMap.h"


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

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

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

/*==================================================================================================
*                                        GLOBAL FUNCTIONS
==================================================================================================*/


#ifdef __cplusplus
}
#endif

/** @} */

[!ENDCODE!]
