/**
*   @file    Can_PBcfg.c
*   @implements Can_PBcfg.c_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Can - module interface
*   @details Configuration Structures for PostBuild.
*
*   @addtogroup CAN_DRIVER
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : MCAN
*   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_PBcfg_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_PBcfg_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_PBcfg_c_REF_3
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Declaration is reserved for future feature.
*
* @section Can_PBcfg_c_REF_4
* Violates MISRA 2012 Advisory Rule 8.7,  Functions and objects should not be defined with external linkage if they are 
* referenced in only one translation unit.
* These objects are used in various parts of the code.
*
* @section Can_PBcfg_c_REF_5
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if identifier only appears in a single function.
* These objects are used when Precompile is supported.
*
* @section Can_PBcfg_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.
*/


/**
* @file           Can_PBcfg.c
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Can.h"
#include "Can_IPW.h"
#include "Reg_eSys_MCan.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_VersionCheck_Src_PB.m"!][!//
[!ENDNOCODE!][!//

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/*
* @file           Can_PBcfg.c
*/
#define CAN_VENDOR_ID_PBCFG_C                    43
/* @violates @ref Can_PBcfg_c_REF_3 MISRA 2012 Advisory Rule 2.5 */
#define CAN_MODULE_ID_PBCFG_C                    80
#define CAN_AR_RELEASE_MAJOR_VERSION_PBCFG_C     4
#define CAN_AR_RELEASE_MINOR_VERSION_PBCFG_C     3
#define CAN_AR_RELEASE_REVISION_VERSION_PBCFG_C  1
#define CAN_SW_MAJOR_VERSION_PBCFG_C             1
#define CAN_SW_MINOR_VERSION_PBCFG_C             0
#define CAN_SW_PATCH_VERSION_PBCFG_C             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Can header file are of the same vendor */
#if (CAN_VENDOR_ID_PBCFG_C != CAN_VENDOR_ID)
#error "Can_PBcfg.c and Can.h have different vendor ids"
#endif
/* Check if current file and Can header file are of the same Autosar version */
#if ((CAN_AR_RELEASE_MAJOR_VERSION_PBCFG_C != CAN_AR_RELEASE_MAJOR_VERSION) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PBCFG_C != CAN_AR_RELEASE_MINOR_VERSION) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PBCFG_C != CAN_AR_RELEASE_REVISION_VERSION) \
    )
  #error "AutoSar Version Numbers of Can_PBcfg.c and Can.h are different"
#endif
/* Check if current file and Can header file are of the same Software version */
#if ((CAN_SW_MAJOR_VERSION_PBCFG_C != CAN_SW_MAJOR_VERSION) || \
     (CAN_SW_MINOR_VERSION_PBCFG_C != CAN_SW_MINOR_VERSION) || \
     (CAN_SW_PATCH_VERSION_PBCFG_C != CAN_SW_PATCH_VERSION) \
    )
       #error "Software Version Numbers of Can_PBcfg.c and Can.h are different"
#endif

/* Check if current file and Can_IPW header file are of the same vendor */
#if (CAN_VENDOR_ID_PBCFG_C != CAN_IPW_VENDOR_ID_H)
#error "Can_PBcfg.c and Can_IPW.h have different vendor ids"
#endif
/* Check if current file and Can_IPW header file are of the same Autosar version */
#if ((CAN_AR_RELEASE_MAJOR_VERSION_PBCFG_C != CAN_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PBCFG_C != CAN_IPW_AR_RELEASE_MINOR_VERSION_H) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PBCFG_C != CAN_IPW_AR_RELEASE_REVISION_VERSION_H) \
    )
  #error "AutoSar Version Numbers of Can_PBcfg.c and Can_IPW.h are different"
#endif
/* Check if current file and Can_IPW header file are of the same Software version */
#if ((CAN_SW_MAJOR_VERSION_PBCFG_C != CAN_IPW_SW_MAJOR_VERSION_H) || \
     (CAN_SW_MINOR_VERSION_PBCFG_C != CAN_IPW_SW_MINOR_VERSION_H) || \
     (CAN_SW_PATCH_VERSION_PBCFG_C != CAN_IPW_SW_PATCH_VERSION_H) \
    )
       #error "Software Version Numbers of Can_PBcfg.c and Can_IPW.h are different"
#endif

/* Check if current file and Reg_eSys_MCan header file are of the same vendor */
#if (CAN_VENDOR_ID_PBCFG_C != CAN_VENDOR_ID_REGM)
    #error "Can_PBcfg.c and Reg_eSys_MCan.h have different vendor ids"
#endif
/* Check if current file and Reg_eSys_MCan header file are of the same Autosar version */
#if ((CAN_AR_RELEASE_MAJOR_VERSION_PBCFG_C != CAN_AR_RELEASE_MAJOR_VERSION_REGM) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PBCFG_C != CAN_AR_RELEASE_MINOR_VERSION_REGM) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PBCFG_C != CAN_AR_RELEASE_REVISION_VERSION_REGM))
    #error "AutoSar Version Numbers of Can_PBcfg.c and Reg_eSys_MCan.h are different"
#endif
/* Check if current file and Reg_eSys_MCan header file are of the same Software version */
#if ((CAN_SW_MAJOR_VERSION_PBCFG_C != CAN_SW_MAJOR_VERSION_REGM) || \
     (CAN_SW_MINOR_VERSION_PBCFG_C != CAN_SW_MINOR_VERSION_REGM) || \
     (CAN_SW_PATCH_VERSION_PBCFG_C != CAN_SW_PATCH_VERSION_REGM))
    #error "Software Version Numbers of Can_PBcfg.c and Reg_eSys_MCan.h are different"
#endif

#define CAN_START_SEC_CONST_UNSPECIFIED
/* @violates @ref Can_PBcfg_c_REF_1 MISRA 2012 Required Directive 4.10 */
#include "Can_MemMap.h"

/*==================================================================================================
*                                   GLOBAL FUNCTION PROTOTYPES
==================================================================================================*/
/**
@brief    Prototype of User Notifications
*/
[!NOCODE!][!INCLUDE "Can_NotifyCheck_Src_PB.m"!][!ENDNOCODE!]
[!NOCODE!][!INCLUDE "Can_SourceClock.m"!][!ENDNOCODE!]
[!NOCODE!][!CALL "CanRxFifoWarningNotification_PB"!][!ENDNOCODE!]
[!NOCODE!][!CALL "CanRxFifoOverflowNotification_PB"!][!ENDNOCODE!]
[!NOCODE!][!CALL "CanErrorControllerNotification_PB"!][!ENDNOCODE!]
[!NOCODE!][!CALL "CanMRAFNotification_PB"!][!ENDNOCODE!]

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


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


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

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


[!NOCODE!][!/* This section is for global variables, local to this file */!]
    [!VAR "Tsyncsegment" = "1"!][!/* Sync_seg has 1 Tq length */!]
    [!/*
        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!]

[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    /**
    * @brief          Can_RxFilterTableType
    * @details
    *
    */
    static CONST(Can_RxFilterTableType, CAN_CONST) RxFilterTableID[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][CAN_MAX_RX_FILTER_TABLE] =
    {
        [!INDENT "4"!]
        [!VAR "Mcan1StandardIndex" = "0"!][!//
        [!VAR "Mcan2StandardIndex" = "0"!][!//
        [!VAR "Mcan3StandardIndex" = "0"!][!//
        [!VAR "Mcan4StandardIndex" = "0"!][!//
        [!VAR "MTTCAN_0StandardIndex" = "0"!][!//
        [!VAR "Mcan1ExtendedIndex" = "0"!][!//
        [!VAR "Mcan2ExtendedIndex" = "0"!][!//
        [!VAR "Mcan3ExtendedIndex" = "0"!][!//
        [!VAR "Mcan4ExtendedIndex" = "0"!][!//
        [!VAR "MTTCAN_0ExtendedIndex" = "0"!][!//
        [!VAR "TableOffsetValue" = "0"!][!//
        [!VAR "TableConfigValue" = "0"!][!//
        [!VAR "TableTypeValue" = "2"!][!//
        [!VAR "TableIdCountLocal" = "0"!][!//
        [!VAR "TableId2Value" = "0"!][!//
        /* HRH: CanIdValue; CanFilterMaskValue */
        [!VAR "TableIdCount" = "num:i(count(CanHardwareObject/*[CanObjectType = 'RECEIVE']))"!]
        [!LOOP "CanHardwareObject/*"!]
            [!IF "CanObjectType = 'RECEIVE'"!]
                [!IF "CanIdType = 'STANDARD'"!]
                    [!SELECT "node:ref(CanControllerRef)"!]
                        [!IF "CanControllerActivation = 'true'"!]
                            [!IF "CanHwChannel='MCAN_1'"!] 
                                [!VAR "TableOffsetValue"="$Mcan1StandardIndex"!]
                                [!VAR "Mcan1StandardIndex"="$Mcan1StandardIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_2'"!] 
                                [!VAR "TableOffsetValue"="$Mcan2StandardIndex"!]
                                [!VAR "Mcan2StandardIndex"="$Mcan2StandardIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_3'"!] 
                                [!VAR "TableOffsetValue"="$Mcan3StandardIndex"!]
                                [!VAR "Mcan3StandardIndex"="$Mcan3StandardIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_4'"!] 
                                [!VAR "TableOffsetValue"="$Mcan4StandardIndex"!]
                                [!VAR "Mcan4StandardIndex"="$Mcan4StandardIndex+1"!]
                            [!ELSEIF "CanHwChannel='MTTCAN_0'"!] 
                                [!VAR "TableOffsetValue"="$MTTCAN_0StandardIndex"!]
                                [!VAR "MTTCAN_0StandardIndex"="$MTTCAN_0StandardIndex+1"!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!VAR "TableOffsetValue"="0"!]
                        [!ENDIF!]    
                    [!ENDSELECT!]
                    [!IF "CanStoreRxMB = 'FIFO_0'"!]
                        [!VAR "TableConfigValue" = "1"!]
                        [!VAR "TableId2Value" = "num:i(CanHwFilter/CanHwFilterMask)"!]
                    [!ELSEIF "CanStoreRxMB = 'FIFO_1'"!]
                        [!VAR "TableConfigValue" = "2"!]
                        [!VAR "TableId2Value" = "num:i(CanHwFilter/CanHwFilterMask)"!]
                    [!ELSEIF "contains(CanStoreRxMB,'BUFFER')"!]
                        [!VAR "TableConfigValue" = "7"!]
                        [!VAR "TableId2Value" = "num:i(substring-after(CanStoreRxMB,'BUFFER_'))"!]
                    [!ELSE!]
                        [!VAR "TableConfigValue" = "0"!]
                    [!ENDIF!]
                    [!VAR "TableTypeValue" = "2"!]
                    [!VAR "TableIdCountLocal" = "$TableIdCountLocal+1"!]
                    {
                        [!INDENT "8"!]
                        /* Can Controller Offset on chip: MCAN1=offset 0, MCAN2=offset 1, .. */
                        [!SELECT "node:ref(CanControllerRef)"!]
                            [!IF "CanControllerActivation = 'true'"!]
                                (uint8)[!"CanHwChannel"!]_OFFSET,
                            [!ELSE!]
                                (uint8)MCAN_NULL_OFFSET_U8,
                            [!ENDIF!]
                        [!ENDSELECT!]
                        /* ID type: EXTENDED, STANDARD, MIXED */
                        CAN_[!"CanIdType"!],
                        /* Filter Offset */
                        (uint8)[!"num:inttohex($TableOffsetValue,2)"!]U,
                        /* Filter Config */
                        (uint8)[!"num:inttohex($TableConfigValue,2)"!]U,
                        /* Filter Type */
                        (uint8)[!"num:inttohex($TableTypeValue,2)"!]U,
                        /* SFID1/EFID1 */
                        (uint32)[!"num:inttohex(CanHwFilter/CanHwFilterCode,8)"!]U,
                        /* SFID2/EFID2 */
                        (uint32)[!"num:inttohex($TableId2Value,8)"!]U
                        [!ENDINDENT!]
                    }[!IF "(num:i($TableIdCount) != num:i($TableIdCountLocal)) or (num:i(count(../../CanController/*/CanRxFilterElement/*)) != '0')"!],[!ENDIF!][!CR!]
                [!ELSE!]
                    [!SELECT "node:ref(CanControllerRef)"!]
                        [!IF "CanControllerActivation = 'true'"!]
                            [!IF "CanHwChannel='MCAN_1'"!] 
                                [!VAR "TableOffsetValue"="$Mcan1ExtendedIndex"!]
                                [!VAR "Mcan1ExtendedIndex"="$Mcan1ExtendedIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_2'"!] 
                                [!VAR "TableOffsetValue"="$Mcan2ExtendedIndex"!]
                                [!VAR "Mcan2ExtendedIndex"="$Mcan2ExtendedIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_3'"!] 
                                [!VAR "TableOffsetValue"="$Mcan3ExtendedIndex"!]
                                [!VAR "Mcan3ExtendedIndex"="$Mcan3ExtendedIndex+1"!]
                            [!ELSEIF "CanHwChannel='MCAN_4'"!] 
                                [!VAR "TableOffsetValue"="$Mcan4ExtendedIndex"!]
                                [!VAR "Mcan4ExtendedIndex"="$Mcan4ExtendedIndex+1"!]
                            [!ELSEIF "CanHwChannel='MTTCAN_0'"!] 
                                [!VAR "TableOffsetValue"="$MTTCAN_0ExtendedIndex"!]
                                [!VAR "MTTCAN_0ExtendedIndex"="$MTTCAN_0ExtendedIndex+1"!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!VAR "TableOffsetValue"="0"!]
                        [!ENDIF!]    
                    [!ENDSELECT!]
                    [!IF "CanStoreRxMB = 'FIFO_0'"!]
                        [!VAR "TableConfigValue" = "1"!]
                        [!VAR "TableId2Value" = "num:i(CanHwFilter/CanHwFilterMask)"!]
                    [!ELSEIF "CanStoreRxMB = 'FIFO_1'"!]
                        [!VAR "TableConfigValue" = "2"!]
                        [!VAR "TableId2Value" = "num:i(CanHwFilter/CanHwFilterMask)"!]
                    [!ELSEIF "contains(CanStoreRxMB,'BUFFER')"!]
                        [!VAR "TableConfigValue" = "7"!]
                        [!VAR "TableId2Value" = "num:i(substring-after(CanStoreRxMB,'BUFFER_'))"!]
                    [!ELSE!]
                        [!VAR "TableConfigValue" = "0"!]
                    [!ENDIF!]
                    [!VAR "TableTypeValue" = "2"!]
                    [!VAR "TableIdCountLocal" = "$TableIdCountLocal+1"!]
                    {
                        [!INDENT "8"!]
                        /* Can Controller Offset on chip: MCAN1=offset 0, MCAN2=offset 1, .. */
                        [!SELECT "node:ref(CanControllerRef)"!]
                            [!IF "CanControllerActivation = 'true'"!]
                                (uint8)[!"CanHwChannel"!]_OFFSET,
                            [!ELSE!]
                                (uint8)MCAN_NULL_OFFSET_U8,
                            [!ENDIF!]
                        [!ENDSELECT!]
                        /* ID type: EXTENDED, STANDARD, MIXED */
                        CAN_[!"'EXTENDED'"!],
                        /* Filter Offset */
                        (uint8)[!"num:inttohex($TableOffsetValue,2)"!]U,
                        /* Filter Config */
                        (uint8)[!"num:inttohex($TableConfigValue,2)"!]U,
                        /* Filter Type */
                        (uint8)[!"num:inttohex($TableTypeValue,2)"!]U,
                        /* SFID1/EFID1 */
                        (uint32)[!"num:inttohex(CanHwFilter/CanHwFilterCode,8)"!]U,
                        /* SFID2/EFID2 */
                        (uint32)[!"num:inttohex($TableId2Value,8)"!]U
                        [!ENDINDENT!]
                    }[!IF "(num:i($TableIdCount) != num:i($TableIdCountLocal)) or (num:i(count(../../CanController/*/CanRxFilterElement/*)) != '0')"!],[!ENDIF!][!CR!]
                [!ENDIF!]       
            [!ENDIF!]
        [!ENDLOOP!]
    
        /* Filter table: CanRxFilterElement */
        [!VAR "TableIdCount" = "num:i(count(CanController/*/CanRxFilterElement/*))"!]
        [!VAR "TableIdCountLocal" = "0"!]
        [!LOOP "CanController/*"!]
            [!IF "num:i(count(CanRxFilterElement/*)) != '0'"!]
                [!LOOP "CanRxFilterElement/*"!]
                    [!IF "CanFilterIDType = 'STANDARD'"!]
                        [!SELECT "node:current()/../.."!]
                            [!IF "CanControllerActivation = 'true'"!]
                                [!IF "CanHwChannel='MCAN_1'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan1StandardIndex"!]
                                    [!VAR "Mcan1StandardIndex"="$Mcan1StandardIndex+1"!]
                                [!ELSEIF "CanHwChannel='MCAN_2'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan2StandardIndex"!]
                                    [!VAR "Mcan2StandardIndex"="$Mcan2StandardIndex+1"!]
                                [!ELSEIF "CanHwChannel='MCAN_3'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan3StandardIndex"!]
                                    [!VAR "Mcan3StandardIndex"="$Mcan3StandardIndex+1"!]
                                [!ELSEIF "CanHwChannel='MCAN_4'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan4StandardIndex"!]
                                    [!VAR "Mcan4StandardIndex"="$Mcan4StandardIndex+1"!]
                                [!ELSEIF "CanHwChannel='MTTCAN_0'"!] 
                                    [!VAR "TableOffsetValue"="$MTTCAN_0StandardIndex"!]
                                    [!VAR "MTTCAN_0StandardIndex"="$MTTCAN_0StandardIndex+1"!]
                                [!ENDIF!]
                            [!ELSE!]
                                [!VAR "TableOffsetValue"="0"!]
                            [!ENDIF!]    
                        [!ENDSELECT!]                       
                    [!ELSE!]
                        [!SELECT "node:current()/../.."!]
                            [!IF "CanControllerActivation = 'true'"!]
                                [!IF "CanHwChannel='MCAN_1'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan1ExtendedIndex"!]
                                    [!VAR "Mcan1ExtendedIndex"="$Mcan1ExtendedIndex+1"!]
                                [!ENDIF!]
                                [!IF "CanHwChannel='MCAN_2'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan2ExtendedIndex"!]
                                    [!VAR "Mcan2ExtendedIndex"="$Mcan2ExtendedIndex+1"!]
                                [!ENDIF!]
                                [!IF "CanHwChannel='MCAN_3'"!]
                                    [!VAR "TableOffsetValue"="$Mcan3ExtendedIndex"!]
                                    [!VAR "Mcan3ExtendedIndex"="$Mcan3ExtendedIndex+1"!]
                                [!ENDIF!]
                                [!IF "CanHwChannel='MCAN_4'"!] 
                                    [!VAR "TableOffsetValue"="$Mcan4ExtendedIndex"!]
                                    [!VAR "Mcan4ExtendedIndex"="$Mcan4ExtendedIndex+1"!]
                                [!ENDIF!]
                                [!IF "CanHwChannel='MTTCAN_0'"!] 
                                    [!VAR "TableOffsetValue"="$MTTCAN_0ExtendedIndex"!]
                                    [!VAR "MTTCAN_0ExtendedIndex"="$MTTCAN_0ExtendedIndex+1"!]
                                [!ENDIF!]
                            [!ELSE!]
                                [!VAR "TableOffsetValue"="0"!]
                            [!ENDIF!]    
                        [!ENDSELECT!]
                    [!ENDIF!]
                    [!VAR "TableIdCountLocal" = "$TableIdCountLocal+1"!]
                    [!IF "node:ref(CanHardWareObjectRef)/CanStoreRxMB = 'FIFO_0'"!]
                        [!VAR "TableConfigValue" = "1"!]
                    [!ELSEIF "node:ref(CanHardWareObjectRef)/CanStoreRxMB = 'FIFO_1'"!]
                        [!VAR "TableConfigValue" = "2"!]
                    [!ELSEIF "contains(node:ref(CanHardWareObjectRef)/CanStoreRxMB,'BUFFER')"!]
                        [!VAR "TableConfigValue" = "7"!]
                        [!VAR "TableId2Value" = "num:i(substring-after(node:ref(CanHardWareObjectRef)/CanStoreRxMB,'BUFFER_'))"!]
                    [!ELSE!]
                        [!VAR "TableConfigValue" = "0"!]
                    [!ENDIF!]
                    [!IF "node:exists(CanRxFilterType)"!]
                        [!IF "CanRxFilterType = 'RANGE'"!]
                           [!VAR "TableTypeValue" = "0"!]
                        [!ELSEIF "CanRxFilterType = 'DUAL_ID'"!]
                           [!VAR "TableTypeValue" = "1"!]
                        [!ELSEIF "CanRxFilterType = 'CLASSIC'"!]
                           [!VAR "TableTypeValue" = "2"!]
                        [!ELSE!]
                           [!VAR "TableTypeValue" = "3"!]
                        [!ENDIF!]
                    [!ELSE!]
                        [!VAR "TableTypeValue" = "2"!]
                    [!ENDIF!]
                    [!VAR "TableId1Value" = "num:i(CanRxFilterId1Value)"!]
                    [!IF "node:exists(CanRxFilterId2Value)"!]
                        [!VAR "TableId2Value" = "num:i(CanRxFilterId2Value)"!]
                    [!ENDIF!]
                    {
                        [!INDENT "8"!]
                        /* Can Controller Offset on chip: MCAN1=offset 0, MCAN2=offset 1, .. */
                        [!IF "../../CanControllerActivation = 'true'"!]
                            (uint8)[!"../../CanHwChannel"!]_OFFSET,
                        [!ELSE!]
                            (uint8)MCAN_NULL_OFFSET_U8,
                        [!ENDIF!]
                        /* ID type: EXTENDED, STANDARD, MIXED */
                        CAN_[!"CanFilterIDType"!],
                        /* Filter Offset */
                        (uint8)[!"num:inttohex($TableOffsetValue,2)"!]U,
                        /* Filter Config */
                        (uint8)[!"num:inttohex($TableConfigValue,2)"!]U,
                        /* Filter Type */
                        (uint8)[!"num:inttohex($TableTypeValue,2)"!]U,
                        /* SFID1/EFID1 */
                        (uint32)[!"num:inttohex($TableId1Value,8)"!]U,
                        /* SFID2/EFID2 */
                        (uint32)[!"num:inttohex($TableId2Value,8)"!]U
                        [!ENDINDENT!]
                    }[!IF "num:i($TableIdCount) != num:i($TableIdCountLocal)"!],[!ENDIF!][!CR!]
                [!ENDLOOP!]
            [!ENDIF!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
    [!CR!]
[!ENDSELECT!]
[!ENDINDENT!]

/*==================================================================================================*/
/**
* @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.
*
*/
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "./CanHardwareObject/*[contains(CanStoreRxMB,'BUFFER')]"!]
        [!VAR "ControllerRef" ="CanControllerRef"!]
        [!VAR "BufferIndex" ="num:i(substring-after(CanStoreRxMB,'BUFFER_'))"!]
        [!IF "$BufferIndex > num:i(count(../*[contains(CanStoreRxMB,'BUFFER')][CanControllerRef=$ControllerRef])-1)"!]
            [!ERROR!]Rx Message Buffer Index in HRH must be consecutive and must be start at 0 in one MCAN controller [!ENDERROR!]
        [!ENDIF!]  
    [!ENDLOOP!]
    static CONST(Can_MBConfigObjectType, CAN_CONST) Can_MessageBufferConfigs[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][CAN_MAXMBCOUNT] =
    {
        [!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"!]
            /* [!"@name"!] Message Buffer of Can Controller ID = [!SELECT "node:ref(CanControllerRef)"!][!"num:i(CanControllerId)"!]U[!ENDSELECT!] */
            {
                [!INDENT "8"!]
                /* ControllerId  - based on the order from CanController list */
                [!SELECT "node:ref(CanControllerRef)"!]
                    (uint8)[!"num:i(CanControllerId)"!]U,
                [!ENDSELECT!]
                /* ID type: EXTENDED, STANDARD */
                CAN_[!"CanIdType"!],
                /* Receive/Transmit MB configuration */
                CAN_[!"CanObjectType"!],
                /* MessageId */
                [!IF "node:exists(CanHwFilter)"!]
                    (Can_IdType)[!"num:inttohex(CanHwFilter/CanHwFilterCode)"!]U,
                [!ELSE!]
                    (Can_IdType)0x0U,
                [!ENDIF!]
                /* This Bit not used in platfrom where IPV_MCAN present. Initialised to zero so as not to change generic file */
                (uint8)0U,
                /* Hardware Object ID */
                (Can_HwHandleType)[!"num:inttohex(CanObjectId)"!]U,
                #if (CAN_FD_MODE_ENABLE == STD_ON)
                /* Padding value for MB > 8 bytes */
                    [!IF " (node:exists(CanFdPaddingValue)) and node:exists((node:ref(node:ref(CanControllerRef)/CanControllerDefaultBaudrate))/CanControllerFdBaudrateConfig) and (CanObjectType = 'TRANSMIT')"!]
                        (uint8)[!"num:inttohex(CanFdPaddingValue)"!]U,
                    [!ELSE!]
                        (uint8)0U,
                    [!ENDIF!]
                #endif
                /* Store MB into Rx FIFO 0/Rx FIFO 1/ Rx Buffer */
                [!IF "CanObjectType='RECEIVE'"!]
                    [!IF "node:exists(CanStoreRxMB)"!]
                        [!IF "CanStoreRxMB = 'FIFO_0'"!]
                            (uint8)MCAN_STORE_RX_FIFO0_U8,
                        [!ELSEIF "CanStoreRxMB = 'FIFO_1'"!]
                            (uint8)MCAN_STORE_RX_FIFO1_U8,
                        [!ELSE!]
                            (uint8)[!"num:i(substring-after(CanStoreRxMB,'BUFFER_'))"!]U,
                        [!ENDIF!]
                    [!ELSE!]
                        (uint8)MCAN_STORE_TX_BUFFER_U8,
                    [!ENDIF!]
                [!ELSE!]
                    (uint8)MCAN_STORE_TX_BUFFER_U8,
                [!ENDIF!]
                /* Read/Write period reference used when polling mode is selected for the controller */
                [!IF "node:refexists(CanMainFunctionRWPeriodRef)"!]
                    [!SELECT "node:ref(CanMainFunctionRWPeriodRef)"!]
                        (uint8)[!"@index"!]U,   /* HOH reference is from [!"node:name(.)"!] */
                    [!ENDSELECT!]
                [!ELSE!]
                    (uint8)0U,  /* HOH configured for interrupt mode, reference not used */
                [!ENDIF!]
                /* Hardware Object Payload length */
                [!IF "node:exists(node:ref(node:ref(CanControllerRef)/CanControllerDefaultBaudrate)/CanControllerFdBaudrateConfig)"!]
                    (uint8)[!"substring-before(substring-after(./../../../CanGeneral/MBDSR,'_'),'_')"!]U,
                [!ELSE!]
                    (uint8)8U,
                [!ENDIF!]
                /* Hardware Object Count */
                (uint16)[!"CanHwObjectCount"!]U
            #if (STD_ON == CAN_TRIGGER_TRANSMIT_EN)
                [!IF "(node:exists(CanTriggerTransmitEnable)) and CanTriggerTransmitEnable = 'true'"!]
                    ,(boolean)TRUE
                [!ELSE!]
                    ,(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'))"!]
                    ,(boolean)TRUE
                [!ELSE!]
                    ,(boolean)FALSE
                [!ENDIF!]
                [!ENDINDENT!]
            }[!IF "$END_COMMA < $MASK_COUNT"!],[!CR!][!ENDIF!][!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
    [!CR!]
[!ENDSELECT!]
[!ENDINDENT!]
/*==================================================================================================*/
/**
* @brief          Information about Rx FIFO Configuration
* @details        Information about Rx FIFO Configuration
*
*/
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!IF "CanControllerActivation = 'true'"!]
            [!LOOP "CanRxFifo/*"!]
                static CONST(Can_ControllerRxFifoConfigType, CAN_CONST) Can_ControllerRxFifo[!"substring-after(ReceiveFifo,'FIFO_')"!]Configs_[!"../../CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
                /* FIFO Configuration of [!"node:name(.)"!] in [!"node:name(../..)"!] */
                {
                    
                    [!INDENT "4"!]
                    /* FIFO Configuration of [!"node:name(.)"!] in [!"node:name(../..)"!] */    
                    CAN_[!"ReceiveFifo"!],
                    [!"num:i(CanFifoDepth)"!]U,
                    [!IF "CanFifoWatermask/CanFifoWatermarkEnable ='false'"!]
                        [!"num:i(0)"!]U,
                        TRUE,
                        NULL_PTR,
                    [!ELSE!]
                        [!"num:i(CanFifoWatermask/CanFifoWatermarkLevel)"!]U,
                        [!IF "(CanFifoWatermask/CanFifoWatermarkProcessing) = 'POLLING'"!]
                            TRUE,
                        [!ELSE!]
                            FALSE,
                        [!ENDIF!]
                        [!IF "(normalize-space(CanFifoWatermask/CanFifoWatermarkNotification) != 'NULL_PTR') and (normalize-space(CanFifoWatermask/CanFifoWatermarkNotification) != '"NULL"')"!]
                            &[!"normalize-space(CanFifoWatermask/CanFifoWatermarkNotification)"!],
                        [!ELSE!]
                            NULL_PTR,
                        [!ENDIF!]
                    [!ENDIF!]
                    [!IF "CanFifoOverflow/CanFifoOverflowProcessing = 'POLLING'"!]
                        TRUE,
                    [!ELSE!]
                        FALSE,
                    [!ENDIF!]  
                    [!IF "(normalize-space(CanFifoOverflow/CanFifoOverflowNotification) != 'NULL_PTR') and (normalize-space(CanFifoOverflow/CanFifoOverflowNotification) != '"NULL"')"!]
                        &[!"normalize-space(CanFifoOverflow/CanFifoOverflowNotification)"!],
                    [!ELSE!]
                        NULL_PTR
                    [!ENDIF!]
                    [!ENDINDENT!]
                };
                [!CR!]
            [!ENDLOOP!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDINDENT!]

/*==================================================================================================*/
/**
* @brief          Information about Section Offset of Mcan controller
* @details        Information about Section Offset of Mcan controller
*
*/
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "StartSectionOffsetAdd" = "0"!]
    [!VAR "ExceedMemory" = "'false'"!]
    [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!][!//
        [!IF "CanControllerActivation = 'true'"!][!//
            static CONST(Can_ControllerSectionOffsetType, CAN_CONST) Can_ControllerSectionOffset_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
            {
                [!INDENT "4"!]
                [!VAR "CanCCName" = "node:name(.)"!]
                [!VAR "NumStandardFilterCC" = "0"!]
                [!VAR "NumStandardFilterHRH" = "0"!]
                [!VAR "NumExtendedFilterCC" = "0"!]
                [!VAR "NumExtendedFilterHRH" = "0"!]
                [!VAR "NumRxBuffer" = "0"!]
                [!VAR "NumTxBuffer" = "0"!]
                [!VAR "ElementSize" = "0"!]
                [!IF "node:exists(CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig)"!]
                    [!VAR "ElementSize"="num:i(substring-after(substring-before(../../../../CanGeneral/MBDSR,'_BYTES_PAYLOAD'),'CAN_') div 4 + 2)"!]
                [!ELSE!]
                    [!VAR "ElementSize"="num:i(4)"!]
                [!ENDIF!]        
                [!VAR "NumStandardFilterCC" = "num:i(count(CanRxFilterElement/*[CanFilterIDType='STANDARD']))"!]
                [!VAR "NumStandardFilterHRH" = "num:i(count(../../CanHardwareObject/*[CanIdType='STANDARD'][CanObjectType='RECEIVE'][contains(node:value(CanControllerRef),$CanCCName)]))"!]
                [!IF "($NumStandardFilterCC + $NumStandardFilterHRH) > ecu:get('MCan.CanConfigSet.CanFilterStd')"!]
                    [!ERROR!]Exceed number of standard filters of [!"$CanCCName"!]. There are only [!"ecu:get('MCan.CanConfigSet.CanFilterStd')"!] standard filters for one controller[!ENDERROR!]
                [!ENDIF!]  
                [!VAR "NumExtendedFilterCC" = "num:i(count(CanRxFilterElement/*[CanFilterIDType='EXTENDED']))"!]
                [!VAR "NumExtendedFilterHRH" = "num:i(count(../../CanHardwareObject/*[CanIdType!='STANDARD'][CanObjectType='RECEIVE'][contains(node:value(CanControllerRef),$CanCCName)]))"!]
                [!IF "($NumExtendedFilterCC + $NumExtendedFilterHRH) > ecu:get('MCan.CanConfigSet.CanFilterExtd')"!]
                    [!ERROR!]Exceed number of extended filters of [!"$CanCCName"!]. There are only [!"ecu:get('MCan.CanConfigSet.CanFilterExtd')"!] extended filters for one controller[!ENDERROR!]
                [!ENDIF!]
                [!IF "($NumStandardFilterCC + $NumStandardFilterHRH) > 0"!]
                    [!IF "($StartSectionOffsetAdd + ($NumStandardFilterCC + $NumStandardFilterHRH)) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                         [!IF "$ExceedMemory = 'false'"!]
                            [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Standard Filter Section Offset */
                            [!VAR "ExceedMemory" = "'true'"!]
                         [!ELSE!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Standard Filter Section Offset */         
                         [!ENDIF!]
                    [!ELSE!]
                        [!"num:i($StartSectionOffsetAdd)"!]U, /* Standard Filter Section Offset */
                    [!ENDIF!]
                [!ELSE!]
                    [!"num:i(0)"!]U, /* Standard Filter Section is not initialzed */
                [!ENDIF!]  
                [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + ($NumStandardFilterCC + $NumStandardFilterHRH)"!]
                [!IF "($NumExtendedFilterCC + $NumExtendedFilterHRH) > 0"!]
                    [!IF "($StartSectionOffsetAdd +  ($NumExtendedFilterCC + $NumExtendedFilterHRH)*2) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                        [!IF "$ExceedMemory = 'false'"!]
                            [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Extended Filter Section Offset */
                            [!VAR "ExceedMemory" = "'true'"!]
                        [!ELSE!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Extended Filter Section Offset */
                        [!ENDIF!]
                    [!ELSE!]
                        [!"num:i($StartSectionOffsetAdd)"!]U, /* Extended Filter Section Offset */
                    [!ENDIF!]
                [!ELSE!]
                    [!"num:i(0)"!]U, /* Extended Filter Section is not initialzed */
                [!ENDIF!]
                [!IF "node:exists(CanRxFifo/*[ReceiveFifo='FIFO_0']/CanFifoDepth)"!]
                    [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + ($NumExtendedFilterCC + $NumExtendedFilterHRH)*2"!]
                    [!IF "($StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_0']/CanFifoDepth)*$ElementSize) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                         [!IF "$ExceedMemory = 'false'"!]
                            [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_0 Section Offset */
                            [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_0']/CanFifoDepth)*$ElementSize"!]
                            [!VAR "ExceedMemory" = "'true'"!]
                         [!ELSE!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_0 Section Offset */
                            [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_0']/CanFifoDepth)*$ElementSize"!]
                         [!ENDIF!]
                    [!ELSE!]
                        [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_0 Section Offset */
                        [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_0']/CanFifoDepth)*$ElementSize"!]
                    [!ENDIF!]
                [!ELSE!]
                    [!"num:i(0)"!]U, /* FIFO_0 Section is not initialzed */
                    [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + ($NumExtendedFilterCC + $NumExtendedFilterHRH)*2"!]
                [!ENDIF!]  
                [!IF "node:exists(CanRxFifo/*[ReceiveFifo='FIFO_1']/CanFifoDepth)"!]
                    [!IF "($StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_1']/CanFifoDepth)*$ElementSize) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                        [!IF "$ExceedMemory = 'false'"!]
                           [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                           [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_1 Section Offset */
                           [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_1']/CanFifoDepth)*$ElementSize"!]
                           [!VAR "ExceedMemory" = "'true'"!]
                        [!ELSE!]
                           [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_1 Section Offset */
                           [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_1']/CanFifoDepth)*$ElementSize"!]
                        [!ENDIF!]
                    [!ELSE!]           
                        [!"num:i($StartSectionOffsetAdd)"!]U, /* FIFO_1 Section Offset */
                        [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + num:i(CanRxFifo/*[ReceiveFifo='FIFO_1']/CanFifoDepth)*$ElementSize"!]
                    [!ENDIF!]  
                [!ELSE!]
                    [!"num:i(0)"!]U, /* FIFO_1 Section is not initialzed */  
                [!ENDIF!]
                [!VAR "NumRxBuffer" = "num:i(count(../../CanHardwareObject/*[CanObjectType='RECEIVE'][contains(CanStoreRxMB,'BUFFER')][contains(node:value(CanControllerRef),$CanCCName)]))"!]
                [!IF "$NumRxBuffer > 0"!]
                    [!IF "($StartSectionOffsetAdd + $NumRxBuffer*$ElementSize) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                        [!IF "$ExceedMemory = 'false'"!]
                           [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                           [!"num:i($StartSectionOffsetAdd)"!]U, /* Rx_Buffer Section Offset */
                           [!VAR "ExceedMemory" = "'true'"!]
                        [!ELSE!]
                           [!"num:i($StartSectionOffsetAdd)"!]U, /* Rx_Buffer Section Offset */  
                        [!ENDIF!]
                    [!ELSE!]
                        [!"num:i($StartSectionOffsetAdd)"!]U, /* Rx_Buffer Section Offset */
                    [!ENDIF!]
                [!ELSE!]
                    [!"num:i(0)"!]U, /* Rx_Buffer Section is not initialzed */
                [!ENDIF!]
                [!VAR "NumTxBuffer" = "num:i(count(../../CanHardwareObject/*[CanObjectType='TRANSMIT'][contains(node:value(CanControllerRef),$CanCCName)]))"!]
                [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + $NumRxBuffer*$ElementSize"!]
                [!IF "$NumTxBuffer > 0"!]
                    [!IF "($StartSectionOffsetAdd + $NumTxBuffer*$ElementSize) > num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetStart'))"!]
                         [!IF "$ExceedMemory = 'false'"!]
                            [!VAR "StartSectionOffsetAdd" = "num:i(ecu:get('MCan.CanConfigSet.TTCanSRamOffsetEnd'))"!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Tx_Buffer Section Offset */
                            [!VAR "ExceedMemory" = "'true'"!]
                         [!ELSE!]
                            [!"num:i($StartSectionOffsetAdd)"!]U, /* Tx_Buffer Section Offset */    
                         [!ENDIF!]
                    [!ELSE!]
                        [!"num:i($StartSectionOffsetAdd)"!]U /* Tx_Buffer Section Offset */
                    [!ENDIF!]
                [!ELSE!]
                    [!"num:i(0)"!]U /* Tx_Buffer Section is not initialzed */
                [!ENDIF!]  
                [!VAR "StartSectionOffsetAdd" = "$StartSectionOffsetAdd + $NumTxBuffer*$ElementSize"!]
                [!IF "$StartSectionOffsetAdd > num:i(ecu:get('MCan.CanConfigSet.SRamSize'))"!]
                    [!ERROR!] Not enough shared RAM resource [!ENDERROR!]
                [!ENDIF!]
                [!ENDINDENT!]
            };
            [!CR!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDINDENT!]
/*==================================================================================================*/
/**
* @brief          Configuration of MCan controller
* @details        Configuration of MCan controller
*
*/
[!INDENT "0"!]
[!VAR "LoopVar"="0"!][!//
[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!VAR "MASK_COUNT2"="num:i(count(CanControllerBaudrateConfig/*))"!]
        [!VAR "END_COMMA2"="0"!]
        static CONST(Can_ControllerBaudrateConfigType, CAN_CONST) Can_ControllerBaudrateCfgSet_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!][[!"num:i(count(CanControllerBaudrateConfig/*))"!]] =
        {
            [!INDENT "4"!]
            [!LOOP "CanControllerBaudrateConfig/*"!][!VAR "END_COMMA2"="$END_COMMA2 + 1"!][!//
                [!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).
                */!]
                [!/* Make the selection of source clock: from MCU or from CAN bus. */!]
                [!VAR "OutCanClockFrequencyFromMcu" = "0"!]
                [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                    [!VAR "OutCanClockFrequencyFromMcu_Alternate" = "0"!]
                [!ENDIF!][!ENDIF!]
                [!CALL "CanClockFrequency_M"!]
                [!VAR "CANClockFrequency" = "$OutCanClockFrequencyFromMcu"!][!/* Get the clock from MCU */!]
                [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!]
                    [!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                        [!VAR "CANClockFrequency_Alternate" = "$OutCanClockFrequencyFromMcu_Alternate"!][!/* Get the clock from MCU */!]
                    [!ENDIF!]
                [!ENDIF!]
                
                [!/* Calculate the prescaler */!]
                [!VAR "Prescaler" = "num:i(CanControllerPrescaller)"!][!/* Calculate Prescaler value. */!]
                [!VAR "CanControllerTimeQuanta" = "$Prescaler div ($CANClockFrequency)"!]
                [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!]
                    [!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 "($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]
                        No of CanTimeQuantas = (1 / CanControllerBaudRate) / CanControllerTimeQuanta; where CanControllerTimeQuanta = (Prescaler / CANClockFrequency).
                    [!ENDERROR!]
                [!ENDIF!]
                [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!]
                    [!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                        [!VAR "CANTimeQuanta_Alternate" = "num:i(round((1 div (num:i(CanControllerBaudRate) * 1000)) div $CanControllerTimeQuanta_Alternate))"!]
                        [!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 = [!"num:i($CANTimeQuanta_Alternate)"!] --->>> OUT of RANGE [8-25]
                                No of CanTimeQuantas = (1 / CanControllerBaudRate) / CanControllerTimeQuanta_Alternate; where CanControllerTimeQuanta_Alternate = (Prescaler_Alternate / CANClockFrequency_Alternate).
                            [!ENDERROR!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDIF!]

                [!IF "CanAdvancedSetting = 'false'"!]
                    [!IF "CanControllerCheckCanStandard"!]
                        [!IF "ecu:get('MCan.CanConfigSet.CanFdEnable')='STD_ON'"!]
                            [!/* 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"!]
                                    [!VAR "OutCanClockFrequencyFromMcuCbt" = "McuClockReferencePointFrequency"!]
                                [!ENDSELECT!]
                                [!VAR "CANTimeQuantaFd" = "num:i($OutCanClockFrequencyFromMcuFd div(num:i(num:i(CanControllerFdBaudrateConfig/CanControllerFdBaudRate) * (num:i(CanControllerFdBaudrateConfig/CanControllerFDPrescaller))*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 "UserNoTimeQuantasFd"= "num:i($FdTsyncsegment + $FdTimeSegment1 + $FdTimeSegment2)"!]
                                [!IF "($CANTimeQuantaFd) != ($UserNoTimeQuantasFd)"!]
                                    [!ERROR!]
                                        Time quanta value calculated based on CPU frequency and user prescaler should be [!"$CANTimeQuantaFd "!].
                                        The value of FdTimeSegment1 + FdTimeSegment2 + FdTsyncsegment -> [!"$FdTimeSegment1"!] + [!"$FdTimeSegment2"!] + [!"$FdTsyncsegment"!]= [!"$UserNoTimeQuantasFd"!]
                                    [!ENDERROR!]  
                                [!ENDIF!]
                                
                                [!IF "($CANTimeQuantaFd<5) or ($CANTimeQuantaFd>48) "!]
                                    [!ERROR!]
                                        Time quanta out of range. Modify the prescaller to obtain a valid Time Quanta
                                    [!ENDERROR!]
                                [!ENDIF!]

                                [!IF "($FdTimeSegment1<0) or ($FdTimeSegment1>255) "!]
                                    [!ERROR!]
                                        FdTimeSegment1 should have values between 0 and 255
                                    [!ENDERROR!]
                                [!ENDIF!]

                                [!IF "($FdTimeSegment2<0) or ($FdTimeSegment2>255) "!]
                                    [!ERROR!]
                                        FdTimeSegment2 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 "($TimeSegment2 < 2) or ($TimeSegment2 > 8)"!]
                            [!ERROR!]
                                For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], TimeSegment2 [=CanControllerSeg2] should be between [2 .. 8], current value is [!"num:i($TimeSegment2)"!]
                            [!ENDERROR!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [5..10], TimeSegment2: 2, ResynchronizationJumpWidth: [1..2] */!]
                        [!IF "$TimeSegment2 = 2"!]
                            [!IF "(num:i($TimeSegment1) < 5) or (num:i($TimeSegment1) > 10)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [5 .. 10], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 2)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], If TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 2] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [4..11], TimeSegment2: 3, ResynchronizationJumpWidth: [1 .. 3] */!]
                        [!IF "$TimeSegment2 = 3"!]
                            [!IF "(num:i($TimeSegment1) < 4) or (num:i($TimeSegment1) > 11)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [4 .. 11], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 3)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], If TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 3] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [5..12], TimeSegment2: 4, Re-synchronizationJumpWidth: [1 .. 4] */!]
                        [!IF "$TimeSegment2 = 4"!]
                            [!IF "(num:i($TimeSegment1) < 5) or (num:i($TimeSegment1) > 12)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [5 .. 12], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 4)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 4] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [6..13], TimeSegment2: 5, ResynchronizationJumpWidth: [1..4] */!]
                        [!IF "$TimeSegment2 = 5"!]
                            [!IF "(num:i($TimeSegment1) < 6) or (num:i($TimeSegment1) > 13)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1 + 2] should be between [6 .. 13], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 4)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 4] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [7..14], TimeSegment2: 6, ResynchronizationJumpWidth: [1..4] */!]
                        [!IF "$TimeSegment2 = 6"!]
                            [!IF "(num:i($TimeSegment1) < 7) or (num:i($TimeSegment1) > 14)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [7 .. 14], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 4)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 4] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [8..15], TimeSegment2: 7, ResynchronizationJumpWidth: [1..4] */!]
                        [!IF "$TimeSegment2 = 7"!]
                            [!IF "(num:i($TimeSegment1) < 8) or (num:i($TimeSegment1) > 15)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [8 .. 15], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 4)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=anControllerSeg2] is [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 4] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]
                        [!/* TimeSegment1: [9..16], TimeSegment2: 8, ResynchronizationJumpWidth: [1..4] */!]
                        [!IF "$TimeSegment2 = 8"!]
                            [!IF "(num:i($TimeSegment1) < 9) or (num:i($TimeSegment1) > 16)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] was [!"num:i(num:i(CanControllerSeg2))"!], TimeSegment1 [= CanControllerPropSeg + CanControllerSeg1] should be between [9 .. 16], current value is [!"num:i($TimeSegment1)"!].[!ENDERROR!]
                            [!ENDIF!]
                            [!IF "((CanControllerSyncJumpWidth) < 1) or ((CanControllerSyncJumpWidth) > 4)"!]
                                [!ERROR!]For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], When TimeSegment2 [=CanControllerSeg2] was [!"num:i(num:i(CanControllerSeg2))"!], (CanControllerSyncJumpWidth) should be between [1 .. 4] instead of [!"CanControllerSyncJumpWidth"!].[!ENDERROR!]
                            [!ENDIF!]
                        [!ENDIF!]

                        [!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"!],
                            No of CanTimeQuantas should be between [8 .. 25], current value is [!"num:i($NoTimeQuantas)"!].
                            BitTimeQuanta = SyncSeg + PropSeg + PSEG1 + PSEG2.
                            SyncSeg = 1. PropSeg = [!"num:i(CanControllerPropSeg)"!]. PSEG1 = [!"num:i(CanControllerSeg1)"!]. PSEG2 = [!"num:i(CanControllerSeg2)"!].[!ENDERROR!]
                        [!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"="round($Tpropogationsegment div $CanControllerTimeQuanta )"!]

                    [!IF "($PropogationSegment >= 1) and ($PropogationSegment <= 8)"!]
                        [!VAR "PhaseSegments" = "($CANTimeQuanta - $PropogationSegment - $Tsyncsegment)"!]
                        [!IF "$PhaseSegments >= 3"!]
                            [!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.
                                [!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.
                                [!ENDERROR!]
                            [!ENDIF!]
                            [!IF "$PhaseSegment1 < 5"!]
                                    [!VAR "SJW" = "num:i($PhaseSegment1)"!]
                            [!ELSE!]
                                    [!VAR "SJW" = "4"!]
                            [!ENDIF!]
                        [!ELSE!]
                            [!ERROR!] For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!], (Phase Segment1+Phase Segment2) must be >= 3. 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"!],
                        Propagation Segment is out of range [1:8].
                        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 = 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 by No of CanTimeQuantas calculated from clock settings ([!"num:i($CANTimeQuanta)"!]).
                                NoTimeQuantas = SyncSeg + PropSeg + PSEG1 + PSEG2 (from user settings).
                                NoCANTimeQuantas = (1 / CanControllerBaudRate) / CanControllerTimeQuanta;
                                Increase the Prescaller or the time segments.
                        [!ENDWARNING!]
                    [!ENDIF!]
                    [!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                        [!IF "num:i($CANTimeQuanta_Alternate) != num:i($NoTimeQuantas)"!]
                            [!WARNING!]
                                    For [!"node:name(.)"!] of CanController [!"../../CanHwChannel"!],
                                    The No of CanTimeQuantas set by you ([!"$NoTimeQuantas"!]) is different by No of CANTimeQuanta_Alternate calculated from clock alternate settings ([!"num:i($CANTimeQuanta_Alternate)"!]).
                                    NoTimeQuantas = SyncSeg + PropSeg + PSEG1 + PSEG2 (from user settings).
                                    NoCANTimeQuantas_Alternate = (1 / CanControllerBaudRate) / CanControllerTimeQuanta_Alternate;
                                    Where CanControllerTimeQuanta_Alternate = Prescaler_Alternate / CANClockFrequency_Alternate;
                                    Change the Prescaler_Alternate or the time segments.
                            [!ENDWARNING!]
                        [!ENDIF!]
                    [!ENDIF!]
                [!ENDIF!]
                [!ENDNOCODE!]
                /*
                    =================================================
                    Clock Size = [!"$CANClockFrequency"!]Hz Clock from MCU.
                    [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Clock Size Alternate = [!"$CANClockFrequency_Alternate"!]Hz  Clock from MCU.[!ENDIF!][!ENDIF!][!CR!]
                    Clock Prescaler = [!"$Prescaler"!] (1..1023)
                    [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Clock Prescaler_Alternate = [!"$Prescaler_Alternate"!] (1..256)[!ENDIF!][!ENDIF!][!CR!]
                    CanBitRate = [!"CanControllerBaudRate"!] Kbps (1bps..1Mbps)
                    Number CANTimeQuantas per bit = [!"$CANTimeQuanta"!] (8..25)
                    [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!][!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]Number CANTimeQuantas_Alternate per bit = [!"$CANTimeQuanta_Alternate"!] (8..25)[!ENDIF!][!ENDIF!][!CR!]
                    BTP Register Fields:
                        [!INDENT "8"!]
                        TSEG1 = [!WS "1"!][!IF "CanAdvancedSetting"!][!"num:i($PropogationSegment + $PhaseSegment1 - 1)"!][!ELSE!][!"num:i(CanControllerPropSeg + CanControllerSeg1 - 1)"!][!ENDIF!] [!WS "1"!](0..15)
                        TSEG2 = [!WS "1"!][!IF "CanAdvancedSetting"!][!"num:i($PhaseSegment2 - 1)"!][!ELSE!][!"num:i(CanControllerSeg2 - 1)"!][!ENDIF!] [!WS "1"!](1..7)
                        SJW = [!WS "1"!][!IF "CanAdvancedSetting"!][!"num:i($SJW - 1)"!][!ELSE!][!"num:i(CanControllerSyncJumpWidth - 1)"!][!ENDIF!] [!WS "1"!](0..3)
                        [!ENDINDENT!]
                    =================================================
                */
                [!IF "../../CanControllerActivation = 'true'"!]
                    /* Configuration for CanController ID[!"../../CanControllerId"!] == [!"../../CanHwChannel"!] */
                    {
                        [!INDENT "8"!]
                        /* ===== Bit Timing and Prescaler Register - BTP ===== */
                        
                        /* BTP[BRP] - Clock Prescaler */
                        (uint32)(
                                 [!INDENT "18"!]
                                 [!SELECT "as:modconf('Resource')[1]"!]
                                    (uint32)((uint32)[!"num:i(num:i($Prescaler - 1))"!]U << MCAN_NBTP_BRP_SHIFT_U8) |
                                 [!ENDSELECT!]
                                 /* BTP[TSEG1] - Segment 1 */
                                 ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSeg1 + CanControllerPropSeg - 1)"!][!ELSE!](uint32)[!"num:i($PhaseSegment1 + $PropogationSegment - 1)"!][!ENDIF!]U << MCAN_NBTP_TSEG1_SHIFT_U8) |
                                 /* BTP[TSEG2] - Segment 2 */
                                 ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSeg2 - 1)"!][!ELSE!](uint32)[!"num:i($PhaseSegment2 - 1)"!][!ENDIF!]U << MCAN_NBTP_TSEG2_SHIFT_U8) | 
                                 /* BTP[SJW] - Resynchronization Jump Width */
                                 ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSyncJumpWidth - 1)"!][!ELSE!](uint32)[!"num:i($SJW -1 )"!][!ENDIF!]U << MCAN_NBTP_SJW_SHIFT_U8) |
                                 (uint32)0U
                                 [!ENDINDENT!]
                        [!WS "8"!]),
                        
                        #if (CAN_DUAL_CLOCK_MODE == STD_ON)
                        [!IF "node:exists(./../../../../../CanGeneral/CanEnableDualClockMode)"!]
                            [!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                                /* ===== Bit Timing and Prescaler Register - BTP ===== */
                                /* BTP[BRP] - Clock Prescaler */
                                (uint32)(
                                          [!INDENT "18"!]
                                          [!SELECT "as:modconf('Resource')[1]"!]
                                              (((uint32)[!"num:i(num:i($Prescaler_Alternate - 1))"!]U << MCAN_NBTP_BRP_SHIFT_U8)  & MCAN_NBTP_BRP_U32) |
                                          [!ENDSELECT!]
                                          /* BTP[TSEG1] - Segment 1 */
                                          ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSeg1 + CanControllerPropSeg - 1)"!][!ELSE!](uint32)[!"num:i($PhaseSegment1 + $PropogationSegment - 1)"!][!ENDIF!]U << MCAN_NBTP_TSEG1_SHIFT_U8) |
                                          /* BTP[TSEG2] - Segment 2 */
                                          ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSeg2 - 1)"!][!ELSE!](uint32)[!"num:i($PhaseSegment2 - 1)"!][!ENDIF!]U << MCAN_NBTP_TSEG2_SHIFT_U8) |
                                          /* BTP[SJW] - Resynchronization Jump Width */
                                          ([!IF "CanAdvancedSetting = 'false'"!](uint32)[!"num:i(CanControllerSyncJumpWidth - 1)"!][!ELSE!](uint32)[!"num:i($SJW -1 )"!][!ENDIF!]U << MCAN_NBTP_SJW_SHIFT_U8) |
                                           (uint32)0U
                                          [!ENDINDENT!]
                               [!WS "8"!]),
                            [!ELSE!]
                                0U,
                            [!ENDIF!]
                        [!ELSE!]
                            0U,
                        [!ENDIF!]
                        [!IF "./../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                            [!INFO!]When dual clock feature is enabled (CanEnableDualClockMode), user has to use Can_SetClockMode API to switch between NORMAL Clock or ALTERNATE Clock.[!ENDINFO!]
                        [!ENDIF!]
                        #endif /* CAN_DUAL_CLOCK_MODE == STD_ON */
                        
                        (uint16)[!"CanControllerBaudRate"!] ,  /* [!"CanControllerBaudRate"!]kbps baud rate */
                        
                        [!IF "ecu:get('MCan.CanConfigSet.CanFdEnable')='STD_ON'"!]
                            #if (CAN_FD_MODE_ENABLE == STD_ON)
                            {
                                [!INDENT "12"!]
                                [!IF "(node:exists(CanControllerFdBaudrateConfig)) = 'true'"!]
                                    [!SELECT "CanControllerFdBaudrateConfig"!]
                                        (uint32)((uint32)1U << MCAN_FD_OFFSET_U8), /*CAN FD Activated*/
                                        (uint32)[!"CanControllerFdBaudRate"!]U,   /* [!"CanControllerFdBaudRate"!]kbps baud rate */
                                        (uint32)(
                                                [!INDENT "22"!]
                                                [!VAR "PropSegment" = "num:i(CanControllerPropSeg)"!] /* Propagation segment */
                                                [!VAR "Segment1" = "num:i(CanControllerSeg1)"!] /* Phase segment 1 */
                                                [!IF "node:exists(CanControllerTrcvDelayCompensationOffset)"!]
                                                    /* Active Transceiver Delay Compenstation */
                                                    ((uint32)1U << MCAN_FD_TDC_OFFSET) |
                                                [!ENDIF!]
                                                ((uint32)[!"num:i((CanControllerFDPrescaller)-1)"!]U << MCAN_FD_PRESDIV_OFFSET) |  /* CAN FD propagation segment */
                                                ((uint32)[!"num:i($Segment1 + $PropSegment - 1)"!]U << MCAN_FD_PSEG1_OFFSET) | /* Time segment 1 = Propagation segment + Phase segment 1 */
                                                ((uint32)[!"num:i(CanControllerSeg2 - 1)"!]U << MCAN_FD_PSEG2_OFFSET) |   /* Time segment 2 = Phase segment 2 */
                                                ((uint32)[!"num:i(CanControllerSyncJumpWidth -1)"!]U << MCAN_FD_SJW_OFFSET) /* Sync jump width*/
                                                [!ENDINDENT!]
                                        [!WS "8"!]),
                                        [!IF "node:exists(CanControllerTrcvDelayCompensationOffset)"!]
                                            (uint32)[!"CanControllerTrcvDelayCompensationOffset"!]U << MCAN_TDCR_TDCO_SHIFT_U8, /* TRCV DELAY*/
                                        [!ELSE!]
                                            (uint32)0U << MCAN_TDCR_TDCO_SHIFT_U8,
                                        [!ENDIF!]
                                        [!IF "(node:value(CanControllerTxBitRateSwitch)) = 'true'"!]
                                            (uint32)((uint32)1U << MCAN_FD_BRS_OFFSET) /* BRS activated */
                                        [!ELSE!]
                                            (uint32)((uint32)0U << MCAN_FD_BRS_OFFSET) /* BRS deactivated */
                                        [!ENDIF!]
                                    [!ENDSELECT!]
                                [!ELSE!]
                                    (uint32)0U, /* CAN FD Deactivated */
                                    (uint32)0U, /* Baud rate */
                                    (uint32)0U, /* BTP configuration */
                                    (uint32)0U, /* TRCV DELAY */
                                    (uint32)0U  /* BRS deactivated */
                                [!ENDIF!]
                                [!ENDINDENT!]
                            },
                            #endif
                        [!ENDIF!]
                        #if (CAN_SET_BAUDRATE_API == STD_ON)
                            (uint16)[!"CanControllerBaudRateConfigID"!]U
                        #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. */
                        /* ===== Bit Timing and Prescaler Register - BTP ===== */
                        /* BTP[BRP] - Clock Prescaler */
                        (uint32)(
                                 [!INDENT "18"!]
                                 [!SELECT "as:modconf('Resource')[1]"!]
                                    ((uint32)7U << MCAN_NBTP_BRP_SHIFT_U8) |
                                 [!ENDSELECT!]
                                 /* BTP[SJW] - Resynchronization Jump Width */
                                 ((uint32)0U << MCAN_NBTP_SJW_SHIFT_U8) |
                                 /* BTP[PSEG1] - Segment 1 */
                                 ((uint32)3U << MCAN_NBTP_TSEG1_SHIFT_U8) |
                                 /* BTP[PSEG2] - Segment 2 */
                                 ((uint32)2U << MCAN_NBTP_TSEG2_SHIFT_U8) |
                                 /* BTP[PROPSEG] - Propagation segment */
                                 (uint32)0U
                                 [!ENDINDENT!]
                         [!WS "8"!]),
                        
                        #if (CAN_DUAL_CLOCK_MODE == STD_ON)
                            /* ===== Bit Timing and Prescaler Register Alternate - BTP ===== */
                            /* BTP[BRP] - Clock Prescaler */
                            (uint32)(
                                      [!INDENT "18"!]
                                      [!SELECT "as:modconf('Resource')[1]"!]
                                          ((uint32)7U << MCAN_NBTP_BRP_SHIFT_U8) |
                                      [!ENDSELECT!]
                                      /* BTP[SJW] - Resynchronization Jump Width */
                                      ((uint32)0U << MCAN_NBTP_SJW_SHIFT_U8 ) |
                                      /* BTP[PSEG1] - Segment 1 */
                                      ((uint32)3U << MCAN_NBTP_TSEG1_SHIFT_U8) |
                                      /* BTP[PSEG2] - Segment 2 */
                                      ((uint32)2U << MCAN_NBTP_TSEG2_SHIFT_U8) |
                                      /* BTP[PROPSEG] - Propagation segment */
                                      (uint32)0U
                                      [!ENDINDENT!]
                            [!WS "8"!]),
                        #endif /* CAN_DUAL_CLOCK_MODE == STD_ON */
                        (uint16)125U, /* 125kbps baud rate */
                        #if (CAN_SET_BAUDRATE_API == STD_ON)
                            (uint16)0U    /*Can Controller BaudRate ConfigID */
                        #endif
                        
                        [!ENDINDENT!]
                    }[!IF "$END_COMMA2 < $MASK_COUNT2"!],[!ENDIF!][!CR!]
                [!ENDIF!]
            [!ENDLOOP!]
            [!ENDINDENT!]
        };
        [!CR!]
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDINDENT!]

/*==================================================================================================*/
/**
* @brief          Description of individual MCan controllers on chip
* @details        Description of individual MCan controllers on chip
*
*/
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    static CONST(Can_ControlerDescriptorType, CAN_CONST) Can_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"!]
        [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
            [!VAR "END_COMMA4"="$END_COMMA4 + 1"!]
            /* ControlerDescriptor of [!"@name"!] */
            {
                [!INDENT "8"!]
                    [!IF "CanControllerActivation = 'true'"!]
                        [!VAR "CtrlId" = "CanControllerId"!]
                        [!VAR "rxbuffer" = "0"!]
                        [!VAR "txbuffer" = "0"!]
                        [!LOOP "../../CanHardwareObject/*"!]
                            [!IF "node:ref(CanControllerRef)/CanControllerId = $CtrlId"!]
                                [!IF "CanObjectType = 'RECEIVE'"!]
                                    [!IF "contains(CanStoreRxMB,'BUFFER')"!]
                                        [!VAR "rxbuffer" = "$rxbuffer + 1"!]
                                    [!ENDIF!]
                                [!ELSE!]
                                    [!VAR "txbuffer" = "$txbuffer + CanHwObjectCount"!]
                                [!ENDIF!]
                            [!ENDIF!]
                        [!ENDLOOP!]
                        [!IF "$rxbuffer>ecu:get('MCan.CanConfigSet.CanMB.RxBuffer')"!]
                            [!ERROR!]Exceeds maximum Number of Rx Buffers of [!"@name"!] - [!"ecu:get('MCan.CanConfigSet.CanMB.RxBuffer')"!] Rx Buffers.[!ENDERROR!]
                        [!ENDIF!]
                        [!IF "$txbuffer>ecu:get('MCan.CanConfigSet.CanMB.TxBuffer')"!]
                            [!ERROR!]Exceeds maximum Number of Tx Buffers of [!"@name"!] - [!"ecu:get('MCan.CanConfigSet.CanMB.TxBuffer')"!]  Tx Buffers.[!ENDERROR!]
                        [!ENDIF!]
                        /* No. of Rx Message Buffers for current controller */
                        (uint8)[!"num:i($rxbuffer)"!]U,
                        
                        /* No. of Tx Message Buffers for current controller */
                        (uint8)[!"num:i($txbuffer)"!]U,

                        /* ControllerRxFifo0ConfigsPtr */
                        [!IF "num:i(count(CanRxFifo/*[ReceiveFifo='FIFO_0'])) > 0"!]
                            &Can_ControllerRxFifo[!"substring-after('FIFO_0','FIFO_')"!]Configs_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
                        [!ELSE!]
                            NULL_PTR,
                        [!ENDIF!]

                        /* ControllerRxFifo1ConfigsPtr */
                        [!IF "num:i(count(CanRxFifo/*[ReceiveFifo='FIFO_1'])) > 0"!]
                            &Can_ControllerRxFifo[!"substring-after('FIFO_1','FIFO_')"!]Configs_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
                        [!ELSE!]
                            NULL_PTR,
                        [!ENDIF!]

                        /* pControllerSectionOffsetPtr */
                        &Can_ControllerSectionOffset_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],

                        /* No. of BaudRate configured for current controller */
                        [!VAR "maxbrcount" = "num:i(count(CanControllerBaudrateConfig/*))"!]
                        (uint8)[!"num:i($maxbrcount)"!]U,
                        [!IF "contains(node:path(node:ref(CanControllerDefaultBaudrate)),node:path(CanControllerBaudrateConfig))"!]
                        [!ELSE!]
                            [!ERROR!]
                                Please select CanControllerDefaultBaudrate from the "[!"substring-after(node:path(CanControllerBaudrateConfig),'ELEMENTS/')"!]" container.
                            [!ENDERROR!]
                        [!ENDIF!]

                        /* Default BaudRate configured for current controller */
                        (uint16)[!"node:ref(CanControllerDefaultBaudrate)/CanControllerBaudRateConfigID"!]U,

                        /* ControllerBaudrateConfigsPtr */
                        Can_ControllerBaudrateCfgSet_[!"CanControllerId"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],

                        /* ===== Controller Options ===== */
                        [!IF "InterruptLineEnable = 'INTERRUPTLINE0'"!]
                            (uint32)CAN_CTLR_CONFIG_ILE_INTL0_EN_U32
                        [!ENDIF!]
                        [!IF "InterruptLineEnable = 'INTERRUPTLINE1'"!]
                            (uint32)CAN_CTLR_CONFIG_ILE_INTL1_EN_U32
                        [!ENDIF!]
                    [!ELSE!]
                        /* No. of Rx Message Buffers for current controller */
                        (uint8)0U,

                        /* No. of Tx Message Buffers for current controller */
                        (uint8)0U,
                        
                        /* ControllerRxFifo0ConfigsPtr */
                        NULL_PTR,
                        
                        /* ControllerRxFifo1ConfigsPtr */
                        NULL_PTR,
                        
                        /* pControllerSectionOffsetPtr */
                        NULL_PTR,

                        /* No. of BaudRate configured for current controller */
                        (uint8)0U,

                        /* Default BaudRate configured for current controller */
                        (uint8)0U,

                        /* ControllerBaudrateConfigsPtr */
                        NULL_PTR,

                        /* ===== Controller Options ===== */
                        (uint32)0U
                    [!ENDIF!]
                [!ENDINDENT!]
            }[!IF "$END_COMMA4 < $MASK_COUNT4"!],[!ENDIF!][!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
[!ENDSELECT!]
[!ENDINDENT!]

/**
* @brief          Top level structure containing all Can driver configurations
* @details        Top level structure containing all Can driver configurations
*
*/
[!INDENT "0"!]
[!SELECT "CanConfigSet"!]
    /* @violates @ref Can_PBcfg_c_REF_4 MISRA 2012 Advisory Rule 8.7 */
    /* @violates @ref Can_PBcfg_c_REF_5 MISRA 2012 Advisory Rule 8.9 */
    [!IF "((../IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (../IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!]
        CONST(Can_ConfigType, CAN_CONST) Can_[!"as:name(.)"!][!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!] =
    [!ELSE!]
        CONST(Can_ConfigType, CAN_CONST) Can_PBCfgVariantPredefined =
    [!ENDIF!]
    {
        [!INDENT "4"!]
        /* MessageBufferConfigContainer */
        {
            [!INDENT "8"!]
            /* MessageBufferConfigsPtr */
                Can_MessageBufferConfigs[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
            
            /* MessageBufferConfigCount */
                (Can_HwHandleType)[!"num:i(count(CanHardwareObject/*))"!]U,
            [!ENDINDENT!]
        },

        /* MCAN controller description */
            Can_ControlerDescriptors[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],

        /* The number of Rx Filter Element */
            CAN_MAX_RX_FILTER_TABLE,

        /* Rx Filter Table */
            RxFilterTableID[!IF "var:defined('postBuildVariant')"!]_[!"$postBuildVariant"!][!ENDIF!],
        /*Can Object Type mapping*/
        {
            [!INDENT "8"!]
            [!VAR "Can_hardware_ob_id" = "0"!][!VAR "END_COMMA"="0"!]
                [!VAR "MASK_COUNT"="num:i(count(CanHardwareObject/*))"!]
                [!FOR "objectid" = "0" TO "num:i(count(CanHardwareObject/*) - 1)"!]
                    [!LOOP "CanHardwareObject/*"!]
                    [!IF "CanObjectId = $objectid"!]
                        [!VAR "END_COMMA"="$END_COMMA + 1"!]
                        [!IF "$Can_hardware_ob_id != CanObjectId"!]
                            [!VAR "Can_hardware_ob_id" = "CanObjectId"!]
                            CAN_[!"CanObjectType"!][!IF "$END_COMMA < $MASK_COUNT"!],[!ENDIF!][!CR!]
                        [!ELSE!]
                            [!VAR "END_COMMA"="$END_COMMA + 1"!]
                        [!ENDIF!]
                        [!BREAK!]
                    [!ENDIF!]
                [!ENDLOOP!]
            [!ENDFOR!]
            [!ENDINDENT!]
        }
        [!ENDINDENT!]
    };
[!ENDSELECT!]
[!ENDINDENT!]

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


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

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


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

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

#define CAN_STOP_SEC_CONST_UNSPECIFIED
/* @violates @ref Can_PBcfg_c_REF_1 MISRA 2012 Required Directive 4.10 */
/* @violates @ref Can_PBcfg_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */
