/**
*   @file    Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!].c
*   @version 1.0.0
*
*   @brief   AUTOSAR Can_43_FLEXCAN - module interface
*   @details Configuration Structures for PostBuild.
*
*   @addtogroup CAN_DRIVER
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : FLEXCAN
*   Dependencies         : 
*
*   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

/**
* @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 Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_1
* Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents 
* of a header file being included more than once
* This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_2
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor directives or comments.
* AUTOSAR imposes the specification of the sections in which certain parts of the driver must be placed.
*
* @section Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_3
* Violates MISRA 2012 Advisory Rule 8.7, Function and objects should not be defined with external linkage if they 
* are referenced in only one translation unit.
*
* @section Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_4
* Violates MISRA 2012 Required Rule 8.4, A compatible declaration shall be visible when an object or function with external linkage is defined.
*
* @section Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_5
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its identifier only appears
* in a single function.
*
* @section Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_6
* Violates MISRA 2012 Required Rule 8.5, An external object or function shall be declared once in one and only one file.
* These functions represent the API of the callback function by user.
*/

/*
   (CAN078) The code file structure shall not be defined within this specification completely.
            At this point it shall be pointed out that the code-file structure shall include the following file named: Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!].c.
            This file shall contain all post-build time configurable parameters.
   (CAN221) VariantPB: (Mix of precompile and Post Build multiple selectable configurable configurations.
*/
/**
* @file           Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!].c
*/

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

[!AUTOSPACING!]
[!NOCODE!]
/*
 Example 1 of valid configuration:
   Source Clock = 8MHz, Bit Rate = 1Mb/sec,
   CanControllerTimeQuanta  = 125ns
      -> Presclaer = 1, CanBit = 8Tq (these ale calculated in background)
   CanControllerPropSeg  = 3, CanControllerSeg1 = 0, CanControllerSeg2 = 1, CanControllerSyncJumpWidth = 0.

 Example 2 of valid configuration:
   Source Clock = 8MHz, Bit Rate = 125Kb/sec,
   CanControllerTimeQuanta  = 1000ns,
      -> Presclaer = 8, CanBit = 8Tq (these ale calculated in background)
   CanControllerPropSeg  = 0, CanControllerSeg1 = 2, CanControllerSeg2 = 2, CanControllerSyncJumpWidth = 2.
*/
[!ENDNOCODE!][!//
[!//
[!NOCODE!][!//
[!INCLUDE "Can_43_FLEXCAN_VersionCheck_Src_PB.m"!][!//
[!ENDNOCODE!][!//
[!//
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/*
* @file           Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!].c
*/
#define CAN_43_FLEXCAN_VENDOR_ID_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C                      43
#define CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C       4
#define CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C       3
#define CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C    1
#define CAN_43_FLEXCAN_SW_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C               1
#define CAN_43_FLEXCAN_SW_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C               0
#define CAN_43_FLEXCAN_SW_PATCH_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C               0

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

/* Check if current file and Can configuration header file are of the same vendor */
#if (CAN_43_FLEXCAN_VENDOR_ID_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_VENDOR_ID)
#error "Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN.h have different vendor ids"
#endif
/* Check if current file and CAN header file are of the same Autosar version */
#if ((CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION) || \
     (CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION) || \
     (CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION))
  #error "AutoSar Version Numbers of Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN.h are different"
#endif
/* Check if current file and CAN header file are of the same Software version */
#if ((CAN_43_FLEXCAN_SW_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_SW_MAJOR_VERSION) || \
     (CAN_43_FLEXCAN_SW_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_SW_MINOR_VERSION) || \
     (CAN_43_FLEXCAN_SW_PATCH_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_SW_PATCH_VERSION))
       #error "Software Version Numbers of Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN.h are different"
#endif

/* Check if current file and Can_IPW configuration header file are of the same vendor */
#if (CAN_43_FLEXCAN_VENDOR_ID_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C  != CAN_43_FLEXCAN_IPW_VENDOR_ID_H)
#error "Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN_IPW.h have different vendor ids"
#endif
/* Check if current file and CAN_IPW header file are of the same Autosar version */
#if ((CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
     (CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_MINOR_VERSION_H) || \
     (CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_REVISION_VERSION_H))
  #error "AutoSar Version Numbers of Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN_IPW.h are different"
#endif
/* Check if current file and CAN_IPW header file are of the same Software version */
#if ((CAN_43_FLEXCAN_SW_MAJOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_SW_MAJOR_VERSION_H) || \
     (CAN_43_FLEXCAN_SW_MINOR_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_SW_MINOR_VERSION_H) || \
     (CAN_43_FLEXCAN_SW_PATCH_VERSION_PBCFG[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_C != CAN_43_FLEXCAN_IPW_SW_PATCH_VERSION_H))
       #error "Software Version Numbers of Can_43_FLEXCAN_PBcfg.c and Can_43_FLEXCAN_IPW.h are different"
#endif

/*==================================================================================================
*                                   GLOBAL FUNCTION PROTOTYPES
==================================================================================================*/
[!IF "node:exists(CanConfigSet/CanController/*[CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'])"!]
#define CAN_43_FLEXCAN_START_SEC_VAR_NO_INIT_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_1 MISRA 2012 Required Directive 4.10 */
#include "Can_43_FLEXCAN_MemMap.h"

#ifdef CAN_43_FLEXCAN_DMA_USED
/* destination DMA buffers */
[!INDENT "0"!]
    [!SELECT "CanConfigSet"!]
        ALIGNED_VARS_START(CAN_VAR, 32)
        [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
            [!IF "CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true' and CanControllerActivation = 'true'"!]
                    /* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_3 MISRA 2012 Advisory Rule 8.7 */
                    /* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_4 MISRA 2012 Required Rule 8.4*/
                    VAR_ALIGN(static VAR(uint8, CAN_VAR) aCanDmaDestBuffer_[!"CanControllerId"!][[!"num:i(CanRxFifo/NumberMBTransferDMA * 80)"!]], 32)
            [!ENDIF!]
        [!ENDLOOP!]
        ALIGNED_VARS_STOP()
    [!ENDSELECT!]
[!ENDINDENT!]
#endif
#define CAN_43_FLEXCAN_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_1 MISRA 2012 Required Directive 4.10  */
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_43_FLEXCAN_MemMap.h"
[!ENDIF!]

#define CAN_43_FLEXCAN_START_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_1 MISRA 2012 Required Directive 4.10 */
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_43_FLEXCAN_MemMap.h"

/**
@brief    Prototype of User Notifications
*/
[!NOCODE!][!INCLUDE "Can_43_FLEXCAN_NotifyCheck_Src_PB.m"!][!ENDNOCODE!][!//
[!NOCODE!][!INCLUDE "Can_43_FLEXCAN_SourceClock.m"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanRxFifoWarningNotification_PB"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanRxFifoOverflowNotification_PB"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanErrorControllerNotification_PB"!][!ENDNOCODE!][!//

[!IF "node:exists(CanGeneral/CanTimeStamp)"!]
    [!IF "CanGeneral/CanTimeStamp/CanRxTimestampNotification != 'NULL_PTR'"!]
extern FUNC(void,CAN_CODE) [!"normalize-space(CanGeneral/CanTimeStamp/CanRxTimestampNotification)"!](VAR(Can_HwHandleType, CAN_VAR) Hoh, VAR(uint32, CAN_VAR) u32TimestampVal);
    [!ENDIF!]
    
    [!IF "CanGeneral/CanTimeStamp/CanTxTimestampNotification != 'NULL_PTR'"!]
extern FUNC(void,CAN_CODE) [!"normalize-space(CanGeneral/CanTimeStamp/CanTxTimestampNotification)"!](VAR(Can_HwHandleType, CAN_VAR) Hoh, VAR(uint32, CAN_VAR) CanTxPduId, VAR(uint32, CAN_VAR) u32TimestampVal);
    [!ENDIF!]
[!ENDIF!]
/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/


/*==================================================================================================
*                                       LOCAL MACROS
==================================================================================================*/

[!NOCODE!]
[!VAR "LoopVar"="0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "HOHCount" = "num:i(count(CanHardwareObject/*))"!]
    [!VAR "additionalHTH" = "0"!]
    [!IF "(../CanGeneral/CanMultiplexedTransmission = 'true')"!]
        [!LOOP "CanHardwareObject/*"!]
            [!IF "(CanObjectType = 'TRANSMIT') and (node:value(CanHwObjectCount) > 1 )"!]
                [!VAR "additionalHTH" = "$additionalHTH + node:value(CanHwObjectCount) - 1 "!]
            [!ENDIF!]
        [!ENDLOOP!]
    [!ENDIF!]
[!ENDSELECT!]
[!VAR "MaxConfiguredMBs" = "num:i($additionalHTH + $HOHCount)"!]
[!ENDNOCODE!]

/* This macro defines the total of HOH configured */
#define CAN_43_FLEXCAN_MAXMBCOUNT_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]  [!WS!][!"$MaxConfiguredMBs"!]U[!CR!]

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

/*==================================================================================================
*                                      LOCAL VARIABLES
==================================================================================================*/
[!/* This section is for global variables, local to this file */!][!//
[!VAR "Tsyncsegment" = "1"!][!/* Sync_seg has 1 Tq length */!][!//
[!NOCODE!][!//
[!/*
    Sync-seg = is the segment that is used to synchronise the nodes on the bus. A bit edge (if there is a data change) is expected during this segment.
    Prop-Seg = is a period of time that is used to compensate for physical delay times within the network.
    Phase-seg1 = is a buffer segment that may be lengthened during resynchronisation to compensate for oscillator drift and positive phase differences between the oscillators of the transmitting and receiving node(s).
    Phase-seg2 = is a buffer segment that may be shortened during resynchronisation (described below) to compensate for negative phase errors and oscillator drift.

    The Sample point is always at the end of Phase-seg1 and is the time at which the bus level is read and interpreted as the value of the current bit.
    Whether transmitting or receiving, all nodes on a single CAN bus must have the same nominal bit time. Bit time is programmable at each node on a CAN Bus and is a function
        of the period of the oscillator local to each node, the value that is user-programmed into a Baud Rate Prescaler (BRP) register in the controller at each node, and the programmed number of time quanta per bit.
    When any node receives a data frame or a remote frame, it is necessary for the receiver to synchronise with the transmitter.
        1. The first is hard synchronisation and occurs at Start-of-Frame (SOF).
        2. For subsequent bits in any received frame, if a bit edge does not occur in the Sync-seg segment of bit time, resynchronisation is automatically invoked and will shorten or lengthen the current bit time depending
            on where the edge occurs. The maximum amount by which the bit time is lengthened or shortened is determined by a user-programmable number of time quanta known as the Synchronisation Jump Width (SJW).
*/!]
[!ENDNOCODE!]
[!VAR "LoopVar"="0"!]
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "TableIdCount" = "0"!]
    [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!] 
        [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true' or CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
            [!VAR "TableIdCount" = "$TableIdCount + count(./CanRxFifo/CanRxFifoTable/*)"!]
        [!ENDIF!]
    [!ENDLOOP!]
    [!IF "$TableIdCount != 0"!]
        #if (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON)
        /**
        * @brief        Can_43_FLEXCAN_RxFiFoTableIdConfigType
        * @details      For RxFifo Legacy
        *                   Identifier FormatA:
        *                       - StandardID: bits [29:19]
        *                       - ExtendedID: bits [29:1]
        *                   Identifier FormatB:
        *                       - StandardID: bits [29:19] & [13:3]
        *                       - ExtendedID: bits [29:16] & [13:0] (only 14 MSB)
        *                   Identifier FormatC:
        *                       - StandardID: bits [31::24] & [23:16] & [15:8] & [7:0] (only 8 MSB)
        *                       - ExtendedID: bits [31::24] & [23:16] & [15:8] & [7:0] (only 8 MSB)
        *               For Enhanced RxFifo
        *
        */
        static CONST(Can_43_FLEXCAN_RxFiFoTableIdConfigType, CAN_CONST) RxFifoTableID_PBConfig0[CAN_43_FLEXCAN_MAXTABLEID_0] =
        {
            [!INDENT "4"!]
            [!VAR "TableIdCountLocal" = "0"!][!//
            [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!] [!//
                [!VAR "ControllerCanHwChannel" = "CanHwChannel"!][!//
                [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true'"!][!//
                    [!VAR "tableidvalue" = "0"!][!//
                    [!LOOP "CanRxFifo/CanRxFifoTable/*/CanRxFifoLegacyTable"!][!//
                        [!VAR "TableIdCountLocal" = "$TableIdCountLocal+1"!][!//
                        [!IF "../../../CanControllerIDAcceptanceMode = 'D'"!][!//
                            [!VAR "tableidvalue" = "0"!][!//
                        [!ELSE!][!//
                            [!VAR "tableidvalue" = "num:i(CanIDValue0)"!][!//
                        [!ENDIF!][!//
                        [!VAR "tablefiltermaskvalue" = "num:i(CanMBFilterMaskValue)"!][!//
                        [!IF "../../../CanControllerIDAcceptanceMode = 'C'"!][!//
                            [!VAR "tableidvalue0" = "bit:shl($tableidvalue,24)"!][!//
                            [!VAR "tableidvalue1" = "bit:shl(num:i(CanIDValue1),16)"!][!//
                            [!VAR "tableidvalue2" = "bit:shl(num:i(CanIDValue2),8)"!][!//
                            [!VAR "tableidvalue3" = "bit:shl(num:i(CanIDValue3),0)"!][!//
                            [!VAR "tableidvalue" = "bit:or($tableidvalue0,$tableidvalue1)"!][!//
                            [!VAR "tableidvalue" = "bit:or($tableidvalue,$tableidvalue2)"!][!//
                            [!VAR "tableidvalue" = "bit:or($tableidvalue,$tableidvalue3)"!][!//
                        [!ELSEIF "CanTableIDType = 'Standard'"!][!//
                            [!IF "../../../CanControllerIDAcceptanceMode = 'A'"!][!//
                                [!VAR "tableidvalue" = "bit:shl($tableidvalue,19)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:shl($tablefiltermaskvalue,19)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue,num:hextoint('0xc0000000'))"!][!//
                            [!ENDIF!][!//
                            [!IF "../../../CanControllerIDAcceptanceMode = 'B'"!][!//
                                [!VAR "tableidvalue0" = "bit:shl($tableidvalue,19)"!][!//
                                [!VAR "tableidvalue1" = "bit:shl(num:i(CanIDValue1),3)"!][!//
                                [!VAR "tableidvalue" = "bit:or($tableidvalue0,$tableidvalue1)"!][!//
                                [!VAR "tablefiltermaskvalue0" = "bit:and($tablefiltermaskvalue,num:hextoint('0x3ff800'))"!][!//
                                [!VAR "tablefiltermaskvalue1" = "bit:and($tablefiltermaskvalue,num:hextoint('0x7ff'))"!][!//
                                [!VAR "tablefiltermaskvalue0" = "bit:shl($tablefiltermaskvalue0,8)"!][!//
                                [!VAR "tablefiltermaskvalue1" = "bit:shl($tablefiltermaskvalue1,3)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue0,$tablefiltermaskvalue1)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue,num:hextoint('0xc000c000'))"!][!//
                            [!ENDIF!][!//
                        [!ELSE!][!//
                            [!IF "../../../CanControllerIDAcceptanceMode = 'A'"!][!//
                                [!VAR "tableidvalue" = "bit:shl($tableidvalue,1)"!][!//
                                [!VAR "tableidvalue" = "bit:bitset($tableidvalue,30)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:shl($tablefiltermaskvalue,1)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue,num:hextoint('0xc0000000'))"!][!//
                            [!ENDIF!][!//
                            [!IF "../../../CanControllerIDAcceptanceMode = 'B'"!][!//
                                [!VAR "tableidvalue0" = "bit:shl($tableidvalue,16)"!][!//
                                [!VAR "tableidvalue" = "bit:or($tableidvalue0,num:i(CanIDValue1))"!][!//
                                [!VAR "tableidvalue" = "bit:bitset($tableidvalue,30)"!][!//
                                [!VAR "tableidvalue" = "bit:bitset($tableidvalue,14)"!][!//
                                [!VAR "tablefiltermaskvalue0" = "bit:and($tablefiltermaskvalue,num:hextoint('0xfffc000'))"!][!//
                                [!VAR "tablefiltermaskvalue1" = "bit:and($tablefiltermaskvalue,num:hextoint('0x3fff'))"!][!//
                                [!VAR "tablefiltermaskvalue0" = "bit:shl($tablefiltermaskvalue0,2)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue0,$tablefiltermaskvalue1)"!][!//
                                [!VAR "tablefiltermaskvalue" = "bit:or($tablefiltermaskvalue,num:hextoint('0xc000c000'))"!][!//
                            [!ENDIF!][!//
                        [!ENDIF!][!//
                        {
                            [!INDENT "8"!]
                            (uint32)[!"num:inttohex($tableidvalue,8)"!]U, /* [!"../@name"!] of [!IF "../../../CanControllerIDAcceptanceMode != 'C'"!]type [!"(CanTableIDType)"!] and[!ENDIF!] format[!"../../../CanControllerIDAcceptanceMode"!] for [!"$ControllerCanHwChannel"!] */
                            (uint32)[!"num:inttohex($tablefiltermaskvalue,8)"!]U  /* Filter Mask (correspond to RXIMR register) */
                            [!ENDINDENT!]
                        }[!IF "$TableIdCount != $TableIdCountLocal"!],[!ENDIF!][!CR!]
                    [!ENDLOOP!][!//
                [!ELSEIF "CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                    [!LOOP "CanRxFifo/CanRxFifoTable/*/CanRxFifoEnhancedTable"!][!//
                        [!VAR "TableIdCountLocal" = "$TableIdCountLocal+1"!][!//
                        [!VAR "EnhancedFilterID1" = "CanTableEnhancedValueFilter1"!]
                        [!VAR "EnhancedFilterID2" = "CanTableEnhancedValueFilter2"!]
                        [!IF "CanTableEnhancedIDType = 'STANDARD'"!]
                            [!VAR "EnhancedFilterID2" = "bit:shl($EnhancedFilterID2, 16)"!]
                        [!ENDIF!]
                        [!IF "CanTableEnhancedSchemeType = 'RANGE_FILTER_SCHEME'"!]
                            [!VAR "EnhancedFilterID2" = "bit:or($EnhancedFilterID2, num:hextoint('0x40000000'))"!][!/* FSCH = b01*/!]
                        [!ELSEIF "CanTableEnhancedSchemeType = 'TWO_FILTER_SCHEME'"!]
                            [!VAR "EnhancedFilterID2" = "bit:or($EnhancedFilterID2, num:hextoint('0x80000000'))"!][!/* FSCH = b10*/!]
                        [!ENDIF!]
                        /* [!"../@name"!]: [!"CanTableEnhancedIDType"!] filter for [!"$ControllerCanHwChannel"!] with Filter Scheme [!"CanTableEnhancedSchemeType"!] */
                        {
                            [!INDENT "8"!]
                            (uint32)[!"num:inttohex($EnhancedFilterID2, 8)"!]U,
                            (uint32)[!"num:inttohex($EnhancedFilterID1, 8)"!]U
                            [!ENDINDENT!]
                        }[!IF "$TableIdCount != $TableIdCountLocal"!],[!ENDIF!][!CR!]
                    [!ENDLOOP!][!//
                [!ENDIF!][!//
            [!ENDLOOP!][!//
            [!ENDINDENT!]
        };
        #endif /* (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON) */
    [!ENDIF!][!//
    [!VAR "LoopVar"="0"!][!//
[!ENDSELECT!][!//
[!ENDINDENT!]
/*==================================================================================================*/
/**
* @brief          Filter Masks
* @details        Filter Masks
*
*/
/*==================================================================================================*/
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    [!INDENT "0"!]
    static CONST(Can_IdType, CAN_CONST) Can_FilterMasks[!"$CSET_NR"!]_PB[CAN_43_FLEXCAN_MAXFILTERCOUNT_[!"$CSET_NR"!]] =
    {
        [!INDENT "4"!]
        [!VAR "filtermaskcount" = "0"!]
        [!VAR "MASK_COUNT"="num:i(count(CanHardwareObject/*/CanHwFilter/CanHwFilterMask))"!]
        [!VAR "END_COMMA"="0"!]
        [!LOOP "node:order(CanHardwareObject/*,'node:value(CanObjectId)')"!] 
           [!SELECT "CanHwFilter"!]
               [!VAR "END_COMMA"="$END_COMMA + 1"!]
               (Can_IdType)[!"num:inttohex(CanHwFilterMask)"!]U[!//
               [!IF "$END_COMMA < $MASK_COUNT"!],[!ELSE!][!WS "1"!][!ENDIF!] /* FilterMasks0[[!"num:i($filtermaskcount)"!]], "[!"@name"!]" */
               [!VAR "filtermaskcount" = "$filtermaskcount + 1"!]
          [!ENDSELECT!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
    [!ENDINDENT!]
[!ENDSELECT!]

[!NOCODE!]
[!/*==================================================================================================*/!]
[!VAR "ARBITRATION_LENGTH" = "8"!]
[!VAR "CAN_REGION_LENGTH" = "512"!]
[!VAR "MBOffsetAddr" = "0"!]
[!VAR "topOfRamAreaAddr" = "'0x80'"!]
[!VAR "maxMBsTable" = "ecu:get('Can.CanConfigSet.CanController.NoMB')"!]
[!VAR "startAddressExpandedMbMem" = "'0x1000'"!]
[!VAR "endAddressExpandedMbMem" = "'0x17FF'"!]
[!VAR "endOfRamAreaCtrlAddr" = "''"!]
[!VAR "currentStartBlockAddr" = "'0x0080'"!]
[!VAR "Can_NextMBBlockAddr" = "''"!]
[!VAR "normalRamBlockNumber" = "num:i(ecu:get('Can.CanConfigSet.CanMB') div 32)"!]
[!SELECT "CanConfigSet"!]
    [!/* create a array which is used to save maximum address for each controller */!]
    [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
        [!IF "text:contains(ecu:get('Can.CanConfigSet.CanExpandedMBMemoryList'), CanHwChannel) and node:exists(CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig) and (../../../CanGeneral/CanSpecifiedRAMBlockSize = 'true')"!]
            [!VAR "endOfRamAreaCtrlAddr" = "concat($endOfRamAreaCtrlAddr, $endAddressExpandedMbMem, ' ')"!]
        [!ELSE!]
            [!VAR "maxMBsCtrl" = "ecu:get(concat('Can.CanConfigSet.', CanHwChannel))"!]
            [!VAR "endOfRamAreaCtrlAddr" = "concat($endOfRamAreaCtrlAddr, num:inttohex(num:hextoint($topOfRamAreaAddr)  + (num:i($maxMBsCtrl) * 16) - 1, 4), ' ')"!]
        [!ENDIF!]
    [!ENDLOOP!]
    [!/* create a array which is used to save start Ram block addresses for each controller */!]
    [!/* Example when Hardware support 2 Ram block and 8 controller: '0x0080 0x0080 0x0080 0x0080 0x0080 0x0080 0x0080 0x0080#0x0280 0x0280 0x0280 0x0280 0x0280 0x0280 0x0280 0x0280' */!]
    [!VAR "countController" = "num:i(ecu:get('Can.CanConfigSet.CanController'))"!]
    [!IF "(ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON')"!]
        [!LOOP "ecu:list('Can.CanConfigSet.CanRamBlockList')"!]
            [!IF "(num:i(text:split(., '_')[4])) > 0"!]
                [!VAR "Can_NextMBBlockAddr" = "concat($Can_NextMBBlockAddr, '#')"!]
            [!ENDIF!]
            [!IF "(num:i(text:split(., '_')[4])) < $normalRamBlockNumber"!][!/* a normal Ram block area's start address is 0x0080 */!]
                [!VAR "currentStartBlockAddr" = "num:i(num:hextoint('0x0080') + (num:i(text:split(., '_')[4]) * num:hextoint('0x0200')))"!]
            [!ELSE!][!/* a expanded Ram block area's start address is 0x1000 */!]
                [!VAR "currentStartBlockAddr" = "num:i(num:hextoint('0x1000') + ((num:i(text:split(., '_')[4]) - $normalRamBlockNumber) * num:hextoint('0x0200')))"!]
            [!ENDIF!]
            [!FOR "i" = "0" TO "$countController - 1"!]
                [!VAR "Can_NextMBBlockAddr" = "concat($Can_NextMBBlockAddr, num:inttohex($currentStartBlockAddr, 4))"!]
                [!IF "$i < ($countController - 1)"!]
                    [!VAR "Can_NextMBBlockAddr" = "concat($Can_NextMBBlockAddr, ' ')"!]
                [!ENDIF!]
            [!ENDFOR!]
        [!ENDLOOP!]
    [!ENDIF!]
[!ENDSELECT!]

[!MACRO "GetMBOffsetAddr_separate", "Controller" = "0", "RamBlock" = "0", "PayloadLength" = "8"!]
    [!VAR "strBlockBefore" = "substring($Can_NextMBBlockAddr, 1, num:i($RamBlock * 7 * ($countController)))"!]
    [!VAR "strBlockAfter"  = "substring($Can_NextMBBlockAddr, num:i(($RamBlock+1) * 7 * ($countController)))"!]
    [!VAR "targetBlockAddr" = "text:split($Can_NextMBBlockAddr, '#')[position()-1 = $RamBlock]"!]
    [!VAR "strBefore" = "substring($targetBlockAddr, 1, num:i($Controller * 7))"!]
    [!VAR "strAfter"  = "substring($targetBlockAddr, num:i(($Controller+1) * 7))"!]
    [!VAR "MBOffsetAddr" = "text:split($targetBlockAddr)[position()-1 = $Controller]"!]
    [!VAR "maxMbAddress" = "text:split($endOfRamAreaCtrlAddr, ' ')[position()-1 = $Controller]"!]
    [!IF "num:hextoint($MBOffsetAddr) > num:hextoint($maxMbAddress)"!]
        [!ERROR!]Exceed MBs configured for Can Controller ID = [!"num:i($Controller)"!] with MB's Payload length = [!"num:i($PayloadLength)"!].[!ENDERROR!]
    [!ENDIF!]
    [!IF "($RamBlock >= $normalRamBlockNumber)"!]
        [!VAR "avaiableRegionRemain" = "$CAN_REGION_LENGTH - num:i(num:mod((num:hextoint($MBOffsetAddr) - num:hextoint($startAddressExpandedMbMem)), $CAN_REGION_LENGTH))"!]
        [!VAR "BlockMaxAddr" = "num:i((num:hextoint($startAddressExpandedMbMem) + (($RamBlock - $normalRamBlockNumber + 1) * $CAN_REGION_LENGTH ) - 1))"!]
    [!ELSE!]
        [!VAR "avaiableRegionRemain" = "$CAN_REGION_LENGTH - num:i(num:mod((num:hextoint($MBOffsetAddr) - num:hextoint('0x80')), $CAN_REGION_LENGTH))"!]
        [!VAR "BlockMaxAddr" = "num:i((num:hextoint('0x80') + (($RamBlock + 1) * $CAN_REGION_LENGTH ) - 1))"!]
    [!ENDIF!]
    [!IF "($avaiableRegionRemain < num:i($ARBITRATION_LENGTH + $PayloadLength)) or (num:hextoint($MBOffsetAddr) > $BlockMaxAddr)"!]
        [!ERROR!]
            Exceed MBs configured for Ram Block [!"num:i($RamBlock)"!] of Can Controller [!"num:i($Controller)"!] with Payload length = [!"num:i($PayloadLength)"!].
        [!ENDERROR!]
    [!ENDIF!]
    [!VAR "targetAddr" = "num:hextoint($MBOffsetAddr)"!]
    [!VAR "targetAddr" = "num:inttohex(num:i($targetAddr + $ARBITRATION_LENGTH + $PayloadLength), 4)"!]
    [!VAR "targetBlockAddr" = "concat($strBefore, $targetAddr, $strAfter)"!]
    [!VAR "Can_NextMBBlockAddr" = "concat($strBlockBefore, $targetBlockAddr, $strBlockAfter)"!]
[!ENDMACRO!]

[!VAR "Can_NextMBAddr" = "'0x0080 0x0080 0x0080 0x0080 0x0080 0x0080 0x0080 0x0080'"!]
[!MACRO "GetMBOffsetAddr_normal", "Controller" = "0", "PayloadLength" = "8", "canHardWareChannel" = "''"!]
    [!VAR "strBefore" = "substring($Can_NextMBAddr, 1, num:i($Controller * 7))"!]
    [!VAR "strAfter"  = "substring($Can_NextMBAddr, num:i(($Controller+1) * 7))"!]
    [!VAR "MBOffsetAddr" = "text:split($Can_NextMBAddr)[position()-1 = $Controller]"!]
    [!VAR "maxMbAddress" = "text:split($endOfRamAreaCtrlAddr, ' ')[position()-1 = $Controller]"!]
    [!IF "num:hextoint($MBOffsetAddr) > num:hextoint($maxMbAddress)"!]
        [!/* When MBOffsetAddr exceed maximum normal address and the controller support expanded MB Memory => update again endOfRamAreaCtrlAddr with new value (endAddressExpandedMbMem) */!]
        [!IF "text:contains(ecu:get('Can.CanConfigSet.CanExpandedMBMemoryList'), $canHardWareChannel) and ($PayloadLength = 64) and (num:hextoint($MBOffsetAddr) < num:hextoint($startAddressExpandedMbMem))"!]
            [!VAR "MBOffsetAddr" = "$startAddressExpandedMbMem"!]
            [!VAR "endOfRamAreaCtrlAddr" = "concat(substring($endOfRamAreaCtrlAddr, 1, num:i($Controller * 7)), $endAddressExpandedMbMem, substring($endOfRamAreaCtrlAddr, num:i(($Controller+1) * 7)))"!]
        [!ELSE!]
            [!ERROR!]Exceed MBs configured for Can Controller ID = [!"num:i($Controller)"!] with MB's Payload length = [!"num:i($PayloadLength)"!].[!ENDERROR!]
        [!ENDIF!]
    [!ENDIF!]
    [!VAR "targetAddr" = "num:hextoint($MBOffsetAddr)"!]
    [!VAR "targetAddr" = "num:i($targetAddr + $ARBITRATION_LENGTH + $PayloadLength)"!]
    [!IF "text:contains(ecu:get('Can.CanConfigSet.CanExpandedMBMemoryList'), $canHardWareChannel) and ($PayloadLength = 64) and ($targetAddr >= num:hextoint($startAddressExpandedMbMem))"!]
        [!VAR "avaiableRegionRemain" = "$CAN_REGION_LENGTH - num:i(num:mod(($targetAddr - num:hextoint($startAddressExpandedMbMem)), $CAN_REGION_LENGTH))"!]
    [!ELSE!]
        [!VAR "avaiableRegionRemain" = "$CAN_REGION_LENGTH - num:i(num:mod(($targetAddr - num:hextoint('0x80')), $CAN_REGION_LENGTH))"!]
    [!ENDIF!]
    [!IF "$avaiableRegionRemain < num:i($ARBITRATION_LENGTH + $PayloadLength)"!]
        [!VAR "targetAddr" = "$targetAddr + $avaiableRegionRemain"!]
    [!ENDIF!]
    [!VAR "targetAddr" = "num:inttohex($targetAddr,4)"!]
    [!VAR "Can_NextMBAddr" = "concat($strBefore, $targetAddr, $strAfter)"!]
[!ENDMACRO!]

[!/*==================================================================================================*/!]
[!/* create a array which is used to save the number MB of all ram block for each controllers */!]
[!/* Example when Hardware support 2 Ram block and 8 controller(configure 2 controller only): '32 32#32 32' */!]
[!SELECT "CanConfigSet"!]
    [!VAR "Can_MBsPerBlockTable" = "''"!]
    [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
        [!IF "CanControllerId > 0"!]
            [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, '#')"!]
        [!ENDIF!]
        [!IF "(ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON') and (node:exists('CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig'))"!]
            [!IF "../../../CanGeneral/CanSpecifiedRAMBlockSize"!]
                [!FOR "i" = "0" TO "num:i(count(ecu:list('Can.CanConfigSet.CanRamBlockList')) - 1)"!]
                    [!IF "$i >= $normalRamBlockNumber"!][!/* when use don't use expanded ram blocks , the default value Size is 7 MBs */!]
                        [!VAR "MBsPerBlock" = "'7'"!]
                    [!ELSE!][!/* when use don't use normal ram blocks , the default value Size is 32 MBs */!]
                        [!VAR "MBsPerBlock" = "'32'"!]
                    [!ENDIF!]
                    [!LOOP "node:order(CanRAMBlock/*, 'CanRAMBlockName')"!]
                        [!IF "CanRAMBlockName = concat('CAN_RAM_BLOCK_', num:i($i))"!]
                            [!VAR "payload" = "text:split(CanRAMBlockSizeValue, '_')[position() - 1 = 1]"!]
                            [!VAR "MBsPerBlock" = "num:i(num:i('512') div num:i($ARBITRATION_LENGTH + $payload))"!]
                        [!ENDIF!]
                    [!ENDLOOP!]
                    [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, $MBsPerBlock)"!]
                    [!IF "$i < num:i(count(ecu:list('Can.CanConfigSet.CanRamBlockList')) - 1)"!]
                        [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, ' ')"!]
                    [!ENDIF!]
                [!ENDFOR!]
            [!ELSE!]
                [!VAR "payload" = "text:split(../../../CanGeneral/MBDSR,'_')[position() - 1 = 1]"!]
                [!VAR "MBsPerBlock" = "num:i(num:i('512') div num:i($ARBITRATION_LENGTH + $payload))"!]
                [!FOR "i" = "0" TO "num:i(count(text:split(ecu:get('Can.CanConfigSet.CanRamBlockList'), ',')) - 1)"!]
                    [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, $MBsPerBlock)"!]
                    [!IF "$i < num:i(count(text:split(ecu:get('Can.CanConfigSet.CanRamBlockList'), ',')) - 1)"!]
                        [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, ' ')"!]
                    [!ENDIF!]
                [!ENDFOR!]
            [!ENDIF!]
        [!ELSE!]
            [!FOR "i" = "0" TO "num:i(count(text:split(ecu:get('Can.CanConfigSet.CanRamBlockList'), ',')) - 1)"!]
                [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, '32')"!]
                [!IF "$i < num:i(count(text:split(ecu:get('Can.CanConfigSet.CanRamBlockList'), ',')) - 1)"!]
                    [!VAR "Can_MBsPerBlockTable" = "concat($Can_MBsPerBlockTable, ' ')"!]
                [!ENDIF!]
            [!ENDFOR!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]

[!/*==================================================================================================*/!]

[!VAR "MBIndex" = "0"!]
[!VAR "Can_BlockStartAddrTable" = "'0x0080 0x0280 0x0480 0x0680 0x1000 0x1200 0x1400 0x1600'"!]
[!MACRO "GetMBIndex_FD", "Controller" = "0", "MBAddr" = "'0x0080'", "PayloadLength" = "8"!]
    [!VAR "Can_BlockMBsTable" = "text:split($Can_MBsPerBlockTable, '#')[position() - 1 = $Controller]"!]
    [!IF "num:hextoint($MBAddr) >= num:hextoint($startAddressExpandedMbMem)"!]
        [!VAR "blockNumber" = "num:i($normalRamBlockNumber + ((num:hextoint($MBAddr) - num:hextoint($startAddressExpandedMbMem)) div num:i('512')))"!]
    [!ELSE!]
        [!VAR "blockNumber" = "num:i((num:hextoint($MBAddr) - num:hextoint('0x80')) div num:i('512'))"!]
    [!ENDIF!]
    [!VAR "startMBIdxOfRegion" = "'0'"!]
    [!FOR "i" = "1" TO "$blockNumber"!]
        [!VAR "MBsPerBlock" = "text:split($Can_BlockMBsTable, ' ')[position() = num:i($i)]"!]
        [!VAR "startMBIdxOfRegion" = "num:i($startMBIdxOfRegion + $MBsPerBlock)"!]
    [!ENDFOR!]
    [!VAR "BlockStartAddr" = "text:split($Can_BlockStartAddrTable, ' ')[position() - 1 = num:i($blockNumber)]"!]
    [!VAR "MBIndexOffset" = "num:i((num:hextoint($MBAddr) - num:hextoint($BlockStartAddr)) div num:i($ARBITRATION_LENGTH + $PayloadLength))"!]
    [!VAR "MBIndex" = "num:i($startMBIdxOfRegion + $MBIndexOffset)"!]
[!ENDMACRO!]
[!/*==================================================================================================*/!]

[!VAR "Can_MaxMBCountTable" = "'0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00'"!]
[!MACRO "Update_EndMBIndex", "Controller" = "0", "can_MBIndex" = "0"!]
    [!VAR "strBefore" = "substring($Can_MaxMBCountTable, 1, num:i($Controller * 5))"!]
    [!VAR "strAfter"  = "substring($Can_MaxMBCountTable, num:i(($Controller+1) * 5))"!]
    [!VAR "targetIndex" = "text:split($Can_MaxMBCountTable, ' ')[position() - 1 = $Controller]"!]
    [!VAR "targetIndex" = "num:hextoint($targetIndex)"!]
    [!IF "$targetIndex < num:i($can_MBIndex + 1) "!]
        [!VAR "targetIndex" = "num:i($can_MBIndex + 1)"!]
    [!ENDIF!]
    [!VAR "targetIndex" = "num:inttohex($targetIndex, 2)"!]
    [!VAR "Can_MaxMBCountTable" = "concat($strBefore, $targetIndex, $strAfter)"!]
[!ENDMACRO!]
[!/*==================================================================================================*/!]
[!ENDNOCODE!]
/*==================================================================================================*/
/**
* @brief          Information about message buffers
* @details        (CAN100)Several TX hardware objects with unique HTHs may be configured. The CanIf module provides the HTH as parameter of the TX request. See Figure 7-2 for a possible configuration.
*
*/
/*==================================================================================================*/
[!VAR "FirstInitEnhancedFifo" = "0"!]
[!VAR "EnhancedFifoInterruptEnable" = "0"!] [!/* use to save IT enable for each controller */!]
[!VAR "TimestampEnabled" = "0"!]
[!IF "node:exists(CanGeneral/CanTimeStamp)"!]
    [!VAR "TimestampEnabled" = "1"!]
[!ENDIF!]
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!] 
    static CONST(Can_43_FLEXCAN_MBConfigObjectType, CAN_CONST) Can_43_FLEXCAN_MessageBufferConfigs[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][CAN_43_FLEXCAN_MAXMBCOUNT_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]] =
    {
        [!INDENT "4"!]
        [!VAR "CanControllerIdValue"="0"!]
        [!VAR "ObjectID"="0"!]
        [!VAR "END_COMMA"="0"!]
        [!VAR "MASK_COUNT"="num:i(count(CanHardwareObject/*))"!]
        [!LOOP "node:order(CanHardwareObject/*,'node:value(CanObjectId)')"!]
            [!VAR "END_COMMA"="$END_COMMA + 1"!]
            [!IF "node:ref(CanControllerRef)/CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true' and (bit:and($FirstInitEnhancedFifo, (bit:shl(1, node:ref(CanControllerRef)/CanControllerId)))) = 0"!]
            /* [!"@name"!] Message Buffer Enhanced RxFiFo of Can Controller ID = [!SELECT "node:ref(CanControllerRef)"!][!"num:i(CanControllerId)"!]U[!ENDSELECT!] */
            {
                [!INDENT "8"!]
                /* Found The first MB of the controller which is used for Enhanced RxFifo */
                (Can_HwHandleType)CAN_43_FLEXCAN_MAXMASKCOUNT, /* uIdMaskIndex */
                [!SELECT "node:ref(CanControllerRef)"!]
                    (uint8)[!"num:i(CanControllerId)"!]U, /* ControllerId  - based on the order from CanController list */
                [!ENDSELECT!]
                CAN_43_FLEXCAN_[!"CanIdType"!], /* ID type: EXTENDED, STANDARD, MIXED */
                CAN_43_FLEXCAN_[!"CanObjectType"!], /* Receive/Transmit MB configuration */
                (Can_IdType)0x0U, /* MessageId (not used) */
                (uint8)[!"num:inttohex(CanMBPrio)"!]U, /* Local priority bits used for arbitration */
                (Can_HwHandleType)[!"num:inttohex(CanObjectId)"!]U, /* Hardware Object ID */
                [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                    [!IF " (node:exists(CanFdPaddingValue)) and (node:exists(../../../CanConfigSet/CanController/*/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig)) and (node:fallback(CanObjectType,'TRANSMIT') = 'TRANSMIT')"!]
                        (uint8)[!"num:inttohex(CanFdPaddingValue)"!], /**< @brief Padding value for MB > 8 bytes */
                    [!ELSE!]
                        (uint8)0U,
                    [!ENDIF!]
                #endif
                [!ENDIF!]
                /* Read/Write period reference used when POLLING mode is selected for the controller */
                [!IF "node:exists(CanMainFunctionRWPeriodRef)"!]
                    (uint8)[!"node:ref(CanMainFunctionRWPeriodRef)/@index"!]U,    /* HOH reference to [!"node:ref(CanMainFunctionRWPeriodRef)/@name"!] */
                [!ELSE!]
                    (uint8)0U,   /* HOH configured for INTERRUPT mode, reference not used */
                [!ENDIF!][!//
                FLEXCAN_ENHANCED_RXFIFO_OFFSET_U16,       /* Address of Message Buffer */
            #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                (uint8)64U,
            #else
                (uint8)8U,
            #endif
                (uint8)0U    /* The index of MB in message buffer memory (not used) */
                #if (CAN_43_FLEXCAN_TRIGGER_TRANSMIT_EN == STD_ON)
                [!IF "(node:exists(CanTriggerTransmitEnable) and (CanTriggerTransmitEnable ='true'))"!]
                    /* The parameter is used to detect the MB which run with trigger transmit feature */
                    ,(boolean)TRUE
                [!ELSE!]
                    /* The parameter is used to detect the MB which run with trigger transmit feature */
                    ,(boolean)FALSE
                [!ENDIF!]
                #endif
                [!IF "(node:exists(CanHardwareObjectUsesPolling) and (CanHardwareObjectUsesPolling = 'true')) or ((node:ref(CanControllerRef)/CanRxProcessing = 'POLLING') and (CanObjectType = 'RECEIVE'))"!]
                    /* The parameter is used to detect the MB which is use Polling or Interrupt */
                    ,(boolean)TRUE /* [!"@name"!] uses Polling */
                    [!IF "node:ref(CanControllerRef)/CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true' and node:ref(CanControllerRef)/CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true'"!]
                        [!ERROR!]
                            When enhanced RxFiFo is enabled: DMA can not used in POLLING mode ([!"name(node:ref(CanControllerRef))"!]). Please configure Can Rx Processing Type as INTERRUPT Or MIXED (uncheck CanHardwareObjectUsesPolling node in the Message buffer used for enhanced fifo _[!"name(.)"!]).
                        [!ENDERROR!]
                    [!ENDIF!]
                [!ELSE!]
                    /* The parameter is used to detect the MB which is use Polling or Interrupt */
                    ,(boolean)FALSE /* [!"@name"!] uses Interrupt */
                    [!VAR "EnhancedFifoInterruptEnable" = "bit:or($EnhancedFifoInterruptEnable, (bit:shl(1, node:ref(CanControllerRef)/CanControllerId)))"!][!/* This Controller is enable IT enhanced RxFifo */!]
                [!ENDIF!]
                [!IF "$TimestampEnabled = 1"!]
                    #if (defined(CAN_43_FLEXCAN_MESSAGE_BUFFER_TIMESTAMP_USED) || defined(CAN_43_FLEXCAN_HIGH_RESOLUTION_TIMESTAMP_USED))
                        [!IF "CanTimeStampEnable = 'true'"!]
                        ,(boolean)TRUE
                        [!ELSE!]
                        ,(boolean)FALSE
                        [!ENDIF!]
                    #endif
                [!ENDIF!]
                [!ENDINDENT!]
                [!VAR "FirstInitEnhancedFifo" = "bit:or($FirstInitEnhancedFifo, (bit:shl(1, node:ref(CanControllerRef)/CanControllerId)))"!]
            }
            [!ELSEIF "(../../../CanGeneral/CanMultiplexedTransmission = 'true') and (CanObjectType = 'TRANSMIT') and (node:value(CanHwObjectCount) >= 1 )"!]
                [!VAR "objectid"="0"!]
                [!FOR "objectid" = "0" TO "num:i(node:value(CanHwObjectCount) - 1 )"!]
                    /* [!"@name"!] Message Buffer of Can Controller ID = [!SELECT "node:ref(CanControllerRef)"!][!"num:i(CanControllerId)"!]U[!ENDSELECT!] */
                    {
                        [!INDENT "8"!]
                        (Can_HwHandleType)CAN_43_FLEXCAN_MAXMASKCOUNT, /* uIdMaskIndex */
                        [!SELECT "node:ref(CanControllerRef)"!]
                            (uint8)[!"num:i(CanControllerId)"!]U, /* ControllerId  - based on the order from CanController list */
                        [!ENDSELECT!]
                        CAN_43_FLEXCAN_[!"CanIdType"!], /* ID type: EXTENDED, STANDARD, MIXED */
                        CAN_43_FLEXCAN_[!"CanObjectType"!], /* Receive/Transmit MB configuration */
                        [!IF "node:exists(CanHwFilter/CanHwFilterCode)"!]
                            (Can_IdType)[!"num:inttohex(CanHwFilter/CanHwFilterCode)"!]U, /* MessageId */
                        [!ELSE!]
                            (Can_IdType)0x0U, /* MessageId */
                        [!ENDIF!]
                        (uint8)[!"num:inttohex(CanMBPrio)"!]U, /* Local priority bits used for arbitration */
                        (Can_HwHandleType)[!"num:inttohex(CanObjectId)"!]U, /* Hardware Object ID */
                        [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                        #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                            [!IF " (node:exists(CanFdPaddingValue)) and (node:exists(../../../CanConfigSet/CanController/*/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig)) and (node:fallback(CanObjectType,'TRANSMIT') = 'TRANSMIT')"!]
                                (uint8)[!"num:inttohex(CanFdPaddingValue)"!], /**< @brief Padding value for MB > 8 bytes */
                            [!ELSE!]
                                (uint8)0U,
                            [!ENDIF!]
                        #endif
                        [!ENDIF!]
                        /* Read/Write period reference used when POLLING mode is selected for the controller */
                        [!IF "node:exists(CanMainFunctionRWPeriodRef)"!]
                            (uint8)[!"node:ref(CanMainFunctionRWPeriodRef)/@index"!]U,    /* HOH reference to [!"node:ref(CanMainFunctionRWPeriodRef)/@name"!] */
                        [!ELSE!]
                            (uint8)0U,   /* HOH configured for INTERRUPT mode, reference not used */
                        [!ENDIF!][!//
                        [!/* Determine Address and payload length of MB */!]
                        [!SELECT "node:ref(CanControllerRef)"!]
                            [!VAR "controllerID" = "num:i(CanControllerId)"!]
                        [!ENDSELECT!]
                        [!IF "(ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON') and (node:exists(concat('../../CanController/', text:split(CanControllerRef, '/')[position()-1 = 4],'/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig')))"!]
                            [!IF "(../../../CanGeneral/CanSpecifiedRAMBlockSize = 'true')"!]
                                [!SELECT "node:ref(CanRAMBlockRef)"!]
                                    [!VAR "dataLength" = "substring-before(substring-after(CanRAMBlockSizeValue,'_'),'_')"!]
                                    [!VAR "blockNumber" = "substring-after(CanRAMBlockName, 'CAN_RAM_BLOCK_')"!]
                                [!ENDSELECT!]
                                [!CALL "GetMBOffsetAddr_separate", "Controller" = "$controllerID", "RamBlock" = "$blockNumber", "PayloadLength" = "$dataLength"!][!//
                                /* Ram block [!"$blockNumber"!] - Payload [!"$dataLength"!]*/
                                (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                                (uint8)[!"num:i($dataLength)"!]U,    /* Payload lenth of Message Buffer */
                                [!CALL "GetMBIndex_FD", "Controller" = "$controllerID", "MBAddr" = "$MBOffsetAddr", "PayloadLength" = "$dataLength"!]
                                (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                            [!ELSE!][!//
                                [!/* Calculate address based on MBDSR */!][!//
                                [!VAR "dataLength" = "substring-before(substring-after(../../../CanGeneral/MBDSR,'_'),'_')"!][!//
                                [!CALL "GetMBOffsetAddr_normal", "Controller" = "$controllerID", "PayloadLength" = "$dataLength", "canHardWareChannel" = "node:ref(CanControllerRef)/CanHwChannel"!]
                                (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                                (uint8)[!"num:i($dataLength)"!]U,    /* Payload lenth of Message Buffer */
                                [!CALL "GetMBIndex_FD", "Controller" = "$controllerID", "MBAddr" = "$MBOffsetAddr", "PayloadLength" = "$dataLength"!]
                                (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                            [!ENDIF!]
                        [!ELSE!][!//
                            [!/* Calculate address for default case 8Bytes */!][!//
                            [!CALL "GetMBOffsetAddr_normal", "Controller" = "$controllerID", "PayloadLength" = "8", "canHardWareChannel" = "node:ref(CanControllerRef)/CanHwChannel"!][!//
                            (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                            (uint8)8U,    /* Payload lenth of Message Buffer */
                            [!VAR "MBIndex" = "num:i((num:hextoint($MBOffsetAddr) - num:hextoint('0x80')) div (num:i($ARBITRATION_LENGTH + 8)))"!]
                            (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                        [!ENDIF!]
                        [!CALL "Update_EndMBIndex", "Controller" = "$controllerID", "can_MBIndex" = "$MBIndex"!]
                        #if (CAN_43_FLEXCAN_TRIGGER_TRANSMIT_EN == STD_ON)
                        [!IF "(node:exists(CanTriggerTransmitEnable) and (CanTriggerTransmitEnable ='true'))"!]
                            /* The parameter is used to detect the MB which run with trigger transmit feature */
                            ,(boolean)TRUE
                        [!ELSE!]
                            /* The parameter is used to detect the MB which run with trigger transmit feature */
                            ,(boolean)FALSE
                        [!ENDIF!]
                        #endif
                        [!IF "(node:exists(CanHardwareObjectUsesPolling) and (CanHardwareObjectUsesPolling = 'true')) or ((node:ref(CanControllerRef)/CanRxProcessing = 'POLLING') and (CanObjectType = 'RECEIVE')) or ((node:ref(CanControllerRef)/CanTxProcessing = 'POLLING') and (CanObjectType = 'TRANSMIT'))"!]
                            /* The parameter is used to detect the MB which is use Polling or Interrupt */
                            ,(boolean)TRUE /* [!"@name"!] uses Polling */
                        [!ELSE!]
                            /* The parameter is used to detect the MB which is use Polling or Interrupt */
                            ,(boolean)FALSE /* [!"@name"!] uses Interrupt */
                        [!ENDIF!]
                        [!IF "$TimestampEnabled = 1"!]
                            #if (defined(CAN_43_FLEXCAN_MESSAGE_BUFFER_TIMESTAMP_USED) || defined(CAN_43_FLEXCAN_HIGH_RESOLUTION_TIMESTAMP_USED))
                                [!IF "CanTimeStampEnable = 'true'"!]
                                ,(boolean)TRUE
                                [!ELSE!]
                                ,(boolean)FALSE
                                [!ENDIF!]
                            #endif
                        [!ENDIF!]
                        [!ENDINDENT!]
                    }[!IF "$objectid < num:i(node:value(CanHwObjectCount) - 1 )"!],[!CR!][!ENDIF!][!//
                [!ENDFOR!]
            [!ELSE!]
                /* [!"@name"!] Message Buffer of Can Controller ID = [!SELECT "node:ref(CanControllerRef)"!][!"num:i(CanControllerId)"!]U[!ENDSELECT!] */
                {
                    [!INDENT "8"!]
                    [!IF "CanObjectType = 'RECEIVE'"!]
                        [!IF "CanHandleType = 'BASIC'"!]
                            [!IF "node:exists(CanHwFilter/CanHwFilterMask)"!]
                                (Can_HwHandleType)[!"num:inttohex(CanObjectId)"!]U, /* uIdMaskIndex */
                            [!ENDIF!] 
                        [!ELSE!]
                            (Can_HwHandleType)CAN_43_FLEXCAN_MAXMASKCOUNT, /* uIdMaskIndex */
                        [!ENDIF!]
                    [!ELSE!]
                        (Can_HwHandleType)CAN_43_FLEXCAN_MAXMASKCOUNT, /* uIdMaskIndex */
                    [!ENDIF!]
                    [!SELECT "node:ref(CanControllerRef)"!]
                        (uint8)[!"num:i(CanControllerId)"!]U, /* ControllerId  - based on the order from CanController list */
                    [!ENDSELECT!]
                    CAN_43_FLEXCAN_[!"CanIdType"!], /* ID type: EXTENDED, STANDARD, MIXED */
                    CAN_43_FLEXCAN_[!"CanObjectType"!], /* Receive/Transmit MB configuration */
                    [!IF "node:exists(CanHwFilter/CanHwFilterCode)"!]
                        (Can_IdType)[!"num:inttohex(CanHwFilter/CanHwFilterCode)"!]U, /* MessageId */
                    [!ELSE!]
                        (Can_IdType)0x0U, /* MessageId */
                    [!ENDIF!]
                    (uint8)[!"num:inttohex(CanMBPrio)"!]U, /* Local priority bits used for arbitration */
                    (Can_HwHandleType)[!"num:inttohex(CanObjectId)"!]U, /* Hardware Object ID */
                    [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                    #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                        [!IF " (node:exists(CanFdPaddingValue)) and (node:exists(../../../CanConfigSet/CanController/*/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig)) and (node:fallback(CanObjectType,'TRANSMIT') = 'TRANSMIT')"!]
                            (uint8)[!"num:inttohex(CanFdPaddingValue)"!], /**< @brief Padding value for MB > 8 bytes */
                        [!ELSE!]
                            (uint8)0U,
                        [!ENDIF!]
                    #endif
                    [!ENDIF!]
                    /* Read/Write period reference used when POLLING mode is selected for the controller */
                    [!IF "node:exists(CanMainFunctionRWPeriodRef)"!]
                        (uint8)[!"node:ref(CanMainFunctionRWPeriodRef)/@index"!]U,    /* HOH reference to [!"node:ref(CanMainFunctionRWPeriodRef)/@name"!] */
                    [!ELSE!]
                        (uint8)0U,   /* HOH configured for INTERRUPT mode, reference not used */
                    [!ENDIF!][!//
                    [!/* Determine Address and payload length of MB*/!]
                    [!SELECT "node:ref(CanControllerRef)"!][!//
                        [!VAR "controllerID" = "num:i(CanControllerId)"!][!//
                    [!ENDSELECT!][!//
                    [!IF "(ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON') and (node:exists(concat('../../CanController/', text:split(CanControllerRef, '/')[position()-1 = 4],'/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig')))"!]
                        [!IF "(../../../CanGeneral/CanSpecifiedRAMBlockSize = 'true')"!]
                            [!SELECT "node:ref(CanRAMBlockRef)"!]
                                [!VAR "dataLength" = "substring-before(substring-after(CanRAMBlockSizeValue,'_'),'_')"!]
                                [!VAR "blockNumber" = "substring-after(CanRAMBlockName, 'CAN_RAM_BLOCK_')"!]
                            [!ENDSELECT!]
                            [!CALL "GetMBOffsetAddr_separate", "Controller" = "$controllerID", "RamBlock" = "$blockNumber", "PayloadLength" = "$dataLength"!][!//
                            /* Ram block [!"$blockNumber"!] - Payload [!"$dataLength"!]*/
                            (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                            (uint8)[!"num:i($dataLength)"!]U,    /* Payload lenth of Message Buffer */
                            [!CALL "GetMBIndex_FD", "Controller" = "$controllerID", "MBAddr" = "$MBOffsetAddr", "PayloadLength" = "$dataLength"!]
                            (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                        [!ELSE!][!//
                            [!/* Calculate address based on MBDSR */!][!//
                            [!VAR "dataLength" = "substring-before(substring-after(../../../CanGeneral/MBDSR,'_'),'_')"!][!//
                            [!CALL "GetMBOffsetAddr_normal", "Controller" = "$controllerID", "PayloadLength" = "$dataLength", "canHardWareChannel" = "node:ref(CanControllerRef)/CanHwChannel"!][!//
                            (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                            (uint8)[!"num:i($dataLength)"!]U,    /* Payload lenth of Message Buffer */
                            [!CALL "GetMBIndex_FD", "Controller" = "$controllerID", "MBAddr" = "$MBOffsetAddr", "PayloadLength" = "$dataLength"!]
                            (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                        [!ENDIF!]
                    [!ELSE!][!//
                        [!/* Calculate address for default case 8Bytes */!][!//
                        [!CALL "GetMBOffsetAddr_normal", "Controller" = "$controllerID", "PayloadLength" = "8", "canHardWareChannel" = "node:ref(CanControllerRef)/CanHwChannel"!][!//
                        (uint16)[!"$MBOffsetAddr"!]U,       /* Address of Message Buffer  */
                        (uint8)8U,    /* Payload lenth of Message Buffer */
                        [!VAR "MBIndex" = "num:i((num:hextoint($MBOffsetAddr) - num:hextoint('0x80')) div (num:i($ARBITRATION_LENGTH + 8)))"!]
                        (uint8)[!"$MBIndex"!]U    /* The index of MB in message buffer memory */
                        [!IF "$MBIndex = 0"!]
                            [!SELECT "node:ref(CanControllerRef)"!]
                                [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true'"!]
                                    [!VAR "RxfifoMBsNumber" = "num:i((num:i(substring-after(./CanRxFifo/CanRxFifoFiltersNumber,'FILTERS_NUMBER_')) div 4) + 6)"!]
                                    [!FOR "i" = "1" TO "num:i($RxfifoMBsNumber - 1)"!] [!// Loop MBs for Rxfifo (if Rxfifo is enabled)
                                        [!CALL "GetMBOffsetAddr_normal", "Controller" = "$controllerID", "PayloadLength" = "8", "canHardWareChannel" = "CanHwChannel"!]
                                    [!ENDFOR!]
                                    [!VAR "MBIndex" =  "num:i($RxfifoMBsNumber - 1)"!] [!// Update the number of MBs occupied by RxFIFO
                                [!ENDIF!]
                            [!ENDSELECT!]
                        [!ENDIF!]
                    [!ENDIF!]
                    [!CALL "Update_EndMBIndex", "Controller" = "$controllerID", "can_MBIndex" = "$MBIndex"!]
                    #if (CAN_43_FLEXCAN_TRIGGER_TRANSMIT_EN == STD_ON)
                    [!IF "(node:exists(CanTriggerTransmitEnable) and (CanTriggerTransmitEnable ='true'))"!]
                        /* The parameter is used to detect the MB which run with trigger transmit feature */
                        ,(boolean)TRUE
                    [!ELSE!]
                        /* The parameter is used to detect the MB which run with trigger transmit feature */
                        ,(boolean)FALSE
                    [!ENDIF!]
                    #endif
                    [!IF "(node:exists(CanHardwareObjectUsesPolling) and (CanHardwareObjectUsesPolling = 'true')) or ((node:ref(CanControllerRef)/CanRxProcessing = 'POLLING') and (CanObjectType = 'RECEIVE')) or ((node:ref(CanControllerRef)/CanTxProcessing = 'POLLING') and (CanObjectType = 'TRANSMIT'))"!]
                        /* The parameter is used to detect the MB which is use Polling or Interrupt */
                        ,(boolean)TRUE /* [!"@name"!] uses Polling */
                    [!ELSE!]
                        /* The parameter is used to detect the MB which is use Polling or Interrupt */
                        ,(boolean)FALSE /* [!"@name"!] uses Interrupt */
                    [!ENDIF!]
                    [!IF "$TimestampEnabled = 1"!]
                        #if (defined(CAN_43_FLEXCAN_MESSAGE_BUFFER_TIMESTAMP_USED) || defined(CAN_43_FLEXCAN_HIGH_RESOLUTION_TIMESTAMP_USED))
                            [!IF "CanTimeStampEnable = 'true'"!]
                            ,(boolean)TRUE
                            [!ELSE!]
                            ,(boolean)FALSE
                            [!ENDIF!]
                        #endif
                    [!ENDIF!]
                    [!ENDINDENT!]
                }[!//
            [!ENDIF!][!//
            [!IF "$END_COMMA < $MASK_COUNT"!],[!ENDIF!][!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
[!ENDSELECT!]
[!ENDINDENT!]
/*==================================================================================================*/
/**
* @brief          Configuration of FlexCan controller
* @details        Configuration of FlexCan controller
*
*/
[!INDENT "0"!]
[!VAR "LoopVar"="0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    [!LOOP "CanController/*"!]
        [!VAR "MASK_COUNT2"="num:i(count(CanControllerBaudrateConfig/*))"!]
        [!VAR "END_COMMA2"="0"!]
        /* Compiler_Warning: this warning due to behavior of compiler depend on configs. */
        static CONST(Can_43_FLEXCAN_ControllerBaudrateConfigType, CAN_CONST) Can_43_FLEXCAN_ControllerBaudrateCfgSet_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][[!"num:i(count(CanControllerBaudrateConfig/*))"!]] =
        {
            [!INDENT "4"!]
            [!LOOP "CanControllerBaudrateConfig/*"!]
                [!NOCODE!]
                [!VAR "END_COMMA2"="$END_COMMA2 + 1"!]
                [!/*
                Sync-seg = is the segment that is used to synchronise the nodes on the bus. A bit edge (if there is a data change) is expected during this segment.
                Prop-Seg = is a period of time that is used to compensate for physical delay times within the network.
                Phase-seg1 = is a buffer segment that may be lengthened during resynchronisation to compensate for oscillator drift and positive phase differences between the oscillators of the transmitting and receiving node(s).
                Phase-seg2 = is a buffer segment that may be shortened during resynchronisation (described below) to compensate for negative phase errors and oscillator drift.

                The Sample point is always at the end of Phase-seg1 and is the time at which the bus level is read and interpreted as the value of the current bit.
                Whether transmitting or receiving, all nodes on a single CAN bus must have the same nominal bit time. Bit time is programmable at each node on a CAN Bus and is a function
                    of the period of the oscillator local to each node, the value that is user-programmed into a Baud Rate Prescaler (BRP) register in the controller at each node, and the programmed number of time quanta per bit.

                When any node receives a data frame or a remote frame, it is necessary for the receiver to synchronise with the transmitter.
                    1. The first is hard synchronisation and occurs at Start-of-Frame (SOF).
                    2. For subsequent bits in any received frame, if a bit edge does not occur in the Sync-seg segment of bit time, resynchronisation is automatically invoked and will shorten or lengthen the current bit time depending
                        on where the edge occurs. The maximum amount by which the bit time is lengthened or shortened is determined by a user-programmable number of time quanta known as the Synchronisation Jump Width (SJW).
                */!]
                [!/* Make the selection of source clock: from MCU or from CAN bus. */!]
                [!VAR "OutCanClockFrequencyFromMcu" = "0"!]
                [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                    [!VAR "OutCanClockFrequencyFromMcu_Alternate" = "0"!]
                [!ENDIF!]
                [!CALL "CanClockFrequency_M"!]
                [!VAR "CANClockFrequency" = "$OutCanClockFrequencyFromMcu"!][!/* Get the clock from MCU */!]
                [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                    [!VAR "CANClockFrequency_Alternate" = "$OutCanClockFrequencyFromMcu_Alternate"!][!/* Get the clock from MCU */!]
                [!ENDIF!]
                [!/* Calculate the prescaler */!]
                [!VAR "Prescaler" = "num:i(CanControllerPrescaller)"!][!/* Calculate Prescaler value. */!]
                [!VAR "CanControllerTimeQuanta" = "$Prescaler div ($CANClockFrequency)"!]
                [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!]
                    [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                        [!VAR "Prescaler_Alternate" = "num:i(CanControllerPrescaller_Alt)"!][!/* Calculate Prescaler value. */!]
                        [!VAR "CanControllerTimeQuanta_Alternate" = "$Prescaler_Alternate div ($CANClockFrequency_Alternate)"!]
                    [!ENDIF!]
                [!ENDIF!]
                
                [!/* Calculate the Number of Tq/Can bit for the current baud rate and clock selection. */!]
                [!VAR "CANTimeQuanta" = "num:i(round((1 div (num:i(CanControllerBaudRate) * 1000)) div $CanControllerTimeQuanta))"!]
                
                [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                    [!IF "($CANTimeQuanta<8) or ($CANTimeQuanta>129) "!]
                        [!ERROR!]
                           The No of CanTimeQuantas for Can CBT ([!"num:i($CANTimeQuanta)"!]) out of range [8, 129]. Modify the CanControllerPrescaller to obtain a valid CanTimeQuantas
                        [!ENDERROR!]
                    [!ENDIF!]
                [!ELSE!]
                    [!IF "($CANTimeQuanta < 8) or ($CANTimeQuanta > 25)"!]
                        [!ERROR!]
                            For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], the desired CAN bus Nominal Bit Time (NBT) should be an integer number of Time Quanta (CAN system clock periods) from 8 to 25.
                            Current No of CanTimeQuantas = [!"num:i($CANTimeQuanta)"!] --->>> OUT of RANGE [8-25]. Reconfigure the CanControllerBaudrateConfig container to obtain the valid CanTimeQuantas as following equation:
                            No of CanTimeQuantas = (CanClockFrequency / CanControllerBaudRate) / CanControllerPrescaller.
                        [!ENDERROR!]
                    [!ENDIF!]
                [!ENDIF!]
                
                [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!]
                    [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                        [!VAR "CANTimeQuanta_Alternate" = "num:i(round((1 div (num:i(CanControllerBaudRate) * 1000)) div $CanControllerTimeQuanta_Alternate))"!]
                        [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                            [!IF "($CANTimeQuanta_Alternate<8) or ($CANTimeQuanta_Alternate>129) "!]
                                    [!ERROR!]
                                     Current No of CanTimeQuantas for the alternate baudrate = [!"num:i($CANTimeQuanta_Alternate)"!] out of range [8, 129]. Modify the CanControllerPrescaller to obtain a valid CanTimeQuantas
                                    [!ENDERROR!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!IF "($CANTimeQuanta_Alternate < 8) or ($CANTimeQuanta_Alternate > 25)"!]
                                [!ERROR!]
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], the desired CAN bus Nominal Bit Time (NBT) should be an integer number of Time Quanta (CAN system clock periods) from 8 to 25.
                                    Current No of CanTimeQuantas for the alternate baudrate = [!"num:i($CANTimeQuanta_Alternate)"!] --->>> OUT of RANGE [8-25]. Reconfigure the CanControllerBaudrateConfig container to obtain the valid CanTimeQuantas as following equation:
                                    No of CanTimeQuantas = (CanClockFrequency_Alternate / CanControllerBaudRate) / CanControllerPrescaller_Alt.
                                [!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDIF!]
                
                [!IF "CanAdvancedSetting = 'false'"!]
                    [!IF "CanControllerCheckCanStandard"!]
                        [!IF "(node:exists(CanControllerFdBaudrateConfig) = 'true') and ((node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'true')"!] 
                            [!/* Check the CAN FD bit time compliance  - get the values from Tresos interface and check to see that the number of time quantas introduced by user it is correct.*/!]
                            [!/* Formula used fot checking the total number of time quantas is: NoTqFD= fcanclk/((desired_baudrate[Hz])*(FD_prescaller +1 ))*/!]
                            [!IF "(node:exists(CanControllerFdBaudrateConfig)) = 'true'"!] 
                                [!SELECT "node:ref(../../CanCpuClockRef)"!]
                                    [!VAR "OutCanClockFrequencyFromMcuFd" = "McuClockReferencePointFrequency"!]
                                [!ENDSELECT!]
                                [!VAR "CANTimeQuantaFd" = "num:i(round($OutCanClockFrequencyFromMcuFd div(num:i(num:i(CanControllerFdBaudrateConfig/CanControllerFdBaudRate) * (num:i((CanControllerFdBaudrateConfig/CanControllerFDPrescaller)-1) + 1)*1000))))"!]
                                [!VAR "FdTimeSegment1" = "num:i(num:i(CanControllerFdBaudrateConfig/CanControllerPropSeg) + num:i(CanControllerFdBaudrateConfig/CanControllerSeg1))"!]
                                [!VAR "FdTimeSegment2" = "num:i(num:i(CanControllerFdBaudrateConfig/CanControllerSeg2))"!]
                                [!VAR "FdTsyncsegment" = "1"!]
                                [!VAR "CanControllerFDPrescaller1" = "num:i(num:i(CanControllerFdBaudrateConfig/CanControllerFDPrescaller))"!]
                                [!VAR "UserNoTimeQuantasFd"= "num:i($FdTsyncsegment + num:i(CanControllerFdBaudrateConfig/CanControllerPropSeg) + num:i(CanControllerFdBaudrateConfig/CanControllerSeg1) + num:i(CanControllerFdBaudrateConfig/CanControllerSeg2))"!]
                                [!IF "($CANTimeQuantaFd) != ($UserNoTimeQuantasFd)"!]     
                                    [!ERROR!]
                                        The No of CanTimeQuantas for Can FD set by you ([!"$UserNoTimeQuantasFd"!]) is different from the one calculated from clock settings ([!"num:i($CANTimeQuantaFd)"!]).
                                        Reconfigure the parameters in the CanControllerFdBaudrateConfig container and make sure the same in the No of CanTimeQuantas calculated from two following equations.
                                        From user : No of CanTimeQuantas = CanControllerFdSyncSeg + CanControllerPropSeg + CanControllerSeg1 + CanControllerSeg2.
                                        From clock: No of CanTimeQuantas = (CanClockFrequency / CanControllerFdBaudRate) / CanControllerFDPrescaller.
                                    [!ENDERROR!]  
                                [!ENDIF!]
                                [!IF "($CANTimeQuantaFd<5) or ($CANTimeQuantaFd>48) "!]
                                    [!ERROR!]
                                        The No of CanTimeQuantas for Can FD out of range [5, 48]. Modify the CanControllerFDPrescaller to obtain a valid CanTimeQuantas.
                                    [!ENDERROR!]
                                [!ENDIF!]
                                [!IF "($FdTimeSegment1<0) or ($FdTimeSegment1>255) "!]
                                    [!ERROR!]
                                        CanControllerSeg1 in the CanControllerFdBaudrateConfig container should have values between 0 and 255.
                                    [!ENDERROR!]
                                [!ENDIF!]
                                [!IF "($FdTimeSegment2<0) or ($FdTimeSegment2>255) "!]
                                    [!ERROR!]
                                        CanControllerSeg2 in the CanControllerFdBaudrateConfig container should have values between 0 and 255
                                    [!ENDERROR!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* Check the CAN bit time compliance  - get the values from Tresos interface and check.*/!]
                        [!VAR "NoTimeQuantas"= "num:i($Tsyncsegment + num:i(CanControllerPropSeg) + num:i(CanControllerSeg1) + num:i(CanControllerSeg2))"!]
                        [!VAR "TimeSegment1" = "num:i(num:i(CanControllerPropSeg) + num:i(CanControllerSeg1))"!]
                        [!VAR "TimeSegment2" = "num:i(num:i(CanControllerSeg2))"!]
                        [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!] 
                            [!IF "($TimeSegment1<4) or ($TimeSegment1>96) "!]
                                [!ERROR!]
                                   CanControllerCbtSeg1(CanControllerPropSeg + CanControllerSeg1) should have values between 4 and 96.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "($TimeSegment2<2) or ($TimeSegment2>32) "!]
                                [!ERROR!]
                                   CanControllerCbtSeg2(CanControllerSeg2) should have values between 2 and 32.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "($NoTimeQuantas<8) or ($NoTimeQuantas>129) "!]
                                [!ERROR!]
                                   The No of CanTimeQuantas for Can CBT ([!"num:i($CANTimeQuanta)"!]) out of range [8, 129]. Modify the CanControllerPrescaller to obtain a valid CanTimeQuantas
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                                [!IF "(node:exists(CanControllerFdBaudrateConfig) = 'true') and ((node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'true')"!]
                                    [!IF "$Prescaler != $CanControllerFDPrescaller1"!]
                                        [!WARNING!]
                                            The Prescaler for CAN CBT ([!"num:i($Prescaler)"!]) is different from the precaler configurated for CAN FD ([!"num:i($CanControllerFDPrescaller1)"!]) .
                                            To minimize errors when processing FD frames, use the same value for CanControllerFDPrescaller and CanControllerCbtPrescaller.
                                        [!ENDWARNING!]
                                    [!ENDIF!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!IF "($TimeSegment1 < 4) or ($TimeSegment1 > 16)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [4 .. 16], current value is [!"num:i($TimeSegment1)"!][!ENDERROR!]
                            [!ENDIF!]
                            [!IF "($NoTimeQuantas < 8) or ($NoTimeQuantas > 25)"!]
                                [!ERROR!]
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], the desired CAN bus Nominal Bit Time (NBT) should be an integer number of Time Quanta (CAN system clock periods) from 8 to 25.
                                    Current No of CanTimeQuantas = [!"num:i($NoTimeQuantas)"!] --->>> OUT of RANGE [8-25]. Reconfigure the CanControllerBaudrateConfig container to obtain the valid CanTimeQuantas as following equation:
                                    No of CanTimeQuantas = CanControllerSyncSeg + CanControllerPropSeg + CanControllerSeg1 + CanControllerSeg2.
                                [!ENDERROR!]
                            [!ENDIF!]
                            
                            [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                                [!IF "((node:exists(CanControllerFdBaudrateConfig)) = 'true') and ((node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'false')"!]
                                    [!WARNING!]
                                        When the CAN FD feature is enabled, BitRate switch is disabled, always use the CAN CBT register (extended CAN bit timing) for the CAN bit timing to have the same No of time quanta for both control phase and data phase.
                                    [!ENDWARNING!]
                                [!ENDIF!]
                                [!IF "(node:exists(CanControllerFdBaudrateConfig) = 'true') and ((node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'true')"!]
                                    [!WARNING!]
                                        When the CAN FD feature is enabled, BitRate switch is enabled, always use the CAN CBT register (extended CAN bit timing) for .control phase.
                                    [!ENDWARNING!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ELSE!]
                    [!/* Initiates the derivation of the CAN bit timing values from the CanControllerBaudRate parameter. */!]
                    [!VAR "BusPropogationDelay" ="5 div 1000000000"!][!/* Hard coded to 5ns/m. */!]
                    [!VAR "PhysicalDelayOfBus"="CanBusLength * $BusPropogationDelay"!]
                    [!/* Tprop_seg=TpropAB + TpropBA = 2 * (Tbus + Trx + Ttx). Ussually Trx=Ttx. */!]
                    [!VAR "Tpropogationsegment"="2*($PhysicalDelayOfBus + 2 * (CanPropDelayTranceiver div 1000000000))"!]
                    [!VAR "PropogationSegment"="1+round($Tpropogationsegment div $CanControllerTimeQuanta )"!]
                    [!IF "($PropogationSegment >= 1) and ($PropogationSegment <= 8) and (CanControllerCbtEnable = 'false')"!]
                        [!VAR "PhaseSegments" = "($CANTimeQuanta - $PropogationSegment - $Tsyncsegment)"!]
                        [!IF "$PhaseSegments >= 2"!]
                            [!VAR "Modulo" = "$PhaseSegments mod 2"!]
                            [!IF "$Modulo = 0"!]
                                [!VAR "PhaseSegment1" = "num:i($PhaseSegments div 2)"!]
                                [!VAR "PhaseSegment2" = "num:i($PhaseSegment1)"!]
                            [!ELSE!]
                                [!VAR "PhaseSegment1" = "num:i(($PhaseSegments - 1) div 2)"!]
                                [!VAR "PhaseSegment2" = "num:i($PhaseSegment1 + 1)"!]
                            [!ENDIF!]
                            [!IF "($PhaseSegment1 < 1) or ($PhaseSegment1 > 8)"!]
                                [!ERROR!]
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                                    PropSegment1 is out of range [1:8]. Current value is [!"num:i($PhaseSegment1)"!].
                                    The bit length has [!"num:i($CANTimeQuanta)"!] Time Quantas.
                                    Propagation Segment based bus length and tranceiver delay has [!"num:i($PropogationSegment)"!] Time Quantas.
                                    Need to increase PropogationSegment or to decrease the number of Time Quantas per bit.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "($PhaseSegment2 < 2) or ($PhaseSegment2 > 8)"!]
                                [!ERROR!]
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                                    PropSegment2 is out of range [2:8]. Current value is [!"num:i($PhaseSegment2)"!]
                                    The bit length has [!"num:i($CANTimeQuanta)"!] Time Quantas.
                                    Propagation Segment based bus length and tranceiver delay has [!"num:i($PropogationSegment)"!] Time Quantas.
                                    Need to increase PropogationSegment or to decrease the number of Time Quantas per bit.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "$PhaseSegment1 < 5"!]
                                [!VAR "RJW" = "num:i($PhaseSegment1)"!]
                            [!ELSE!]
                                [!VAR "RJW" = "4"!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!ERROR!] For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], (Phase Segment1+Phase Segment2) must be >= 8. Increase no of CANTimeQuanta ([!"num:i($CANTimeQuanta)"!]) per bit or decrease PropSegment ([!"num:i($PropogationSegment)"!])(based CanBusLength and CanPropDelayTranceiver).[!ENDERROR!]
                        [!ENDIF!]
                    [!ELSEIF "($PropogationSegment >= 1) and ($PropogationSegment <= 64) and (CanControllerCbtEnable = 'true')"!]
                        [!VAR "PhaseSegments" = "($CANTimeQuanta - $PropogationSegment - $Tsyncsegment)"!]
                        [!IF "$PhaseSegments >= 2"!]
                            [!VAR "Modulo" = "$PhaseSegments mod 2"!]
                            [!IF "$Modulo = 0"!]
                                [!VAR "PhaseSegment1" = "num:i($PhaseSegments div 2)"!]
                                [!VAR "PhaseSegment2" = "num:i($PhaseSegment1)"!]
                            [!ELSE!]
                                [!VAR "PhaseSegment1" = "num:i(($PhaseSegments - 1) div 2)"!]
                                [!VAR "PhaseSegment2" = "num:i($PhaseSegment1 + 1)"!]
                            [!ENDIF!]
                            [!IF "($PhaseSegment1 < 1) or ($PhaseSegment1 > 32)"!]
                                [!ERROR!]
                                    for disabling Extended CAN bit timing
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                                    PropSegment1 is out of range [1:32]. Current value is [!"num:i($PhaseSegment1)"!].
                                    The bit length has [!"num:i($CANTimeQuanta)"!] Time Quantas.
                                    Propagation Segment based bus length and tranceiver delay has [!"num:i($PropogationSegment)"!] Time Quantas.
                                    Need to increase PropogationSegment or to decrease the number of Time Quantas per bit.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "($PhaseSegment2 < 2) or ($PhaseSegment2 > 32)"!]
                                [!ERROR!]
                                    for enabling Extended CAN bit timing
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                                    PropSegment2 is out of range [2:32]. Current value is [!"num:i($PhaseSegment2)"!]
                                    The bit length has [!"num:i($CANTimeQuanta)"!] Time Quantas.
                                    Propagation Segment based bus length and tranceiver delay has [!"num:i($PropogationSegment)"!] Time Quantas.
                                    Need to increase PropogationSegment or to decrease the number of Time Quantas per bit.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "$PhaseSegment1 < 5"!]
                                [!VAR "RJW" = "num:i($PhaseSegment1)"!]
                            [!ELSE!]
                                [!VAR "RJW" = "4"!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!ERROR!] For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], (Phase Segment1+Phase Segment2) must be >= 8. Increase no of CANTimeQuanta ([!"num:i($CANTimeQuanta)"!]) per bit or decrease PropSegment ([!"num:i($PropogationSegment)"!])(based CanBusLength and CanPropDelayTranceiver).[!ENDERROR!]
                        [!ENDIF!]
                    [!ELSE!]
                        [!ERROR!]
                        For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                        when disable Extended CAN bit timing
                            range of Propagation Segment [1:8]
                        when enable Extended CAN bit timing
                            range of Propagation Segment [1:64]
                            
                        Delay A_to_B >= node output delay(A) + bus line delay(A+B) + node input delay(B)
                        Prop_Seg >= Delay A_to_B + Delay B_to_A
                        Prop_Seg >= 2 * [max(node output delay+ bus line delay + node input delay)]

                        The formulas used:
                        BusPropogationDelay =5 div 1000000000 /* Hard coded to 5ns/m. */
                        PhysicalDelayOfBus = CanBusLength * BusPropogationDelay
                        Tpropogationsegment = 2*(PhysicalDelayOfBus + 2 * (CanPropDelayTranceiver div 1000000000))
                        PropogationSegment = 1+round(Tpropogationsegment div CanControllerTimeQuanta )
                        [!ENDERROR!]
                    [!ENDIF!]
                    [!VAR "NoTimeQuantas"= "num:i($Tsyncsegment + $PropogationSegment + $PhaseSegment1 + $PhaseSegment2)"!]
                [!ENDIF!]
                [!IF "CanControllerCheckCanStandard"!]
                    [!/* Minimum ratio between the peripheral clock frequency and Can Bit rate Check */!]
                    [!VAR "maxmb" = "0"!]
                    [!VAR "x" = "num:i(../../CanControllerId)"!]
                    [!LOOP "../../../../CanHardwareObject/*"!]
                        [!SELECT "node:ref(CanControllerRef)"!]
                            [!IF "num:i(CanControllerId) = num:i($x)"!]
                                [!VAR "maxmb" = "$maxmb+1"!]
                            [!ENDIF!]
                        [!ENDSELECT!]
                    [!ENDLOOP!]
                    [!IF "num:i($maxmb) <= 16"!]
                        [!IF "($NoTimeQuantas * $Prescaler < 8)"!]
                            [!ERROR!]
                            For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                            When CanMessageBufferCount is <=16, Prescaler is [!"num:i($Prescaler)"!], No of CanTimeQuantas is [!"num:i($NoTimeQuantas)"!],
                            Minimum Ratio should be 8, current value is [!"num:i($NoTimeQuantas * $Prescaler)"!].
                            Increase Prescaler or NoTimeQuantas values.[!ENDERROR!]
                        [!ENDIF!]
                    [!ENDIF!]
                    [!IF "(num:i($maxmb) > 16) and (num:i($maxmb) <= 32)"!]
                        [!IF "($NoTimeQuantas * $Prescaler < 8)"!]
                            [!ERROR!]
                            For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                            When CanMessageBufferCount is >16 and <=32, Prescaler is [!"num:i($Prescaler)"!], No of CanTimeQuantas is [!"num:i($NoTimeQuantas)"!],
                            Minimum Ratio should be 8, current value is [!"num:i($NoTimeQuantas * $Prescaler)"!].
                            Increase Prescaler or NoTimeQuantas values.[!ENDERROR!]
                        [!ENDIF!]
                    [!ENDIF!]
                    [!IF "(num:i($maxmb) > 32) and (num:i($maxmb) <= 64)"!]
                        [!IF "($NoTimeQuantas * $Prescaler < 16)"!]
                            [!ERROR!]
                            For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                            When CanMessageBufferCount is >32 and <=64, Prescaler is [!"num:i($Prescaler)"!], No of CanTimeQuantas is [!"num:i($NoTimeQuantas)"!],
                            Minimum Ratio should be 16, current value is [!"num:i($NoTimeQuantas * $Prescaler)"!].
                            Increase Prescaler or NoTimeQuantas values.[!ENDERROR!]
                        [!ENDIF!]
                    [!ENDIF!]
                    [!IF "num:i($CANTimeQuanta) != num:i($NoTimeQuantas)"!]
                        [!WARNING!]
                            For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                            The No of CanTimeQuantas set by you ([!"$NoTimeQuantas"!]) is different from the one calculated from clock settings ([!"num:i($CANTimeQuanta)"!]).
                            Reconfigure the parameters in the CanControllerBaudrateConfig container and make sure the same in the No of CanTimeQuantas calculated from two following equations.
                            From user : No of CanTimeQuantas = CanControllerSyncSeg + CanControllerPropSeg + CanControllerSeg1 + CanControllerSeg2.
                            From clock: No of CanTimeQuantas = (CanClockFrequency / CanControllerBaudRate) / CanControllerPrescaller.
                        [!ENDWARNING!]
                    [!ENDIF!]
                [!ENDIF!]
                [!ENDNOCODE!]
                /*
                =================================================
                Clock Size = [!"$CANClockFrequency"!] Hz [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!] - Clock from MCU. [!ELSE!] - Clock from external OSC.[!ENDIF!][!CR!]
                [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!][!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Clock Size Alternate = [!"$CANClockFrequency_Alternate"!] Hz [!IF "../../CanClockFromBus"!] - Clock from MCU. [!ELSE!] - Clock from external OSC.[!ENDIF!] [!ENDIF!][!ENDIF!][!ENDIF!][!CR!]
                Clock Prescaler = [!"$Prescaler"!][!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](1..256) [!ELSE!] (1..1024) [!ENDIF!][!CR!]
                [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!][!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Clock Prescaler_Alternate = [!"$Prescaler_Alternate"!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](1..256) [!ELSE!] (1..1024) [!ENDIF!][!ENDIF!][!ENDIF!][!ENDIF!][!CR!]
                CanBitRate = [!"CanControllerBaudRate"!] Kbps (1bps..1Mbps)
                Number CANTimeQuantas per bit = [!"$CANTimeQuanta"!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](8..25) [!ELSE!] (8..129) [!ENDIF!][!CR!]
                [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!][!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Number CANTimeQuantas_Alternate per bit = [!"$CANTimeQuanta_Alternate"!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](8..25) [!ELSE!] (8..129) [!ENDIF!][!ENDIF!][!ENDIF!][!ENDIF!][!CR!]
               
                [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!]CTRL Register Fields:[!ELSE!] CBT Register Fields: [!ENDIF!] [!CR!]
                PSEG1 = [!IF "CanAdvancedSetting"!][!"num:i(num:i($PhaseSegment1)-1)"!][!ELSE!][!"num:i(num:i(CanControllerSeg1)-1)"!][!ENDIF!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](0..7) [!ELSE!] (0..31) [!ENDIF!] [!CR!]
                PSEG2 = [!IF "CanAdvancedSetting"!][!"num:i(num:i($PhaseSegment2)-1)"!][!ELSE!][!"num:i(num:i(CanControllerSeg2)-1)"!][!ENDIF!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](0..7) [!ELSE!] (0..31) [!ENDIF!] [!CR!]
                PROPSEG = [!IF "CanAdvancedSetting"!][!"num:i(num:i($PropogationSegment)-1)"!][!ELSE!][!"num:i(num:i(CanControllerPropSeg)-1)"!][!ENDIF!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](0..7) [!ELSE!] (0..63) [!ENDIF!] [!CR!]
                RJW = [!IF "CanAdvancedSetting"!][!"num:i(num:i($RJW)-1)"!][!ELSE!][!"num:i(num:i(CanControllerSyncJumpWidth)-1)"!][!ENDIF!] [!IF "(node:value(CanControllerCbtEnable)) = 'false'"!](0..3) [!ELSE!] (0..31) [!ENDIF!] [!CR!]
                =================================================[!CR!]
                */
                [!IF "../../CanControllerActivation = 'true'"!]
                    /* Configuration for CanController ID[!"../../CanControllerId"!] == [!"../../CanHwChannel"!] */
                    {
                        [!INDENT "8"!]
                        [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                            /* ===== Control Register - CBT ===== */
                        [!ELSE!]
                            /* ===== Control Register - CTRL ===== */
                        [!ENDIF!]
                        (uint32)(
                                    [!INDENT "20"!]
                                    [!IF "CanAdvancedSetting = 'false'"!]
                                        [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                            ((uint32)[!"num:i(num:i($Prescaler) - 1)"!] << FLEXCAN_FD_PRESDIV_CBT_OFFSET_U8) |    /* CBT[PRESDIV] - Clock Prescaler */
                                            ((uint32)[!"num:i(num:i(CanControllerSyncJumpWidth)-1)"!] << FLEXCAN_CBT_SJW_OFFSET_U8) |     /* CBT[RJW] - Resynchronization Jump Width */
                                            ((uint32)[!"num:i(num:i(CanControllerSeg1)-1)"!] << FLEXCAN_CBT_PSEG1_OFFSET_U8) |      /* CBT[PSEG1] - Segment 1 */
                                            ((uint32)[!"num:i(num:i(CanControllerSeg2)-1)"!] << FLEXCAN_CBT_PSEG2_OFFSET_U8) |    /* CBT[PSEG2] - Segment 2 */
                                            ((uint32)[!"num:i(num:i(CanControllerPropSeg)-1)"!]U << FLEXCAN_CBT_PROPSEG_OFFSET_U8)   /* CBT[PROPSEG] - Propagation segment */
                                        [!ELSE!]
                                            ((uint32)[!"num:i(num:i($Prescaler) - 1)"!] << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |    /* CTRL[PRESDIV] - Clock Prescaler */
                                            ((uint32)[!"num:i(num:i(CanControllerSyncJumpWidth)-1)"!] << FLEXCAN_CTRL_RJW_SHIFT_U8) |     /* CTRL[RJW] - Resynchronization Jump Width */
                                            ((uint32)[!"num:i(num:i(CanControllerSeg1)-1)"!] << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |      /* CTRL[PSEG1] - Segment 1 */
                                            ((uint32)[!"num:i(num:i(CanControllerSeg2)-1)"!] << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |    /* CTRL[PSEG2] - Segment 2 */
                                            ((uint32)[!"num:i(num:i(CanControllerPropSeg)-1)"!]U)   /* CTRL[PROPSEG] - Propagation segment */
                                        [!ENDIF!]
                                    [!ELSE!]
                                         [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                            ((uint32)[!"num:i(num:i($Prescaler) - 1)"!] << FLEXCAN_FD_PRESDIV_CBT_OFFSET_U8) |    /* CBT[PRESDIV] - Clock Prescaler */
                                            ((uint32)[!"num:i(num:i($RJW)-1)"!] << FLEXCAN_CBT_SJW_OFFSET_U8) |      /* CBT[RJW] - Resynchronization Jump Width */
                                            ((uint32)[!"num:i(num:i($PhaseSegment1)-1)"!] << FLEXCAN_CBT_PSEG1_OFFSET_U8) |     /* CBT[PSEG1] - Segment 1 */
                                            ((uint32)[!"num:i(num:i($PhaseSegment2)-1)"!] << FLEXCAN_CBT_PSEG2_OFFSET_U8) |   /* CBT[PSEG2] - Segment 2 */
                                            ((uint32)[!"num:i(num:i($PropogationSegment)-1)"!]U << FLEXCAN_CBT_PROPSEG_OFFSET_U8)   /* CBT[PROPSEG] - Propagation segment */
                                        [!ELSE!]
                                            ((uint32)[!"num:i(num:i($Prescaler) - 1)"!] << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |    /* CTRL[PRESDIV] - Clock Prescaler */
                                            ((uint32)[!"num:i(num:i($RJW)-1)"!] << FLEXCAN_CTRL_RJW_SHIFT_U8) |      /* CTRL[RJW] - Resynchronization Jump Width */
                                            ((uint32)[!"num:i(num:i($PhaseSegment1)-1)"!] << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |     /* CTRL[PSEG1] - Segment 1 */
                                            ((uint32)[!"num:i(num:i($PhaseSegment2)-1)"!] << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |   /* CTRL[PSEG2] - Segment 2 */
                                            ((uint32)[!"num:i(num:i($PropogationSegment)-1)"!]U)    /* CTRL[PROPSEG] - Propagation segment */
                                        [!ENDIF!]
                                    [!ENDIF!]
                                    [!ENDINDENT!]
                        [!WS "8"!]),
                        (uint8)[!"num:i(CanTxArbitrationStartDelay)"!]U /* CTRL2[TASD] Tx Arbitration Start Delay */

                        #if (CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON)
                        [!IF "((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'true'))"!]
                            [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                                [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                    /* ===== Control Register Alternate - CBT ===== */
                                [!ELSE!]
                                    /* ===== Control Register Alternate - CTRL ===== */
                                [!ENDIF!]
                                ,(uint32)(
                                            [!INDENT "20"!]
                                            [!IF "CanAdvancedSetting = 'false'"!]
                                                [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                                    ((uint32)[!"num:i(num:i($Prescaler_Alternate) - 1)"!] << FLEXCAN_FD_PRESDIV_CBT_OFFSET_U8) |    /* CBT[PRESDIV] - Clock Prescaler */
                                                    ((uint32)[!"num:i(num:i(CanControllerSyncJumpWidth)-1)"!] << FLEXCAN_CBT_SJW_OFFSET_U8) |     /* CBT[RJW] - Resynchronization Jump Width */
                                                    ((uint32)[!"num:i(num:i(CanControllerSeg1)-1)"!] << FLEXCAN_CBT_PSEG1_OFFSET_U8) |      /* CBT[PSEG1] - Segment 1 */
                                                    ((uint32)[!"num:i(num:i(CanControllerSeg2)-1)"!] << FLEXCAN_CBT_PSEG2_OFFSET_U8) |    /* CBT[PSEG2] - Segment 2 */
                                                    ((uint32)[!"num:i(num:i(CanControllerPropSeg)-1)"!]U << FLEXCAN_CBT_PROPSEG_OFFSET_U8)   /* CBT[PROPSEG] - Propagation segment */
                                                [!ELSE!]
                                                    ((uint32)[!"num:i(num:i($Prescaler_Alternate) - 1)"!] << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |    /* CTRL[PRESDIV] - Clock Prescaler */
                                                    ((uint32)[!"num:i(num:i(CanControllerSyncJumpWidth)-1)"!] << FLEXCAN_CTRL_RJW_SHIFT_U8) |     /* CTRL[RJW] - Resynchronization Jump Width */
                                                    ((uint32)[!"num:i(num:i(CanControllerSeg1)-1)"!] << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |      /* CTRL[PSEG1] - Segment 1 */
                                                    ((uint32)[!"num:i(num:i(CanControllerSeg2)-1)"!] << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |    /* CTRL[PSEG2] - Segment 2 */
                                                    ((uint32)[!"num:i(num:i(CanControllerPropSeg)-1)"!]U)   /* CTRL[PROPSEG] - Propagation segment */
                                                [!ENDIF!]
                                            [!ELSE!]
                                                 [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                                    ((uint32)[!"num:i(num:i($Prescaler_Alternate) - 1)"!] << FLEXCAN_FD_PRESDIV_CBT_OFFSET_U8) |    /* CBT[PRESDIV] - Clock Prescaler */
                                                    ((uint32)[!"num:i(num:i($RJW)-1)"!] << FLEXCAN_CBT_SJW_OFFSET_U8) |      /* CBT[RJW] - Resynchronization Jump Width */
                                                    ((uint32)[!"num:i(num:i($PhaseSegment1)-1)"!] << FLEXCAN_CBT_PSEG1_OFFSET_U8) |     /* CBT[PSEG1] - Segment 1 */
                                                    ((uint32)[!"num:i(num:i($PhaseSegment2)-1)"!] << FLEXCAN_CBT_PSEG2_OFFSET_U8) |   /* CBT[PSEG2] - Segment 2 */
                                                    ((uint32)[!"num:i(num:i($PropogationSegment)-1)"!]U << FLEXCAN_CBT_PROPSEG_OFFSET_U8)   /* CBT[PROPSEG] - Propagation segment */
                                                [!ELSE!]
                                                    ((uint32)[!"num:i(num:i($Prescaler_Alternate) - 1)"!] << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |    /* CTRL[PRESDIV] - Clock Prescaler */
                                                    ((uint32)[!"num:i(num:i($RJW)-1)"!] << FLEXCAN_CTRL_RJW_SHIFT_U8) |      /* CTRL[RJW] - Resynchronization Jump Width */
                                                    ((uint32)[!"num:i(num:i($PhaseSegment1)-1)"!] << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |     /* CTRL[PSEG1] - Segment 1 */
                                                    ((uint32)[!"num:i(num:i($PhaseSegment2)-1)"!] << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |   /* CTRL[PSEG2] - Segment 2 */
                                                    ((uint32)[!"num:i(num:i($PropogationSegment)-1)"!]U)    /* CTRL[PROPSEG] - Propagation segment */
                                                [!ENDIF!]
                                            [!ENDIF!]
                                            [!ENDINDENT!]
                                [!WS "8"!])
                            [!ELSE!]
                                ,0U
                            [!ENDIF!]
                        [!ELSE!]
                            ,0U
                        [!ENDIF!]
                        [!IF "(./../../../../../CanGeneral/CanEnableDualClockMode = 'true') and ((ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON') and (../../CanClockFromBus = 'false'))"!]
                            [!WARNING!]When dual clock feature (CanEnableDualClockMode) is enabled , the clock from MCU should be selected (CanClockFromBus is ticked).[!ENDWARNING!]
                        [!ENDIF!]
                        #endif /* CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON */
                        
                        [!IF "ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON'"!]
                            #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                            ,{
                                [!INDENT "12"!]
                                [!IF "(node:exists(CanControllerFdBaudrateConfig)) = 'true'"!]
                                    (uint32)((uint32)1U << FLEXCAN_FD_OFFSET_U8), /*CAN FD Activated*/
                                    [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'true'"!]
                                        (uint32)[!"CanControllerFdBaudrateConfig/CanControllerFdBaudRate"!]U,   /* [!"CanControllerBaudRate"!]kbps baud rate */
                                        (uint32)(
                                                    [!INDENT "24"!]
                                                    (uint32)((uint32)[!"num:i((CanControllerFdBaudrateConfig/CanControllerFDPrescaller)-1)"!]U << FLEXCAN_FD_PRESDIV_OFFSET_U8) |   /* CAN FD propagation segment */
                                                    (uint32)((uint32)[!"CanControllerFdBaudrateConfig/CanControllerPropSeg"!]U << FLEXCAN_FD_PROPSEG_OFFSET_U8) |   /* CAN FD propagation segment */
                                                    (uint32)((uint32)[!"num:i((CanControllerFdBaudrateConfig/CanControllerSeg1)-1)"!]U << FLEXCAN_FD_PSEG1_OFFSET_U8) |   /* time segment 1 */
                                                    (uint32)((uint32)[!"num:i((CanControllerFdBaudrateConfig/CanControllerSeg2)-1)"!]U<<FLEXCAN_FD_PSEG2_OFFSET_U8) |   /*Time segment 2  */
                                                    (uint32)((uint32)[!"num:i((CanControllerFdBaudrateConfig/CanControllerSyncJumpWidth - 1))"!]U<<FLEXCAN_FD_SJW_OFFSET_U8)  /*Sync jump width*/
                                                    [!ENDINDENT!]
                                        [!WS "8"!]),
                                        [!IF "((node:exists(CanControllerFdBaudrateConfig/CanControllerTrcvDelayCompensationOffset)) = 'true')"!]
                                            (uint32)[!"CanControllerFdBaudrateConfig/CanControllerTrcvDelayCompensationOffset"!]U, /*TRCV DELAY*/
                                        [!ELSE!]
                                            (uint32)0U, /*TRCV DELAY*/
                                        [!ENDIF!]
                                        [!IF "((node:value(CanControllerFdBaudrateConfig/CanControllerTxBitRateSwitch)) = 'true')"!]
                                            (uint32)((uint32)1U<<FLEXCAN_FD_BRS_OFFSET_U8) /*true -> the node exists, BRS activated*/
                                        [!ELSE!]
                                            (uint32)((uint32)0U<<FLEXCAN_FD_BRS_OFFSET_U8) /*false -> the node dos not exist, BRS deactivated*/
                                        [!ENDIF!]
                                        #if ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON) )
                                        ,(uint32)(
                                                    [!INDENT "24"!]
                                                        (uint32)0U
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdIsoCANFD) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_STFCNTEN_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) */
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdPrExcEn) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_PREXCEN_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) */
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdEdgeFilterDis) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_EDFLTDIS_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON) */
                                                    [!ENDINDENT!]
                                        [!WS "8"!])
                                        #endif /* ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON)) */
                                    [!ELSE!]
                                        (uint32)0U,
                                        (uint32)0U, /* CANFDCBT */
                                        (uint32)0U, /*TRCV DELAY*/
                                        (uint32)0U /*false -> the node dos not exist, BRS deactivated*/
                                        #if ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON) )
                                        ,(uint32)(
                                                    [!INDENT "24"!]
                                                        (uint32)0U
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdIsoCANFD) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_STFCNTEN_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) */
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdPrExcEn) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_PREXCEN_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) */
                                                        #if (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON)
                                                        [!IF "(node:value(CanControllerFdBaudrateConfig/CanControllerFdEdgeFilterDis) = 'true')"!]
                                                            | (uint32)((uint32)1U<<FLEXCAN_FD_CTRL2_EDFLTDIS_SHIFT_U32)
                                                        [!ENDIF!]
                                                        #endif /* (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON) */
                                                    [!ENDINDENT!]
                                        [!WS "8"!])
                                        #endif /* ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON)) */
                                    [!ENDIF!]
                                [!ELSE!]
                                    (uint32)((uint32)0U << FLEXCAN_FD_OFFSET_U8), /*CAN FD Deactivated*/
                                    (uint32)0U,
                                    (uint32)0U, /* CANFDCBT */
                                    (uint32)0U, /*TRCV DELAY*/
                                    (uint32)0U /*false -> the node dos not exist, BRS deactivated*/
                                    #if ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON) )
                                        ,(uint32)(0U)
                                    #endif /* ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON)) */
                                [!ENDIF!]
                                [!ENDINDENT!]
                            }
                            #endif /* (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON) */
                        [!ENDIF!]
                        
                        #if (CAN_43_FLEXCAN_CBT_ENABLE == STD_ON)
                            [!INDENT "12"!]
                            [!IF "(node:value(CanControllerCbtEnable)) = 'true'"!]
                                ,(boolean)TRUE
                            [!ELSE!]
                                ,(boolean)FALSE
                            [!ENDIF!]
                            [!ENDINDENT!]
                        #endif /* (CAN_43_FLEXCAN_CBT_ENABLE == STD_ON) */
                        
                        #if (CAN_43_FLEXCAN_SET_BAUDRATE_API == STD_ON)
                            ,(uint16)[!"CanControllerBaudRateConfigID"!]
                        #endif
                        [!ENDINDENT!]
                    }[!IF "$END_COMMA2 < $MASK_COUNT2"!],[!ENDIF!][!CR!]
                [!ELSE!]
                    {
                        [!INDENT "8"!]
                        /* [!"../../CanHwChannel"!] ControlRegister Default Configuration: 125 Kbps BaudRate with Oscillator clock 8MHz as Clock source and TimeQuantum of 1000ns. */
                        /* ===== Control Register - CTRL ===== */
                        (uint32)( 
                                    [!INDENT "24"!]
                                    ((uint32)7 << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |     /* CTRL[PRESDIV] - Clock Prescaler */
                                    ((uint32)2 << FLEXCAN_CTRL_RJW_SHIFT_U8) |         /* CTRL[RJW] - Resynchronization Jump Width */
                                    ((uint32)2 << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |       /* CTRL[PSEG1] - Segment 1 */
                                    ((uint32)2 << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |       /* CTRL[PSEG2] - Segment 2 */
                                    ((uint32)0 << FLEXCAN_CTRL_CLKSRC_SHIFT_U8) |      /* CTRL[CLK_SRC] - Clock source */
                                    (uint32)0                                          /* CTRL[PROPSEG] - Propagation segment */
                                    [!ENDINDENT!]
                         [!WS "8"!]) ,
                        (uint8)12U /* CTRL2[TASD] Tx Arbitration Start Delay */
                        #if (CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON)
                        /* ===== Control Register Alternate - CTRL ===== */
                        ,(uint32)( 
                                    [!INDENT "24"!]
                                    ((uint32)7 << FLEXCAN_CTRL_PRESDIV_SHIFT_U8) |    /* CTRL[PRESDIV] - Clock Prescaler */
                                    ((uint32)2 << FLEXCAN_CTRL_RJW_SHIFT_U8 ) |       /* CTRL[RJW] - Resynchronization Jump Width */
                                    ((uint32)2 << FLEXCAN_CTRL_PSEG1_SHIFT_U8) |      /* CTRL[PSEG1] - Segment 1 */
                                    ((uint32)2 << FLEXCAN_CTRL_PSEG2_SHIFT_U8) |      /* CTRL[PSEG2] - Segment 2 */
                                    ((uint32)0 << FLEXCAN_CTRL_CLKSRC_SHIFT_U8) |     /* CTRL[CLK_SRC] - Clock source */
                                    (uint32)0                                         /* CTRL[PROPSEG] - Propagation segment */
                                    [!ENDINDENT!]
                        [!WS "8"!])
                        #endif /* CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON */
                        
                        #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                        ,{
                            0U, 0U, 0U, 0U, 0U
                            #if ( (CAN_43_FLEXCAN_CONTROLLER_FD_ISO_CANFD == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_PREXCEN == STD_ON) || (CAN_43_FLEXCAN_CONTROLLER_FD_EDFLTDIS == STD_ON))
                                ,0U
                            #endif
                        }
                        #endif
                        
                        #if (CAN_43_FLEXCAN_CBT_ENABLE == STD_ON)
                        ,{0U, 0U, 0U}
                        #endif
                        
                        #if (CAN_43_FLEXCAN_SET_BAUDRATE_API == STD_ON)
                        ,(uint16)0U    /*Can Controller BaudRate ConfigID */
                        #endif
                        [!ENDINDENT!]
                    }
                    [!IF "$END_COMMA2 < $MASK_COUNT2"!]
                        ,
                    [!ENDIF!]
                    [!CR!]
                [!ENDIF!]
            [!ENDLOOP!]
            [!ENDINDENT!]
        };
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDINDENT!]
/*==================================================================================================*/
/**
* @brief          Description of individual FlexCan controllers on chip
* @details        Description of individual FlexCan controllers on chip
*
*/

[!VAR "LoopVar"="0"!]
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    static CONST(Can_43_FLEXCAN_ControlerDescriptorType, CAN_CONST) Can_43_FLEXCAN_ControlerDescriptors[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][[!"num:i(count(CanController/*))"!]U] =
    {
        [!INDENT "4"!]
        [!VAR "MASK_COUNT4"="num:i(count(CanController/*))"!]
        [!VAR "END_COMMA4"="0"!]
        [!VAR "tableidcount" = "0"!]
        [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
            /* ControlerDescriptor of CanController_[!"node:value(CanControllerId)"!]*/
            {
                [!INDENT "8"!]
                [!IF "CanControllerActivation = 'true'"!]
                    /* No. of Message Buffers for current controller - u8MaxMBCount */
                    [!VAR "CtrlID" = "CanControllerId"!]
                    [!VAR "maxmbcount" = "text:split($Can_MaxMBCountTable, ' ')[position() - 1 = $CtrlID]"!]
                    [!VAR "maxmbcount" = "num:hextoint($maxmbcount)"!]
                    [!IF "$maxmbcount = '0' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                        [!VAR "maxmbcount" = "num:i(1)"!]
                    [!ENDIF!]
                    (uint8)[!"$maxmbcount"!]U, /* No. of Message Buffers for current controller - u8MaxMBCount */
                    [!IF "$maxmbcount>ecu:get('Can.CanConfigSet.CanMB')"!]
                        [!ERROR!]Maximum MBs + RxFifo (if enabled) exceed [!"ecu:get('Can.CanConfigSet.CanMB')"!] space.[!ENDERROR!]
                    [!ENDIF!]
                    /* No. of BaudRate configured for current controller - u8MaxBaudRateCount */
                    (uint16)[!"num:i(count(CanControllerBaudrateConfig/*))"!]U,
                    /* Default BaudRate configured for current controller - u8DefaultBaudRateIndex */
                    (uint16)[!"node:ref(CanControllerDefaultBaudrate)/CanControllerBaudRateConfigID"!]U,
                    /* pControllerBaudrateConfigsPtr - pControllerBaudrateConfigsPtr*/
                    Can_43_FLEXCAN_ControllerBaudrateCfgSet_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
                     
                #if (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON)
                    #if (CAN_43_FLEXCAN_LEGACY_RXFIFO_ENABLE == STD_ON)
                        /* Rx Fifo Global mask value - u32RxFifoGlobalMask */
                        (uint32)[!IF "CanRxFifo/CanControllerRxFifoEnable = 'true'"!][!"num:inttohex(num:i(./CanRxFifo/CanRxFifoGlobalMaskValue))"!]U,[!ELSE!]0U,[!ENDIF!][!CR!]
                        /* Number of MBs used by Rx Fifo - u8RxFiFoUsedMb */
                        (uint8)[!IF "CanRxFifo/CanControllerRxFifoEnable = 'true'"!][!"num:i((num:i(substring-after(./CanRxFifo/CanRxFifoFiltersNumber,'FILTERS_NUMBER_')) div 4) + 6)"!]U,[!ELSE!]0U,[!ENDIF!][!CR!]
                        /* Pointer to RxFifo Warning notification function. - Can_RxFifoWarningNotification */
                        [!IF "(CanRxFifo/CanControllerRxFifoEnable = 'true') and (normalize-space(CanRxFifo/CanRxFifoWarningNotification) != 'NULL_PTR')"!]&[!"normalize-space(CanRxFifo/CanRxFifoWarningNotification)"!],[!ELSE!]NULL_PTR,[!ENDIF!][!CR!]
                    #endif
                    #if (CAN_43_FLEXCAN_ENHANCED_RXFIFO_ENABLE == STD_ON)
                        /* @brief Number of Filter Elements */
                        (uint16)[!IF "CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!][!"num:i((count(CanRxFifo/CanRxFifoTable/*[CanRxFifoEnhancedTable/CanTableEnhancedIDType = 'STANDARD']) div 2) + count(CanRxFifo/CanRxFifoTable/*[CanRxFifoEnhancedTable/CanTableEnhancedIDType = 'EXTENDED']))"!]U,[!ELSE!]0U,[!ENDIF!][!CR!]
                        /* @brief Number of Extended Filter Elements */
                        (uint16)[!IF "CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!][!"num:i(count(CanRxFifo/CanRxFifoTable/*[CanRxFifoEnhancedTable/CanTableEnhancedIDType = 'EXTENDED']))"!]U,[!ELSE!]0U,[!ENDIF!][!CR!]
                        #ifdef CAN_43_FLEXCAN_DMA_USED
                            [!VAR "DmaChannelId"="255"!]
                            [!IF "CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                                [!VAR "DmaChannelId"="node:ref(CanRxFifo/CanDmaRef)/MclDMAChannelId"!]
                            [!ENDIF!]
                            (uint8)[!"num:i($DmaChannelId)"!]U, /**< @brief DMA channel */
                            (uint8)[!IF "CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!][!"CanRxFifo/NumberMBTransferDMA"!]U,[!ELSE!]0U,[!ENDIF!] /**< @brief Number of water mask */
                            [!IF "CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                                aCanDmaDestBuffer_[!"CanControllerId"!], /* Pointer to destination Buffer DMA */
                            [!ELSE!]
                                NULL_PTR,
                            [!ENDIF!]
                        #endif
                    #endif
                        /* Pointer to RxFifo Overflow notification function. - Can_RxFifoOverflowNotification */
                        [!IF "(CanRxFifo/CanControllerRxFifoEnable = 'true' or (CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'false')) and (normalize-space(CanRxFifo/CanRxFifoOverflowNotification) != 'NULL_PTR')"!]&[!"normalize-space(CanRxFifo/CanRxFifoOverflowNotification)"!],[!ELSE!]NULL_PTR,[!ENDIF!][!CR!]
                #endif /* (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON) */
                    
                    #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                        [!VAR "numOfRamBlock" = "num:i((ecu:get(concat('Can.CanConfigSet.', string(node:current()/CanHwChannel))) div 32))"!]
                        /* Message Buffer Data Size for [!"$numOfRamBlock"!] RAM regions */
                        (uint32)(
                                    [!INDENT "18"!]
                                    [!IF "(ecu:get('Can.CanConfigSet.CanFdEnable')='STD_ON') and (node:exists(CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig))"!]
                                        /* Exist FD */
                                        [!IF "../../../CanGeneral/CanSpecifiedRAMBlockSize"!]
                                            /* CanSpecifiedRAMBlockSize */
                                            [!VAR "MASK_COUNT5" = "num:i(count(CanRAMBlock/*[text:split(CanRAMBlockName, '_')[4] < $normalRamBlockNumber]))"!]
                                            [!VAR "END_COMMA5"="0"!]
                                            [!LOOP "CanRAMBlock/*[text:split(CanRAMBlockName, '_')[4] < $normalRamBlockNumber]"!]
                                                [!VAR "MBDSRx_OFFSET_U8" = "concat('FLEXCAN_MBDSR', substring-after(CanRAMBlockName, 'CAN_RAM_BLOCK_'), '_OFFSET_U8')"!]
                                                [!VAR "payload" = "CanRAMBlockSizeValue"!]
                                                ((uint32)[!"$payload"!]_U32 << (uint32)[!"$MBDSRx_OFFSET_U8"!])[!//
                                                    [!VAR "END_COMMA5"="$END_COMMA5 + 1"!][!//
                                                    [!IF "$END_COMMA5 < $MASK_COUNT5"!] | [!ENDIF!][!CR!]
                                            [!ENDLOOP!]
                                        [!ELSE!]
                                             /* Don't CanSpecifiedRAMBlockSize */
                                            [!FOR "i" = "0" TO "$numOfRamBlock - 1"!]
                                                [!VAR "FLEXCAN_MBDSRx_OFFSET_U8" = "concat('FLEXCAN_MBDSR', string($i), '_OFFSET_U8')"!]
                                                ((uint32)[!"string(../../../CanGeneral/MBDSR)"!]_U32 << (uint32)[!"$FLEXCAN_MBDSRx_OFFSET_U8"!])[!//
                                                [!IF "$i < $numOfRamBlock - 1"!] | [!ENDIF!][!CR!]
                                            [!ENDFOR!]
                                        [!ENDIF!]
                                    [!ELSE!]
                                        0U
                                    [!ENDIF!]
                                    [!ENDINDENT!]
                       [!WS "8"!]),
                    #endif
                    /* ===== Controller Options ===== -  u32Options*/
                    (uint32)(
                                [!INDENT "20"!]
                                [!IF "CanSoftwareBusOffRecovery = 'true' "!]
                                    CAN_CONTROLLERCONFIG_BUSOFFSWREC_U32 |/* Software BusOff Recovery */
                                [!ENDIF!]
                                [!IF "CanLocalPriorityEn = 'true' "!]
                                    CAN_CONTROLLERCONFIG_LPRIO_EN_U32 |  /* Local Priority Feature */
                                [!ENDIF!]
                                [!IF "(CanErrorControllerNotifEn = 'true') and (normalize-space(CanErrorControllerNotification) != 'NULL_PTR')"!]
                                    CAN_CONTROLLERCONFIG_ERR_EN_U32 | /* Error Notification enabled */
                                [!ELSE!]
                                    /* Error Notification disable */ 
                                [!ENDIF!]
                                [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true' or CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                                    [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true' "!]
                                        CAN_CONTROLLERCONFIG_RXFIFO_U32 | /* RxFifo Legacy Enabled */
                                        [!IF "(normalize-space(CanRxFifo/CanRxFifoWarningNotification) != 'NULL_PTR')"!]
                                            CAN_CONTROLLERCONFIG_WARN_EN_U32 | /* RxFifo Warning handling enabled */
                                        [!ELSE!]
                                            /* RxFifo Warning handling disabled */ 
                                        [!ENDIF!]
                                        [!IF "CanRxFifo/CanControllerIDAcceptanceMode = 'A'"!]
                                            CAN_CONTROLLERCONFIG_IDAM_A_U32 | /* ID Acceptance Mode A */
                                        [!ELSEIF "CanRxFifo/CanControllerIDAcceptanceMode = 'B'"!]
                                            CAN_CONTROLLERCONFIG_IDAM_B_U32 | /* ID Acceptance Mode B */
                                        [!ELSEIF "CanRxFifo/CanControllerIDAcceptanceMode = 'C'"!]
                                            CAN_CONTROLLERCONFIG_IDAM_C_U32 | /* ID Acceptance Mode C */
                                        [!ELSEIF "CanRxFifo/CanControllerIDAcceptanceMode = 'D'"!]
                                            CAN_CONTROLLERCONFIG_IDAM_D_U32 | /* ID Acceptance Mode D: All frames rejected */
                                        [!ENDIF!]
                                    [!ELSE!]
                                        /* RxFifo Legacy Disabled */
                                    [!ENDIF!]
                                    [!IF "CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                                        CAN_CONTROLLERCONFIG_RXFIFO_ENHANCED_U32 | /* Enhanced RxFifo Enabled */
                                        [!IF "(bit:and($EnhancedFifoInterruptEnable, (bit:shl(1, $CtrlID)))) != '0'"!]
                                            [!IF "CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'true'"!]
                                                CAN_CONTROLLERCONFIG_RXFIFO_ENHANCED_DMA_EN_U32 | /* Enhanced RxFifo DMA enabled */
                                            [!ELSE!]
                                                CAN_CONTROLLERCONFIG_RXFIFO_ENHANCED_IE_U32 | /* DMA is disabled so The controller uses default Enhanced RxFiFo interrupt */
                                            [!ENDIF!]
                                        [!ENDIF!]
                                    [!ELSE!]
                                        /* Enhanced RxFifo Disabled */
                                    [!ENDIF!]
                                    [!IF "((CanRxFifo/CanControllerRxFifoEnable = 'true') or (CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true' and CanRxFifo/CanControllerEnhancedRxFifoDMAEnable = 'false')) and (normalize-space(CanRxFifo/CanRxFifoOverflowNotification) != 'NULL_PTR')"!]
                                        CAN_CONTROLLERCONFIG_OVER_EN_U32 | /* RxFifo Overflow handling enabled */
                                    [!ELSE!]
                                        /* RxFifo Overflow handling disabled */
                                    [!ENDIF!]
                                [!ELSE!]
                                    /* RxFifo disabled */
                                [!ENDIF!]
                                [!IF "CanBccSupport = 'true'"!]
                                    #if (CAN_43_FLEXCAN_BCC_SUPPORT_ENABLE == STD_ON)
                                        CAN_CONTROLLERCONFIG_BCC_EN_U32 |
                                    #endif /* (CAN_43_FLEXCAN_BCC_SUPPORT_ENABLE == STD_ON) */
                                [!ENDIF!]
                                0U
                                [!ENDINDENT!]
                    [!WS "8"!])
                [!ELSE!]
                    /* No. of Message Buffers for current controller - u8MaxMBCount */
                    (uint8)0U,
                    /* No. of BaudRate configured for current controller - u8MaxBaudRateCount */
                    (uint8)0U,
                    /* Default BaudRate configured for current controller */
                    (uint8)0U,
                    /* pControllerBaudrateConfigsPtr */
                    Can_43_FLEXCAN_ControllerBaudrateCfgSet_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]

                    #if (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON)
                        #if (CAN_43_FLEXCAN_LEGACY_RXFIFO_ENABLE == STD_ON)
                            /* Rx Fifo Global mask value */
                            ,(uint32)0U
                            /* Number of MBs used by Rx Fifo */
                            ,(uint8)0U
                            /* Pointer to RxFifo Warning notification function. */
                            ,NULL_PTR
                        #endif
                        #if (CAN_43_FLEXCAN_ENHANCED_RXFIFO_ENABLE == STD_ON)
                            /* Number of Filter Elements */
                            ,(uint16)0U
                            /* Number of Extended Filter Elements */
                            ,(uint16)0U
                            #ifdef CAN_43_FLEXCAN_DMA_USED
                            ,(uint8)255U /**< @brief DMA channel */
                            ,(uint8)0U /**< @brief Number of water mask */
                            ,NULL_PTR /* Pointer to destination Buffer DMA */
                            #endif
                        #endif
                        /* Pointer to RxFifo Overflow notification function. */
                        ,NULL_PTR
                    #endif /* (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON) */
                    #if (CAN_43_FLEXCAN_FD_MODE_ENABLE == STD_ON)
                        /* Message Buffer Data Size for three RAM regions */
                        ,(uint32)0U
                    #endif
                    /* ===== Controller Options ===== */
                    ,(uint32)(0U)
                [!ENDIF!]
               [!ENDINDENT!]
            }[!//
            [!VAR "END_COMMA4"="$END_COMMA4 + 1"!][!//
            [!IF "$END_COMMA4 < $MASK_COUNT4"!][!//
                , /* ControlerDescriptors CanController_[!"node:value(CanControllerId)"!] end */
            [!ENDIF!]
            [!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
[!ENDSELECT!]
[!ENDINDENT!]

/*==================================================================================================*/
/**
* @brief          Top level structure containing all Can driver configurations
* @details        Top level structure containing all Can driver configurations
*/
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_3 MISRA 2012 Advisory Rule 8.7 */
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_4 MISRA 2012 Required Rule 8.4 */
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_5 MISRA 2012 Advisory Rule 8.9 */
[!VAR "LoopVar"="0"!] 
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    [!IF "((../IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (../IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!]
        CONST(Can_43_FLEXCAN_ConfigType, CAN_CONST) Can_43_FLEXCAN_[!"as:name(.)"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
    [!ELSE!]
        CONST(Can_43_FLEXCAN_ConfigType, CAN_CONST) Can_43_FLEXCAN_PBCfgVariantPredefined =
    [!ENDIF!]
    {
        [!INDENT "4"!]
        Can_FilterMasks[!"$CSET_NR"!]_PB, /*  - pFilterMasks */
        /* MessageBufferConfigContainer - MBConfigContainer */
        {
            [!INDENT "8"!]
            Can_43_FLEXCAN_MessageBufferConfigs[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!], /* pMessageBufferConfigsPtr */
            (Can_HwHandleType)CAN_43_FLEXCAN_MAXMBCOUNT_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!], /* uMessageBufferConfigCount */
            [!ENDINDENT!]
        },
        /* FlexCAN controller description - ControlerDescriptors*/
        Can_43_FLEXCAN_ControlerDescriptors[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
        
        #if (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON)
        /* Can_43_FLEXCAN_RxFiFoTableIdConfigType - pRxFiFoTableIdConfig */
        [!VAR "rxfifoenable" = "0"!]
        [!LOOP "CanController/*"!][!/* If at least one controller has RxFifo enabled, rxfifoenable var is set. */!]
            [!IF "CanRxFifo/CanControllerRxFifoEnable = 'true' or CanRxFifo/CanControllerEnhancedRxFifoEnable = 'true'"!]
                [!VAR "rxfifoenable" = "1"!]
            [!ENDIF!]
        [!ENDLOOP!]
        [!IF "$rxfifoenable = 1"!]
            RxFifoTableID_PBConfig[!"$CSET_NR"!],
        [!ELSE!]
            NULL_PTR, /* Rx fifo disabled */
        [!ENDIF!]
        #endif  /* (CAN_43_FLEXCAN_RXFIFO_ENABLE == STD_ON) */
        
        /* The index of the first HTH configured */
        [!VAR "Can_First_HTH_Index" = "0"!]
        [!VAR "Can_Check_ExistHTH" = "0"!]
        [!LOOP "node:order(CanHardwareObject/*,'node:value(CanObjectId)')"!]
            [!IF "CanObjectType = 'TRANSMIT'"!]
                [!IF "$Can_Check_ExistHTH = 0"!]
                    [!VAR "Can_First_HTH_Index" = "CanObjectId"!]
                [!ENDIF!]
                [!VAR "Can_Check_ExistHTH" = "1"!]
            [!ENDIF!]
        [!ENDLOOP!]
        [!IF "$Can_Check_ExistHTH = 0"!][!/* Unless it has any HTH, Can_First_HTH_Index will be equal Max MB count  */!]
            (Can_HwHandleType)CAN_43_FLEXCAN_MAXMBCOUNT_PB[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]
        [!ELSE!]
            (Can_HwHandleType)[!"num:i($Can_First_HTH_Index)"!]U
        [!ENDIF!]
        
        [!IF "node:exists(../CanGeneral/CanTimeStamp)"!]
        #if (defined(CAN_43_FLEXCAN_MESSAGE_BUFFER_TIMESTAMP_USED) || defined(CAN_43_FLEXCAN_HIGH_RESOLUTION_TIMESTAMP_USED))
            [!IF "../CanGeneral/CanTimeStamp/TimestampType = 'MESSAGE_BUFFER_TIMESTAMP'"!]
                #ifdef CAN_43_FLEXCAN_MESSAGE_BUFFER_TIMESTAMP_USED
                    ,CAN_43_FLEXCAN_[!"../CanGeneral/CanTimeStamp/MBTSBASE"!] /* Message Buffer Time Stamp Base */
                    /* Message Buffer external time tick enable */
                    [!IF "../CanGeneral/CanTimeStamp/TimestampTimeSource = 'EXTERNAL_CLOCK' and ../CanGeneral/CanTimeStamp/MBTSBASE = 'MESSAGE_BUFFER_TIMER'"!],(boolean)TRUE[!ELSE!],(boolean)FALSE[!ENDIF!][!CR!]
                #endif
            [!ENDIF!]
            /* Time Stamp Capture Point */
            [!IF "../CanGeneral/CanTimeStamp/TimestampType = 'MESSAGE_BUFFER_TIMESTAMP' and ../CanGeneral/CanTimeStamp/MBTSBASE = 'MESSAGE_BUFFER_TIMER'"!]
                ,CAN_43_FLEXCAN_HR_TIMESTAMP_DIS[!CR!]
            [!ELSE!]
                ,CAN_43_FLEXCAN_[!"../CanGeneral/CanTimeStamp/HRTimeStampCapturePoint"!][!CR!]
            [!ENDIF!]
            /* CanTxTimestampNotification */
            [!IF "../CanGeneral/CanTimeStamp/CanTxTimestampNotification != 'NULL_PTR'"!]
                ,&[!"normalize-space(../CanGeneral/CanTimeStamp/CanTxTimestampNotification)"!]
            [!ELSE!]
                ,NULL_PTR
            [!ENDIF!]
            /* CanRxTimestampNotification */
            [!IF "../CanGeneral/CanTimeStamp/CanRxTimestampNotification != 'NULL_PTR'"!]
                ,&[!"normalize-space(../CanGeneral/CanTimeStamp/CanRxTimestampNotification)"!]
            [!ELSE!]
                ,NULL_PTR
            [!ENDIF!]
        #endif
        [!ENDIF!]
        [!ENDINDENT!]
    };
[!ENDSELECT!]
[!ENDINDENT!]
 
/*==================================================================================================
*                                      GLOBAL CONSTANTS
==================================================================================================*/

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

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


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

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

#define CAN_43_FLEXCAN_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_1 MISRA 2012 Required Directive 4.10 */
/* @violates @ref Can_43_FLEXCAN_PBcfg[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!]_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_43_FLEXCAN_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */
