[!CODE!][!//
/**
*   @file    CDD_Mcem_PBcfg.c
*   @implements     CDD_Mcem_PBcfg.c_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Mcem - contains the data exported by the Mcem module
*   @details Contains the information that will be exported by the module, as requested by Autosar.
*
*   @addtogroup MCEM_MODULE
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : Fccu
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

[!INCLUDE "CDD_Mcem_VersionCheck_Src_PB.m"!][!//

[!NOCODE!][!//
[!VAR "PostBuildFile"="0=0"!][!//

[!CODE!][!//
/**
*
* @page misra_violations MISRA-C:2004 violations
*
* @section CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1
* Violates MISRA 2004 Required Rule 1.4, Exceeds 31 characters due to AUTOSAR 
* compatibility
*
* @section CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2
* Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.
* This violation is due to readability of static initializations.
*
* @section CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_3
* Violates MISRA 2004 Required Rule 19.15, Precautions shall be taken in order to prevent the
* contents of a header file being included twice
* This is not a violation since all header files are protected against multiple inclusions
*
* @section CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_4
* Violates MISRA 2004 Advisory Rule 19.1, #include statements in a file should only be preceded by other
* preprocessor directives or comments.
* Violated due to AUTOSAR requirement MEMMAP003.
*
* @section CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_5
* Violates MISRA 2004 Required Rule 8.10, All declarations and definitions of objects 
* or functions at file scope shall have internal linkage unless external linkage is required.
* Possibly unused public configuration
* 
* @section [global]
* Violates MISRA 2004 Required Rule 5.1, Exceeds 31 characters due to AUTOSAR compatibility
*/

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

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
*==================================================================================================*/
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_VENDOR_ID_C                        43
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MAJOR_VERSION_C         4
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MINOR_VERSION_C         3
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_REVISION_VERSION_C      1
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MAJOR_VERSION_C                 1
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MINOR_VERSION_C                 0
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_1 Exceeds 31 characters */
#define CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_PATCH_VERSION_C                 0

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

/* Check Mcem_Cfg.c against CDD_Mcem_Cfg.h file versions */
#if (CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_VENDOR_ID_C != CDD_MCEM_VENDOR_ID_CFG)
    #error "CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and CDD_Mcem_Cfg.h have different vendor IDs"
#endif

#if ((CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MAJOR_VERSION_C != CDD_MCEM_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_MINOR_VERSION_C != CDD_MCEM_AR_RELEASE_MINOR_VERSION_CFG) || \
     (CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_AR_RELEASE_REVISION_VERSION_C != CDD_MCEM_AR_RELEASE_REVISION_VERSION_CFG))
    #error "AutoSar Version Numbers of CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and CDD_Mcem_Cfg.h are different"
#endif

#if ((CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MAJOR_VERSION_C != CDD_MCEM_SW_MAJOR_VERSION_CFG) || \
     (CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_MINOR_VERSION_C != CDD_MCEM_SW_MINOR_VERSION_CFG) || \
     (CDD_MCEM[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBCFG_SW_PATCH_VERSION_C != CDD_MCEM_SW_PATCH_VERSION_CFG))
    #error "Software Version Numbers of CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg.c and CDD_Mcem_Cfg.h are different"
#endif

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


/*==================================================================================================
*                                       LOCAL MACROS
*==================================================================================================*/
/* Enable/Disable Configuration bit values */
#define MCEM_ENABLED               (1UL)
#define MCEM_DISABLED              (0UL)

/* Configuration Bit/Tuple manipulation macros */
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2 Function-like macro defined */
#define MCEM_CONFIG_VAL_1BIT( shl, val )            (((uint32)((val)&1UL)) << ((shl)%32U))
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_2 Function-like macro defined */
#define MCEM_CONFIG_VAL_2BITS( shl, val )           (((uint32)((val)&3UL)) << ((2U*(shl))%32U))

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


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


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

[!ENDCODE!][!//


[!//
[!// Generate an initialization value for a bit register
[!//
[!MACRO "GenBitCfgRegister", "nameList"="''", "valList" = "''", "comment" = "''", "TrueVal"="'MCEM_ENABLED'", "FalseVal"="'MCEM_DISABLED'", "comma"="''"!][!//
[!CODE!]
    /* [!"$comment"!] */
[!ENDCODE!][!//            
    [!IF "$nameList=''"!][!//
[!CODE!][!//
    (uint32)0UL[!"$comma"!]                  /* [!"$comment"!] */
[!ENDCODE!][!//            
    [!ELSE!][!//
        [!VAR "idx"="0"!][!//
        [!VAR "RegVal"="0"!][!//
        [!VAR "Flg"="0"!][!//
        [!LOOP "text:split( $nameList, ',' )"!][!//
            [!VAR "Name"="."!][!//
            [!VAR "idx"="$idx + 1"!][!//
            [!VAR "BitCfg"="node:when( text:split( $valList, ',' )[ position()=$idx ]='true', 1, 0 )"!][!//
            [!VAR "RegVal"="bit:or( $RegVal, bit:shl( $BitCfg, -1+$idx ) )"!][!//
            [!VAR "Or"="node:when( $Flg, '         | ', '(uint32)(  ' )"!][!//
            [!VAR "Flg"="1"!][!//
[!CODE!][!//
    [!"$Or"!]MCEM_CONFIG_VAL_1BIT([!"text:toupper( $Name )"!], [!"node:when( $BitCfg=1, 'MCEM_ENABLED', 'MCEM_DISABLED' )"!] )
[!ENDCODE!][!//
        [!ENDLOOP!][!//
[!CODE!][!//
             )[!"$comma"!]                   /* [!"$comment"!] = [!"num:inttohex( $RegVal, 8 )"!]UL */
[!ENDCODE!][!//
    [!ENDIF!][!//
[!ENDMACRO!][!//



[!//
[!// Generate an initialization value for a bit register
[!// Individual values must be explicitly listed
[!//
[!MACRO "GenCfgRegister", "defList" = "''", "valList" = "''", "comment" = "''", "comma"="''"!][!//
[!CODE!]
    /* [!"$comment"!] */
[!ENDCODE!][!//            
    [!IF "$defList=''"!][!//
[!CODE!][!//
    (uint32)0UL[!"$comma"!]                  /* [!"$comment"!] */
[!ENDCODE!][!//            
    [!ELSE!][!//
        [!VAR "idx"="0"!][!//
        [!VAR "RegVal"="0"!][!//
        [!VAR "Flg"="0"!][!//
        [!LOOP "text:split( $defList, ':' )"!][!//
            [!IF ". != ''"!][!//
                [!VAR "Name"="."!][!//
                [!VAR "idx"="$idx + 1"!][!//
                [!VAR "val"="text:split( $valList, ',' )[ position()=$idx ]"!][!//
                [!VAR "RegVal"="bit:or( $RegVal, $val )"!][!//
                [!VAR "Or"="node:when( $Flg, '         | ', '(uint32)(  ' )"!][!//
                [!VAR "Flg"="1"!][!//
[!CODE!][!//
    [!"$Or"!][!"$Name"!]
[!ENDCODE!][!//
            [!ENDIF!][!//
        [!ENDLOOP!][!//
[!CODE!][!//
             )[!"$comma"!]                   /* [!"$comment"!] = [!"num:inttohex( $RegVal, 8 )"!]UL */
[!ENDCODE!][!//
    [!ENDIF!][!//
[!ENDMACRO!][!//



[!//
[!// Generate an initialization value for a bit register
[!// All values for which FaultList is set
[!//
[!MACRO "GenBitRegister", "valList" = "''", "comment" = "''", "TrueVal"="'MCEM_ENABLED'", "FalseVal"="'MCEM_DISABLED'"!][!//
[!CODE!]
    /* [!"$comment"!]s */
[!ENDCODE!][!//
    [!VAR "RegsORed"="0"!][!//
    [!VAR "RegsNum"="num:i(substring-before('2U','U')-1)"!][!//
    [!FOR "wordIdx"="0" TO "$RegsNum"!][!//
        [!VAR "faultOffset"="$wordIdx * 32"!][!//
        [!VAR "FWord"="substring( $FaultList, $faultOffset+1, 32 )"!][!//
        [!IF "$Empty = $FWord"!][!//
[!CODE!][!//
[!IF "$wordIdx='0'"!][!//
   {(uint32)0UL,              /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ELSEIF "$wordIdx = $RegsNum"!][!//
    (uint32)0UL},             /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ELSE!][!//
    (uint32)0UL,                  /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ENDIF!][!//
[!ENDCODE!][!//
        [!ELSE!][!//
            [!VAR "Word"="substring( $valList, $faultOffset+1, 32 )"!][!//
            [!VAR "RegVal"="0"!][!//
            [!VAR "Flg"="0"!][!//
            [!FOR "bit"="0" TO "31"!][!//
                [!IF "substring( $FWord, $bit+1, 1 ) = '1'"!][!//
                    [!VAR "BitCfg"="substring( $Word, $bit+1, 1 )"!][!//
                    [!IF "$BitCfg='1'"!][!VAR "RegVal"="bit:bitset( $RegVal, $bit )"!][!ENDIF!][!//
                        [!IF "$wordIdx='0'"!][!//
                    [!VAR "Or"="node:when( $Flg, '         | ', '{(uint32)(  ' )"!][!//
                        [!ELSE!][!//
                    [!VAR "Or"="node:when( $Flg, '         | ', '(uint32)(  ' )"!][!//
                        [!ENDIF!][!//       
                    [!VAR "Name"="ecu:list( 'Mcem.McemConfigSet.Fault.SignalDesc' )[ position()-1 = ($faultOffset+$bit) ]"!][!//
                    [!VAR "Flg"="1"!][!//
[!CODE!][!//
    [!"$Or"!]MCEM_CONFIG_VAL_1BIT([!"text:toupper( $Name )"!], [!"node:when( $BitCfg='1', $TrueVal, $FalseVal )"!] )
[!ENDCODE!][!//            
                [!ENDIF!][!//
            [!ENDFOR!][!//
            [!VAR "RegsORed"="bit:or( $RegsORed, $RegVal )"!][!//
[!CODE!][!//
            [!"node:when( $wordIdx=$RegsNum, ')},', '),' )"!]                   /* [!"$comment"!] [!"num:i( $wordIdx )"!] = [!"num:inttohex( $RegVal, 8 )"!]UL */
[!ENDCODE!][!//
        [!ENDIF!][!//
    [!ENDFOR!][!//
[!ENDMACRO!][!//



[!//
[!// Generate an initialization value for a 2-bit register
[!// All values for which FaultList is set
[!//
[!MACRO "GenBit2Register", "valList" = "''", "comment" = "''", "Defines"="''"!][!//
[!CODE!]
    /* [!"$comment"!]s */
[!ENDCODE!][!//            
    [!VAR "RegsNum"="num:i(substring-before('3U','U')-1)"!][!//
    [!FOR "wordIdx"="0" TO "$RegsNum"!][!//
        [!VAR "faultOffset"="$wordIdx * 16"!][!//
        [!VAR "RegVal"="0"!][!//
        [!VAR "FWord"="substring( $FaultList, $faultOffset+1, 16 )"!][!//
        [!VAR "Word"="substring( $valList, $faultOffset+1, 16 )"!][!//
        [!IF "starts-with( $Empty, $FWord )"!][!//
[!CODE!][!//
[!IF "$wordIdx='0'"!][!//
   {(uint32)0UL,              /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ELSEIF "$wordIdx = $RegsNum"!][!//
    (uint32)0UL},             /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ELSE!][!//
    (uint32)0UL,              /* [!"$comment"!] [!"num:i( $wordIdx )"!] */
[!ENDIF!][!//
[!ENDCODE!][!//            
        [!ELSE!][!//
            [!VAR "Flg"="0"!][!//
            [!FOR "bit"="0" TO "15"!][!//
                [!IF "substring( $FWord, $bit+1, 1 ) = '1'"!][!//
                    [!VAR "BitCfg"="num:i( substring( $Word, $bit+1, 1 ) )"!][!//
                    [!VAR "RegVal"="bit:or( $RegVal, bit:shl( $BitCfg, 2*$bit ) )"!][!//
                    [!VAR "Def"="text:split( $Defines, ',' )[ position()=($BitCfg+1) ]"!][!//
                    [!VAR "Def"="text:split( $Def, ':' )[ position()=1 ]"!]
                        [!IF "$wordIdx='0'"!][!//
                    [!VAR "Or"="node:when( $Flg, '         | ', '{(uint32)(  ' )"!][!//
                        [!ELSE!][!//
                    [!VAR "Or"="node:when( $Flg, '         | ', '(uint32)(  ' )"!][!//
                        [!ENDIF!][!//
                    [!VAR "Name"="ecu:list( 'Mcem.McemConfigSet.Fault.SignalDesc' )[ position()-1 = ($faultOffset+$bit) ]"!][!//
                    [!VAR "Flg"="1"!][!//
[!CODE!][!//
    [!"$Or"!]MCEM_CONFIG_VAL_2BITS([!"text:toupper( $Name )"!], MCEM_FCCU_REACTION_[!"text:toupper( $Def )"!] )
[!ENDCODE!][!//            
                [!ENDIF!][!//
            [!ENDFOR!][!//
[!CODE!][!//
             )[!"node:when( $wordIdx=$RegsNum, '}', ',' )"!]                   /* [!"$comment"!] [!"num:i( $wordIdx )"!] = [!"num:inttohex( $RegVal, 8 )"!]UL */
[!ENDCODE!][!//
        [!ENDIF!][!//
    [!ENDFOR!][!//
[!ENDMACRO!][!//



[!//
[!// Auxiliary variables
[!// Reset reaction types and their values
[!VAR "ResetTypes"="'NoResetReaction:0,ShortResetReaction:1,LongResetReaction:2'"!][!//
[!// Zero register ('00...0', length 32)
[!VAR "Empty"="''"!][!//
[!FOR "wordIdx"="0" TO "31"!][!//
    [!VAR "Empty"="concat( $Empty, '0' )"!][!//
[!ENDFOR!][!//


[!CODE!][!//
#define MCEM_START_SEC_CONST_UNSPECIFIED
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_3 precautions to prevent the contents of a header file being included twice */
#include "Mcem_MemMap.h"

[!ENDCODE!][!//

[!VAR "AlarmAnyNotifNULL"="node:when( node:value( McemGeneral/McemAlarmNotificationApi ), 0, 1 )"!][!//

[!SELECT "McemConfigSet"!][!//
  [!IF "((../IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (../IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!][!//
    [!// Settings for each Variant
    [!IF "var:defined('postBuildVariant')"!][!//
        [!VAR "CfgSuffix" = "concat( 'PB_', $postBuildVariant)"!][!//
        [!VAR "MCEM_Cfg"  = "concat( as:name(.), '_', $postBuildVariant)"!][!//
    [!ELSE!][!//
        [!VAR "CfgSuffix" = "'PB'"!][!//
        [!VAR "MCEM_Cfg"  = "as:name(.)"!][!//
    [!ENDIF!][!//
  [!ELSE!]
    [!VAR "CfgSuffix" = "'_Predefined'"!][!//
    [!VAR "MCEM_Cfg"  = "'Mcem_PBCfgVariantPredefined'"!][!//
  [!ENDIF!][!//
[!CODE!]
static CONST(Fccu_ConfigType, MCEM_CONST) Fccu_Config[!"$CfgSuffix"!] = {
[!ENDCODE!][!//

    [!// Build FCCU Glitch Filter Configuration
    [!VAR "GlitchFilterConfig"="''"!][!//
    [!VAR "GlitchFilterConfigVal"="''"!][!//

    [!// Set Glitch Filter Bypass
    [!VAR "GlitchFilterConfig"="concat( $GlitchFilterConfig, 'MCEM_CONFIG_VAL_1BIT( MCEM_FCCU_CTRL_GLITCH_FILTER_BYPASS, ', node:when( text:tolower(node:value(FccuGlitchFilterBypass))='true', 'MCEM_ENABLED', 'MCEM_DISABLED' ), ' ):' )"!][!//
    [!VAR "GlitchFilterConfigVal"="concat( $GlitchFilterConfigVal, bit:shl( node:when( text:tolower(node:value(FccuGlitchFilterBypass))='true', 1, 0 ), 31 ), ',' )"!][!//
    
    [!IF "text:tolower(node:value(FccuGlitchFilterBypass))='false'"!][!//
        [!IF "FccuGlitchFilterWidth = 'Up_To_50_us'"!][!//
            [!VAR "GlitchFilterConfig"="concat( $GlitchFilterConfig, '(MCEM_FCCU_FILTER_GLITCH_UP_TO_50_US)')"!][!//
            [!VAR "GlitchFilterConfigVal"="concat( $GlitchFilterConfigVal, bit:shl(0, 29 ), ',' )"!][!//
        [!ELSEIF "FccuGlitchFilterWidth = 'Up_To_75_us'"!][!//
            [!VAR "GlitchFilterConfig"="concat( $GlitchFilterConfig, '(MCEM_FCCU_FILTER_GLITCH_UP_TO_75_US)')"!][!//
            [!VAR "GlitchFilterConfigVal"="concat( $GlitchFilterConfigVal, bit:shl(1, 29 ), ',' )"!][!//
        [!ELSEIF "FccuGlitchFilterWidth = 'Up_To_100_us'"!][!//
            [!VAR "GlitchFilterConfig"="concat( $GlitchFilterConfig, '(MCEM_FCCU_FILTER_GLITCH_UP_TO_100_US)')"!][!//
            [!VAR "GlitchFilterConfigVal"="concat( $GlitchFilterConfigVal, bit:shl(2, 29 ), ',' )"!][!//
        [!ENDIF!][!//
    [!ENDIF!][!//
    
    [!CALL "GenCfgRegister", "defList"="$GlitchFilterConfig", "valList"="$GlitchFilterConfigVal", "comment"="'CTRL Glitch Filter related bitfields'", "comma"="','"!][!//
    

    [!// Build FCCU Configuration
    [!VAR "FaultConfig"="''"!][!//
    [!VAR "FaultConfigVal"="''"!][!//

    [!// Set EOUT pins after reset
    [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_CONFIG_VAL_1BIT( MCEM_FCCU_CFG_EOUT_AFTER_RESET, ', node:when( text:tolower(node:value(EOUT_AfterReset))='true', 'MCEM_ENABLED', 'MCEM_DISABLED' ), ' ):' )"!][!//
    [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( node:when( text:tolower(node:value(EOUT_AfterReset))='true', 1, 0 ), 24 ), ',' )"!][!//

    [!// Set EOUT output mode
    [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_FCCU_CFG_', text:toupper( EOUT_FaultOutputMode ), ':' )"!][!//
    [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( node:when( node:value(EOUT_FaultOutputMode)='DualRail', 0, node:when( node:value(EOUT_FaultOutputMode)='TimeSwitching', 1, 2 ) ), 6 ), ',' )"!][!//

    [!IF "EOUT_FaultOutputMode != 'EOUT_BiStable'"!][!//
        [!// Workaround due bug in XDM (to be fixed for BETA2)
        [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_CONFIG_VAL_1BIT( MCEM_FCCU_CFG_FAST_SWITCHING_MODE, ', node:when( node:exists( EOUT_SwitchingMode ) and text:tolower(node:value(EOUT_SwitchingMode))='true', 'MCEM_ENABLED', 'MCEM_DISABLED' ), ' ):' )"!][!//
        [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( node:when( node:exists( EOUT_SwitchingMode ) and text:tolower(node:value(EOUT_SwitchingMode))='true', 1, 0 ), 10 ), ',' )"!][!//
    
        [!//Configuration of FCCU_CFG.FOPE
        [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_CONFIG_VAL_1BIT( MCEM_FCCU_CFG_FOPE, ', node:when( EOUT_Prescaler >= 64, 'MCEM_ENABLED', 'MCEM_DISABLED' ), ' ):' )"!][!//
        [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( node:when( EOUT_Prescaler >= 64, 1, 0 ), 15 ), ',' )"!][!//
        [!//Configuration of FCCU_CFG.FOP
        [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_FCCU_CFG_FOP(', num:i(EOUT_Prescaler mod 64),'U):' )"!][!//
        [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( EOUT_Prescaler mod 64, 0 ), ',' )"!][!//

    [!ENDIF!][!//

    [!IF "EOUT_FaultOutputMode != 'EOUT_DualRail'"!][!//
        [!// Workaround due bug in XDM
        [!VAR "FaultConfig"="concat( $FaultConfig, 'MCEM_CONFIG_VAL_1BIT( MCEM_FCCU_CFG_POLARITY, ', node:when( node:exists( EOUT_PolaritySelection ) and text:tolower(node:value(EOUT_PolaritySelection))='true', 'MCEM_FCCU_CFG_POLARITY_E1LE0H', 'MCEM_FCCU_CFG_POLARITY_E1HE0L' ), ' ):' )"!][!//
        [!VAR "FaultConfigVal"="concat( $FaultConfigVal, bit:shl( node:when( node:exists( EOUT_PolaritySelection ) and text:tolower(node:value(EOUT_PolaritySelection))='true', 1, 0 ), 9 ), ',' )"!][!//
    [!ENDIF!][!//

    [!CALL "GenCfgRegister", "defList"="$FaultConfig", "valList"="$FaultConfigVal", "comment"="'Configuration Register'", "comma"="','"!][!//

[!CODE!]
    /* Non Critical Fault Recovery Timeout Register = [!"num:i( node:value( FaultTimeout ) )"!] [16MHz IRC ticks] ([!"num:i( (1. div 16)*node:value( FaultTimeout ) )"!] [us]) */
    (uint32)[!"num:inttohex( node:value( FaultTimeout ), 8 )"!]UL,

    /* Mcem Configuration Timeout Register = [!"num:i( node:value( ConfigTimeout ) )"!] ([!"num:i( 64 * bit:shl( 1, node:value( ConfigTimeout ) ) )"!] [us]) */
    (uint32)[!"num:inttohex( node:value( ConfigTimeout ), 8 )"!]UL,

    /* EOUT delta T signal duration Register = [!"num:i( node:value( DeltaT ) )"!] [us] */
    (uint32)[!"num:inttohex( node:value( DeltaT ), 8 )"!]UL,
[!ENDCODE!][!//

    [!CALL "GenBitCfgRegister", "nameList"="'MCEM_FCCU_CFG_IRQ_EN'", "valList"="( CfgToIrqEnabled )", "comment"="'IRQ Enable Register'", "comma"="','"!][!//

    [!// Prepare 128 NCF positions with the default parameters
    [!VAR "FaultList"="''"!][!//
    [!VAR "FaultSignalList"="''"!][!//
    [!VAR "FaultRecoveryList"="''"!][!//
    [!VAR "FaultReactionList"="''"!][!//
    [!VAR "FaultTOEnList"="''"!][!//
    [!VAR "FaultAlarmEnList"="''"!][!//
    [!VAR "FaultNMIEnList"="''"!][!//
    [!VAR "FaultEOUTEnList"="''"!][!//

    [!// Default parameters
    [!VAR "defFaulRecovery"="node:when( contains( node:value( ./DefaultFaultConfig/RecoveryType ), 'Sw' ), '1', '0' )"!][!//
    [!VAR "defFaultReaction"="text:split( text:grep( text:split( $ResetTypes, ',' ), concat( node:value( ./DefaultFaultConfig/ReactionType ), '.*' ) ), ':' )[ position()=2 ]"!][!//
    [!VAR "defFaultReaction1"="concat( node:value( ./DefaultFaultConfig/ReactionType ), ',' )"!][!//
    [!VAR "defFaultTOEn"="node:when( node:value( ./DefaultFaultConfig/RecoveryTimeOutEnabled ), '1', '0' )"!][!//
    [!VAR "defFaultAlarmEn"="node:when(( node:value( ./DefaultFaultConfig/AlarmIrqEnabled)='true' and node:value( ./DefaultFaultConfig/RecoveryTimeOutEnabled )='true'), '1', '0' )"!][!//
    [!VAR "defFaultNMIEn"="node:when( node:value( ./DefaultFaultConfig/FaultNmiEnabled ), '1', '0' )"!][!//
    [!VAR "defFaultEOUTEn"="node:when( node:value( ./DefaultFaultConfig/ActivateOutputPins ), '1', '0' )"!][!//

    [!// Build a list with default values
    [!LOOP "ecu:list('Mcem.McemConfigSet.Fault.SignalDesc')"!][!//
        [!// Disable reserved signals
        [!VAR "FaultList"="concat( $FaultList, node:when( text:match( ., '^Reserved_\d+$' ), '0', '1' ) )"!][!//
        [!VAR "FaultSignalList"="concat( $FaultSignalList, ., ',' )"!][!//
        [!VAR "FaultReactionList"="concat( $FaultReactionList, $defFaultReaction )"!][!//
        [!VAR "FaultRecoveryList"="concat( $FaultRecoveryList, $defFaulRecovery )"!][!//
        [!VAR "FaultTOEnList"="concat( $FaultTOEnList, $defFaultTOEn )"!][!//
        [!VAR "FaultAlarmEnList"="concat( $FaultAlarmEnList, $defFaultAlarmEn )"!][!//
        [!VAR "FaultNMIEnList"="concat( $FaultNMIEnList, $defFaultNMIEn )"!][!//
        [!VAR "FaultEOUTEnList"="concat( $FaultEOUTEnList, $defFaultEOUTEn )"!][!//
    [!ENDLOOP!][!//

    [!// Fill up to the 128 NCFs with zeros
    [!VAR "tempBuf"="''"!][!//
    [!FOR "i" = "string-length( $FaultList )" TO "128"!][!//
        [!VAR "tempBuf"="concat( $tempBuf, '0' )"!][!//
        [!VAR "FaultSignalList"="concat( $FaultSignalList, ',' )"!][!//
    [!ENDFOR!][!//
    [!// Append the unused signals
    [!VAR "FaultList"="concat( $FaultList, $tempBuf )"!][!//
    [!VAR "FaultReactionList"="concat( $FaultReactionList, $tempBuf )"!][!//
    [!VAR "FaultRecoveryList"="concat( $FaultRecoveryList, $tempBuf )"!][!//
    [!VAR "FaultTOEnList"="concat( $FaultTOEnList, $tempBuf )"!][!//
    [!VAR "FaultAlarmEnList"="concat( $FaultAlarmEnList, $tempBuf )"!][!//
    [!VAR "FaultNMIEnList"="concat( $FaultNMIEnList, $tempBuf )"!][!//
    [!VAR "FaultEOUTEnList"="concat( $FaultEOUTEnList, $tempBuf )"!][!//

    [!// Handle ./Faults/*/ bearing individual signal settings
    [!LOOP "./Fault/*"!][!//
        [!VAR "idx" = "indexOf( ecu:list( 'Mcem.McemConfigSet.Fault.SignalDesc' ), node:value( SignalDesc ) )"!][!//
        [!VAR "FaultEnabled"="node:when( node:value( FaultDisabled ), '0', '1' )"!][!//
        [!VAR "FaultList"="concat( substring( $FaultList, 1, $idx ), $FaultEnabled, substring( $FaultList, $idx+2 ) )"!][!//

        [!VAR "FaultRecoveryVal"="'0'"!][!//
        [!VAR "FaultReactionVal"="'0'"!][!//
        [!VAR "FaultTOEnVal"="'0'"!][!//
        [!VAR "FaultAlarmEnVal"="'0'"!][!//
        [!VAR "FaultNMIEnVal"="'0'"!][!//
        [!VAR "FaultEOUTEnVal"="'0'"!][!//
        [!IF "$FaultEnabled='1'"!]        
            [!VAR "FaultRecoveryVal"="node:when( contains( node:value( RecoveryType ), 'Sw' ), '1', '0' )"!][!//
			[!IF "$idx=17"!]
			[!VAR "FaultReactionVal"="text:split( text:grep( text:split( $ResetTypes, ',' ), concat( 'NoResetReaction', ':.*' ) ), ':' )[ position()=2 ]"!][!//
			[!ELSE!]
            [!VAR "FaultReactionVal"="text:split( text:grep( text:split( $ResetTypes, ',' ), concat( node:value( ReactionType ), ':.*' ) ), ':' )[ position()=2 ]"!][!//
			[!ENDIF!]
            [!VAR "FaultTOEnVal"="node:when( node:value( RecoveryTimeOutEnabled ), '1', '0' )"!][!//
            [!VAR "FaultAlarmEnVal"="node:when( ((node:value(AlarmIrqEnabled))='true' and (node:value(RecoveryTimeOutEnabled))='true'), '1', '0' )"!][!//
            [!VAR "FaultNMIEnVal"="node:when( node:value( FaultNmiEnabled ), '1', '0' )"!][!//
            [!VAR "FaultEOUTEnVal"="node:when( node:value( ActivateOutputPins ), '1', '0' )"!][!//
        [!ENDIF!]
        [!VAR "FaultRecoveryList"="concat( substring( $FaultRecoveryList, 1, $idx ), $FaultRecoveryVal, substring( $FaultRecoveryList, $idx+2 ) )"!][!//
        [!VAR "FaultReactionList"="concat( substring( $FaultReactionList, 1, $idx ), $FaultReactionVal, substring( $FaultReactionList, $idx+2 ) )"!][!//
        [!VAR "FaultTOEnList"="concat( substring( $FaultTOEnList, 1, $idx ), $FaultTOEnVal, substring( $FaultTOEnList, $idx+2 ) )"!][!//
        [!VAR "FaultAlarmEnList"="concat( substring( $FaultAlarmEnList, 1, $idx ), $FaultAlarmEnVal, substring( $FaultAlarmEnList, $idx+2 ) )"!][!//
        [!VAR "FaultNMIEnList"="concat( substring( $FaultNMIEnList, 1, $idx ), $FaultNMIEnVal, substring( $FaultNMIEnList, $idx+2 ) )"!][!//
        [!VAR "FaultEOUTEnList"="concat( substring( $FaultEOUTEnList, 1, $idx ), $FaultEOUTEnVal, substring( $FaultEOUTEnList, $idx+2 ) )"!][!//
    [!ENDLOOP!][!//

[!IF "0=1"!][!CODE!][!//
/*  Template debug info:
      Fault: '[!"$FaultList"!]'
      Recov: '[!"$FaultRecoveryList"!]'
      React: '[!"$FaultReactionList"!]'
      DefRe: '[!"$defFaultReaction1"!]'
       TOEn: '[!"$FaultTOEnList"!]'
      AlmEn: '[!"$FaultAlarmEnList"!]'
      NMIEn: '[!"$FaultNMIEnList"!]'
      OutEn: '[!"$FaultEOUTEnList"!]' 
*/
[!ENDCODE!][!//
[!//      JAN: Signl: '[!"$FaultSignalList"!]'
[!ENDIF!]

[!// Convert the prepared string lists to register init values
[!VAR "RegsORed"="0"!][!//
[!// NCF Enable Register first
[!CALL "GenBitRegister", "valList"="$FaultList", "comment" = "'NCF Enable Register'"!][!//

[!// Check whether there's alarm callbak if there's at least one fault enabled
[!VAR "AlarmNotif"="'NULL_PTR'"!][!//
[!IF "node:exists( AlarmNotificationApi )"!]
    [!VAR "AlarmNotif"="node:value( AlarmNotificationApi )"!][!//
[!ENDIF!]
[!VAR "AlarmNotif"="normalize-space( translate( $AlarmNotif, '&quot;&apos;', '' ) )"!][!//
[!VAR "AlarmNotif1"="text:toupper( $AlarmNotif )"!][!//
[!VAR "AlarmNotifNULL"="0"!][!//
[!IF "($AlarmNotif1 = 'NULL') or ($AlarmNotif1 = 'NULL_PTR') or ($AlarmNotif1 = 'FALSE')"!][!//
    [!VAR "AlarmNotifNULL"="1"!][!//
[!ENDIF!][!//
[!IF "$RegsORed != 0"!][!//
    [!IF "../McemGeneral/McemAlarmNotificationApi"!][!//
        [!IF "$AlarmNotifNULL != 0"!][!//
            [!ERROR "Valid Alarm Notification callback (/Mcem/ELEMENTS/Mcem/McemConfigSet/*/AlarmNotificationApi) must be provided because some faults are enabled."!][!//
        [!ENDIF!][!//
    [!ENDIF!][!//
[!ENDIF!][!//
[!VAR "AlarmAnyNotifNULL"="bit:or( $AlarmAnyNotifNULL, $AlarmNotifNULL )"!][!//

[!// Remaining NCF configuration registers
[!CALL "GenBitRegister", "valList"="$FaultRecoveryList", "comment" = "'NCF Cfg Register'", "TrueVal"="'MCEM_FCCU_RECOVERY_SW'", "FalseVal"="'MCEM_FCCU_RECOVERY_HW'"!][!//
[!CALL "GenBitRegister", "valList"="$FaultAlarmEnList", "comment" = "'NCF Alarm Interrupt Enable Register'"!][!//
[!CALL "GenBitRegister", "valList"="$FaultNMIEnList", "comment" = "'NCF NMI Enable Register'"!][!//
[!CALL "GenBitRegister", "valList"="$FaultTOEnList", "comment" = "'NCF Recovery Timeout Enable Register'"!][!//
[!CALL "GenBitRegister", "valList"="$FaultEOUTEnList", "comment" = "'NCF EOUT Signaling Enable Register'"!][!//
[!CALL "GenBit2Register", "valList"="$FaultReactionList", "comment" = "'NCF Reaction Type Register'", "Defines"="$ResetTypes"!][!//

[!CODE!][!//
};

[!IF "$AlarmNotifNULL = 0"!][!//
/* The Notification Callback function prototype */ 
extern FUNC(void, MCEM_CODE) [!"node:value(AlarmNotificationApi)"!](uint8 FaultID);
[!CR!]
[!ENDIF!][!//

[!IF "normalize-space(McemConfigTimeOutNotificationAPI) != 'NULL_PTR'"!][!//
/* The Notification Callback function prototype */ 
extern FUNC(void, MCEM_CODE) [!"normalize-space(node:value(McemConfigTimeOutNotificationAPI ))"!] (void);
[!CR!]
[!ENDIF!][!//

/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_5 Public configuration */
CONST(Mcem_ConfigType, MCEM_CONST) [!"$MCEM_Cfg"!] = {
[!IF "$AlarmNotifNULL = 0"!][!//
            /* This function is the Notification Callback */
    &[!"node:value( AlarmNotificationApi )"!],
[!ELSE!][!//
    NULL_PTR,                    /* No Notification Callback provided */
[!ENDIF!][!//
[!IF "normalize-space(McemConfigTimeOutNotificationAPI) != 'NULL_PTR'"!][!//
            /* This function is the Notification Callback */
    &[!"normalize-space(node:value(McemConfigTimeOutNotificationAPI ))"!],
[!ELSE!][!//
    NULL_PTR,                    /* No Notification Callback provided */
[!ENDIF!][!//
    (boolean)[!IF "node:value( McemHardlockedConfiguration )"!]TRUE,[!ELSE!]FALSE,[!ENDIF!][!//
                       /* This configuration will [!IF "node:value( McemHardlockedConfiguration )"!][!ELSE!]not [!ENDIF!]be locked */     
    &Fccu_Config[!"$CfgSuffix"!]             /* Fccu configuration pointer */
};

[!ENDCODE!][!//
[!ENDSELECT!][!//

[!CODE!][!//

#define MCEM_STOP_SEC_CONST_UNSPECIFIED
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_3 precautions to prevent the contents of a header file being included twice */
/* @violates @ref CDD_Mcem[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_PBcfg_C_REF_4 only preprocessor statements and comments before "#include". */
#include "Mcem_MemMap.h"

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

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


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


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


[!ENDCODE!][!//

[!ENDNOCODE!][!//

#ifdef __cplusplus
}
#endif

/** @} */
[!ENDCODE!]
