/**
*   @file    Can_43_FLEXCAN_Cfg.c
*   @implements Can_Cfg.c_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Can_43_FLEXCAN - module interface
*   @details Configuration Structures for PreCompile.
*
*   @addtogroup CAN_DRIVER
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : FLEXCAN
*   Dependencies         : 
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
*          The used compilers use more than 31 chars for identifiers.
*
* @section Can_43_FLEXCAN_Cfg_c_REF_1
* Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents 
* of a header file being included more than once
* This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Can_43_FLEXCAN_Cfg_c_REF_2
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor 
* directives or comments.
* AUTOSAR imposes the specification of the sections in which certain parts of the driver must be placed.
*
* @section Can_43_FLEXCAN_Cfg_c_REF_3
* 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.
*
* @section Can_43_FLEXCAN_Cfg_c_REF_4
* Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block scope if its identifier only appears
* in a single function.
* These objects are used when Precompile is supported.
*/

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

/**
* @file           Can_43_FLEXCAN_Cfg.c
*/

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

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

[!NOCODE!][!//
[!INCLUDE "Can_43_FLEXCAN_VersionCheck_Src.m"!][!//
[!ENDNOCODE!][!//

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define CAN_43_FLEXCAN_VENDOR_ID_PCCFG_C                   43
#define CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PCCFG_C     4
#define CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PCCFG_C     3
#define CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PCCFG_C  1
#define CAN_43_FLEXCAN_SW_MAJOR_VERSION_PCCFG_C             1
#define CAN_43_FLEXCAN_SW_MINOR_VERSION_PCCFG_C             0
#define CAN_43_FLEXCAN_SW_PATCH_VERSION_PCCFG_C             0

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

/* Check if current file and CAN header file are of the same vendor */
#if (CAN_43_FLEXCAN_VENDOR_ID_PCCFG_C != CAN_43_FLEXCAN_VENDOR_ID)
#error " Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN.h have different vendor ids"
#endif
/* Check if current file and CAN header file are of the same Autosar version */
#if ((CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION) || \
     (CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION) || \
     (CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PCCFG_C != CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION))
  #error "AutoSar Version Numbers of Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN.h are different"
#endif
/* Check if current file and CAN header file are of the same Software version */
#if ((CAN_43_FLEXCAN_SW_MAJOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_SW_MAJOR_VERSION) || \
     (CAN_43_FLEXCAN_SW_MINOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_SW_MINOR_VERSION) || \
     (CAN_43_FLEXCAN_SW_PATCH_VERSION_PCCFG_C != CAN_43_FLEXCAN_SW_PATCH_VERSION))
       #error "Software Version Numbers of Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN.h are different"
#endif

/* Check if current file and Can_IPW configuration header file are of the same vendor */
#if (CAN_43_FLEXCAN_VENDOR_ID_PCCFG_C  != CAN_43_FLEXCAN_IPW_VENDOR_ID_H)
#error "Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN_IPW.h have different vendor ids"
#endif
/* Check if current file and CAN_IPW header file are of the same Autosar version */
#if ((CAN_43_FLEXCAN_AR_RELEASE_MAJOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
     (CAN_43_FLEXCAN_AR_RELEASE_MINOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_MINOR_VERSION_H) || \
     (CAN_43_FLEXCAN_AR_RELEASE_REVISION_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_AR_RELEASE_REVISION_VERSION_H))
  #error "AutoSar Version Numbers of Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN_IPW.h are different"
#endif
/* Check if current file and CAN_IPW header file are of the same Software version */
#if ((CAN_43_FLEXCAN_SW_MAJOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_SW_MAJOR_VERSION_H) || \
     (CAN_43_FLEXCAN_SW_MINOR_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_SW_MINOR_VERSION_H) || \
     (CAN_43_FLEXCAN_SW_PATCH_VERSION_PCCFG_C != CAN_43_FLEXCAN_IPW_SW_PATCH_VERSION_H))
       #error "Software Version Numbers of Can_43_FLEXCAN_Cfg.c and Can_43_FLEXCAN_IPW.h are different"
#endif

/*==================================================================================================
*                                   GLOBAL FUNCTION PROTOTYPES
==================================================================================================*/
#define CAN_43_FLEXCAN_START_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_Cfg_c_REF_1 MISRA 2012 Required Directive 4.10 */
#include "Can_43_FLEXCAN_MemMap.h"

/**
* @brief    Prototype of User Notifications
*/
[!NOCODE!][!INCLUDE "Can_43_FLEXCAN_NotifyCheck_Src.m"!][!ENDNOCODE!][!//
[!NOCODE!][!INCLUDE "Can_43_FLEXCAN_SourceClock.m"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanRxFifoWarningNotification_PC"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanRxFifoOverflowNotification_PC"!][!ENDNOCODE!][!//
[!NOCODE!][!CALL "CanErrorControllerNotification_PC"!][!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!]

[!IF "(CanGeneral/CanPublicIcomSupport  = 'true') and (ecu:get('Can.CanConfigSet.CanPretendedNetworking')='STD_ON')"!]
    [!INDENT "0"!]
    /*==================================================================================================*/
    /**
    * @brief          Information about Pretended Networking
    * @details        All information about Pretended Networking
    *
    */
    /*==========================================generation of CanIcomRxMessageSignalConfig structures====================================================*/
    [!SELECT "CanConfigSet"!]
        [!VAR "CNT_ICOM_CONFIG_COUNTER" = "0"!]    
        [!LOOP "CanIcom/CanIcomConfig/*"!] 
            [!VAR "CNT_ICOM_RX_MESSAGE" = "0"!]
            [!LOOP "CanIcomWakeupCauses/CanIcomRxMessage/*"!] 
                [!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE1" = "0"!]
                [!LOOP "CanIcomRxMessageSignalConfig/*"!]
                    [!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE1" = "$CNT_ICOM_RX_SIGNAL_MESSAGE1+1"!]
                [!ENDLOOP!]
                [!IF "CanPayloadFilter = 'true'"!]
                    [!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE" = "0"!]
                    static CONST(Can_43_FLEXCAN_IcomRxMessageSignalType, CAN_CONST) Can_PnConfig_[!"num:i($CNT_ICOM_CONFIG_COUNTER)"!]_Rx[!"num:i($CNT_ICOM_RX_MESSAGE)"!]_Signal[[!"num:i($CNT_ICOM_RX_SIGNAL_MESSAGE1)"!]] =
                    {
                        [!INDENT "4"!]
                        [!VAR "CNT_ICOM_RX_MESSAGE" = "$CNT_ICOM_RX_MESSAGE+1"!]
                        [!LOOP "CanIcomRxMessageSignalConfig/*"!] 
                            {
                                [!INDENT "8"!]
                                    (uint32)[!"num:inttohex(bit:shr(num:i(node:value(CanIcomSignalMask)), 32), 8)"!]U,    /* CanIcomSignalMaskLow */
                                    (uint32)[!"num:inttohex(node:value(CanIcomSignalMask), 8)"!]U,    /* CanIcomSignalMaskHigh */
                                    [!"node:value(CanIcomSignalOperation)"!],   /*CanIcomSignalOperation */
                                    (uint32)[!"num:inttohex(bit:shr(num:i(node:value(CanIcomSignalValue)), 32), 8)"!]U,    /* CanIcomSignalValueLow */
                                    (uint32)[!"num:inttohex(node:value(CanIcomSignalValue), 8)"!]U,    /* CanIcomSignalValueHigh */
                                /*DLCLowValue */
                                [!IF "../../CanIcomPayloadLengthError='false'"!]
                                    [!"node:value(DLCLowValue)"!]U,
                                [!ELSE!]
                                    0U ,
                                [!ENDIF!]
                                /*DLCHighValue */
                                [!IF "../../CanIcomPayloadLengthError='false'"!]
                                    [!"node:value(DLCHighValue)"!]U,
                                [!ELSE!]    
                                    8U ,
                                [!ENDIF!]
                                /*CanIcomSignalRef */
                                [!IF "node:exists(CanIcomSignalRef)"!]
                                    1  /*  [!"node:value(CanIcomSignalRef)"!]*/ /*reference it is not availabel for now. It may be referenced from an upper layer*/
                                [!ELSE!]    
                                    0U
                                [!ENDIF!]
                                [!ENDINDENT!]
                            }[!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE" = "$CNT_ICOM_RX_SIGNAL_MESSAGE+1"!][!IF "$CNT_ICOM_RX_SIGNAL_MESSAGE1>1"!],[!ENDIF!][!CR!]
                        [!ENDLOOP!]
                        [!ENDINDENT!]
                    };
                    [!CR!]
                [!ENDIF!]
            [!ENDLOOP!]
            [!VAR "CNT_ICOM_CONFIG_COUNTER" = "$CNT_ICOM_CONFIG_COUNTER+1"!]
        [!ENDLOOP!]
    [!ENDSELECT!]
    /*============================================================================================================*/
    /*====================================generation of CanIcomRxMessage==========================================*/
    [!SELECT "CanConfigSet"!]
        [!VAR "CNT_ICOM_CONFIG_COUNTER" = "0"!]    
        [!LOOP "CanIcom/CanIcomConfig/*"!] 
            [!VAR "CNT_ICOM_RX_MESSAGE1" = "0"!]    
            [!LOOP "CanIcomWakeupCauses/CanIcomRxMessage/*"!]
                [!VAR "CNT_ICOM_RX_MESSAGE1" = "$CNT_ICOM_RX_MESSAGE1+1"!]
            [!ENDLOOP!]
            [!VAR "CNT_ICOM_RX_MESSAGE" = "0"!]
            static CONST(Can_43_FLEXCAN_IcomRxMessageConfigsType, CAN_CONST) Can_PnConfig_[!"num:i($CNT_ICOM_CONFIG_COUNTER)"!]_Rx[[!"num:i($CNT_ICOM_RX_MESSAGE1)"!]]=
            {
                [!INDENT "4"!]
                [!LOOP "CanIcomWakeupCauses/CanIcomRxMessage/*"!] 
                    {
                        [!INDENT "8"!]
                        [!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE1" = "0"!]
                        [!LOOP "CanIcomRxMessageSignalConfig/*"!]
                            [!VAR "CNT_ICOM_RX_SIGNAL_MESSAGE1" = "$CNT_ICOM_RX_SIGNAL_MESSAGE1+1"!]
                        [!ENDLOOP!]
                        /*value for node CanIcomCounterValue */
                        [!IF "node:exists(CanIcomCounterValue)"!]
                            [!"node:value(CanIcomCounterValue)"!]U,
                        [!ELSE!]
                            0U ,
                        [!ENDIF!]
                        /*value for node CanIcomMessageId*/
                        [!IF "node:exists(CanIcomMessageId)"!]
                            [!"node:value(CanIcomMessageId)"!]U,
                        [!ELSE!]
                            0U ,
                        [!ENDIF!]
                        /*value for node CanIcomMessageIdMask*/
                        [!IF "node:exists(CanIcomMessageIdMask)"!]
                            [!"node:value(CanIcomMessageIdMask)"!]U,
                        [!ELSE!]
                            0U ,
                        [!ENDIF!]
                        /*value for node CanIcomMissingMessageTimerValue*/
                        [!IF "node:exists(CanIcomMissingMessageTimerValue)"!]
                            [!"num:i(node:value(CanIcomMissingMessageTimerValue))"!]U,
                        [!ELSE!]
                            0U ,
                        [!ENDIF!]
                        /* Type of ID filtering */
                        [!IF "node:exists(CanIcomIdOperation)"!]
                            [!"node:value(CanIcomIdOperation)"!],
                        [!ELSE!]    
                            0U ,
                        [!ENDIF!]
                        /*total number of CanIcomRxSignalMessage defined structures - u8NumCanIcomRxMessageSignal*/
                        (uint8)[!"num:i($CNT_ICOM_RX_SIGNAL_MESSAGE1)"!]U,
                        /* Select filter payload or not*/
                        [!IF "CanPayloadFilter='true'"!]
                            (boolean)TRUE,
                        [!ELSE!]
                            (boolean)FALSE,
                        [!ENDIF!]
                        /*pCanIcomRxMessageSignalConfigs*/
                        [!IF "CanPayloadFilter = 'true'"!]
                            &Can_PnConfig_[!"num:i($CNT_ICOM_CONFIG_COUNTER)"!]_Rx[!"num:i($CNT_ICOM_RX_MESSAGE)"!]_Signal[0U]
                        [!ELSE!]
                            NULL_PTR
                        [!ENDIF!]
                        [!VAR "CNT_ICOM_RX_MESSAGE" = "$CNT_ICOM_RX_MESSAGE+1"!]            
                        [!ENDINDENT!]
                    }[!IF "$CNT_ICOM_RX_MESSAGE1>1"!] ,[!ENDIF!][!CR!]
                [!ENDLOOP!]
                [!ENDINDENT!]
            };
            [!CR!]
            [!VAR "CNT_ICOM_CONFIG_COUNTER" = "$CNT_ICOM_CONFIG_COUNTER+1"!]
        [!ENDLOOP!]  
    [!ENDSELECT!]
    /*==================================================================*/
    /*==============================generation of CanIcomConfig=========*/
    [!SELECT "CanConfigSet"!]
        [!VAR "CNT_ICOM_CONFIG_COUNTER1" = "0"!]    
        [!LOOP "CanIcom/CanIcomConfig/*"!]
            [!VAR "CNT_ICOM_CONFIG_COUNTER1" = "$CNT_ICOM_CONFIG_COUNTER1+1"!]
        [!ENDLOOP!]    
        [!VAR "CNT_ICOM_CONFIG_COUNTER" = "0"!]    
        static CONST(Can_43_FLEXCAN_IcomConfigsType, CAN_CONST) Can_PnConfig[[!"num:i($CNT_ICOM_CONFIG_COUNTER1)"!]] = 
        {
            [!INDENT "4"!]
            [!LOOP "CanIcom/CanIcomConfig/*"!] 
                {
                    [!INDENT "4"!]
                    /*value for node CanIcomConfigId */
                    (uint8)[!"node:value(CanIcomConfigId)"!]U,
                    /*value for node CanIcomWakeOnBusOff*/
                    [!IF "node:value(CanIcomWakeOnBusOff)='true'"!]
                        (boolean)TRUE,
                    [!ELSE!]
                        (boolean)FALSE,
                    [!ENDIF!]
                    /*u8NumberCanIcomRxMessage */
                    [!VAR "COUNT_ICOM_RX_MSG"="0"!]
                    [!LOOP "CanIcomWakeupCauses/CanIcomRxMessage/*"!]
                        [!VAR "COUNT_ICOM_RX_MSG"="$COUNT_ICOM_RX_MSG+1"!] 
                    [!ENDLOOP!]
                    (uint8)[!"num:i($COUNT_ICOM_RX_MSG)"!]U,
                    /*pCanIcomRxMessageConfigs*/
                    &Can_PnConfig_[!"num:i($CNT_ICOM_CONFIG_COUNTER)"!]_Rx[0U]
                    [!ENDINDENT!]
                }[!VAR "CNT_ICOM_CONFIG_COUNTER" = "$CNT_ICOM_CONFIG_COUNTER+1"!][!IF "$CNT_ICOM_CONFIG_COUNTER1>1"!] ,[!ENDIF!][!CR!]
            [!ENDLOOP!]
            [!ENDINDENT!]
        };
    [!ENDSELECT!]
    [!ENDINDENT!]
[!ENDIF!]

/*==================================================================================================*/
/**
* @brief          Configuration of FlexCan controller
* @details        Configuration of FlexCan controller
*
*/
[!VAR "LoopVar"="0"!]
[!SELECT "CanConfigSet"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    [!LOOP "CanController/*"!]
        [!VAR "MASK_COUNT2"="num:i(count(CanControllerBaudrateConfig/*))"!]
        [!VAR "END_COMMA2"="0"!]
        [!INDENT "0"!]
        /* Compiler_Warning: this warning due to behavior of compiler depend on configs. */
        static CONST(Can_43_FLEXCAN_Static_ControllerBaudrateConfigType, CAN_CONST) ControllerBaudrateCfgSet[!"$CSET_NR"!]_PC_[!"CanControllerId"!][CAN_43_FLEXCAN_CFGSET[!"num:i($CSET_NR)"!]_MAX_BAUDRATE_FC_[!"substring-after(CanHwChannel,'FlexCAN_')"!]_[!"@index"!]] = 
        {
            [!INDENT "4"!]
            [!LOOP "CanControllerBaudrateConfig/*"!][!VAR "END_COMMA2"="$END_COMMA2 + 1"!]
                [!IF "../../CanControllerActivation = 'true'"!]
                    /* Configuration for CanController ID[!"../../CanControllerId"!] == [!"../../CanHwChannel"!] */
                    {
                        [!INDENT "8"!]
                        /* ===== Control Register - CTRL ===== */
                        (uint32)(
                                    [!INDENT "20"!]
                                    /* CTRL[LPB] - Loop-back mode */
                                    ([!IF "../../CanLoopBackMode = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LPB_SHIFT_U8) |
                                    /* CTRL[SMP] - Sampling mode */
                                    ([!IF "../../CanTrippleSamplingEnable = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_SMP_SHIFT_U8) |
                                    /* CTRL[BOFF_REC] - Bus off recovery */
                                    ([!IF "../../CanAutoBusOffRecovery = 'true'"!](uint32)0[!ELSE!](uint32)1[!ENDIF!] << FLEXCAN_CTRL_BOFFREC_SHIFT_U8) |
                                    /* CTRL[LBUF] - Lowest Buffer Transmitted First */
                                    ([!IF "../../CanLowestBuffTransmitFirst = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LBUF_SHIFT_U8) |
                                    /* CTRL[LOM] - Listen only mode */
                                    ([!IF "../../CanListenOnlyMode = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LOM_SHIFT_U8)
                                    [!IF "ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON'"!]
                                                [!IF "../../CanClockFromBus = 'true'"!]
                                                    | ((uint32)1 << FLEXCAN_CTRL_CLKSRC_SHIFT_U8)
                                                [!ENDIF!]
                                            [!ENDIF!]
                                    [!ENDINDENT!]
                        [!WS "9"!]) 
                        #if (CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON)
                        [!IF "../../CanClockFromBus = 'true'"!]
                            [!IF "../../../../../CanGeneral/CanEnableDualClockMode = 'true'"!]
                                /* ===== Control Register Alternate - CTRL ===== */
                                /* CTRL[LPB] - Loop-back mode */
                                ,(uint32)(
                                            [!INDENT "20"!]
                                            ([!IF "../../CanLoopBackMode = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LPB_SHIFT_U8) |
                                            /* CTRL[SMP] - Sampling mode */
                                            ([!IF "../../CanTrippleSamplingEnable = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_SMP_SHIFT_U8) |
                                            /* CTRL[BOFF_REC] - Bus off recovery */
                                            ([!IF "../../CanAutoBusOffRecovery = 'true'"!](uint32)0[!ELSE!](uint32)1[!ENDIF!] << FLEXCAN_CTRL_BOFFREC_SHIFT_U8) |
                                            /* CTRL[LBUF] - Lowest Buffer Transmitted First */
                                            ([!IF "../../CanLowestBuffTransmitFirst = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LBUF_SHIFT_U8) |
                                            /* CTRL[LOM] - Listen only mode */
                                            ([!IF "../../CanListenOnlyMode = 'true'"!](uint32)1[!ELSE!](uint32)0[!ENDIF!] << FLEXCAN_CTRL_LOM_SHIFT_U8)
                                            [!IF "ecu:get('Can.CanConfig.CtrlClksrcAvailable')='STD_ON'"!]
                                                [!IF "../../CanClockFromBus = 'true'"!]
                                                    | ((uint32)1 << FLEXCAN_CTRL_CLKSRC_SHIFT_U8)
                                                [!ENDIF!]
                                            [!ENDIF!]
                                            [!ENDINDENT!]
                                [!WS "9"!])
                            [!ELSE!]
                                ,0U
                            [!ENDIF!]
                        [!ELSE!]
                            ,0U
                        [!ENDIF!]
                        #endif /* CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON */
                        [!ENDINDENT!]
                    }[!IF "$END_COMMA2 < $MASK_COUNT2"!],[!ENDIF!]
                    [!CR!] 
                [!ELSE!]
                    {
                        [!INDENT "8"!]
                        /* [!"../../CanHwChannel"!] ControlRegister Default Configuration: 125 Kbps BaudRate with Oscillator clock 8MHz as Clock source and TimeQuantum of 1000ns. */
                        /* ===== Control Register - CTRL ===== */
                        (uint32)(
                                    [!INDENT "20"!]
                                    /* CTRL[LPB] - Loop-back mode */
                                    ((uint32)0 << FLEXCAN_CTRL_LPB_SHIFT_U8) |
                                    /* CTRL[SMP] - Sampling mode */
                                    ((uint32)0 << FLEXCAN_CTRL_SMP_SHIFT_U8) |
                                    /* CTRL[BOFF_REC] - Bus off recovery */
                                    ((uint32)1 << FLEXCAN_CTRL_BOFFREC_SHIFT_U8) |
                                    /* CTRL[LBUF]  - Lowest Buffer Transmitted First */
                                    ((uint32)0 << FLEXCAN_CTRL_LBUF_SHIFT_U8) |
                                    /* CTRL[LOM] - Listen only mode */
                                    ((uint32)0 << FLEXCAN_CTRL_LOM_SHIFT_U8)
                                    [!ENDINDENT!]
                        [!WS "9"!])
                        #if (CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON)
                        /* ===== Control Register Alternate - CTRL ===== */
                        ,(uint32)(
                                    [!INDENT "20"!]
                                    /* CTRL[LPB] - Loop-back mode */
                                    ((uint32)0 << FLEXCAN_CTRL_LPB_SHIFT_U8) |
                                    /* CTRL[SMP] - Sampling mode */
                                    ((uint32)0 << FLEXCAN_CTRL_SMP_SHIFT_U8) |
                                    /* CTRL[BOFF_REC] - Bus off recovery */
                                    ((uint32)1 << FLEXCAN_CTRL_BOFFREC_SHIFT_U8) |
                                    /* CTRL[LBUF]  - Lowest Buffer Transmitted First */
                                    ((uint32)0 << FLEXCAN_CTRL_LBUF_SHIFT_U8) |
                                    /* CTRL[LOM] - Listen only mode */
                                    ((uint32)0 << FLEXCAN_CTRL_LOM_SHIFT_U8)
                                    [!ENDINDENT!]
                        [!WS "9"!])
                        #endif /* CAN_43_FLEXCAN_DUAL_CLOCK_MODE == STD_ON */
                        [!ENDINDENT!]
                    }[!IF "$END_COMMA2 < $MASK_COUNT2"!],[!ENDIF!][!CR!]
                    [!CR!]
                [!ENDIF!]
            [!ENDLOOP!]
            [!ENDINDENT!]
        };
        [!CR!]
        [!ENDINDENT!]
    [!ENDLOOP!]
[!ENDSELECT!]

/*==================================================================================================*/
/**
* @brief          Description of individual FlexCan controllers on chip
* @details        Description of individual FlexCan controllers on chip
*
*/
[!VAR "LoopVar"="0"!]
[!SELECT "CanConfigSet"!]
    [!INDENT "0"!]
    [!VAR "CSET_NR" = "num:i(0)"!]
    static CONST(CanStatic_43_FLEXCAN_ControlerDescriptorType, CAN_CONST) CanStatic_43_FLEXCAN_ControlerDescriptors[CAN_43_FLEXCAN_MAXCONTROLLERCOUNT] =
    {
        [!INDENT "4"!]
        [!VAR "MASK_COUNT4"="num:i(count(CanController/*))"!]
        [!VAR "END_COMMA4"="0"!]
        [!VAR "tableidcount" = "0"!]
        [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
            /* ControlerDescriptor of CanController_[!"node:value(CanControllerId)"!] */
            {
                [!INDENT "8"!]
                [!IF "CanControllerActivation = 'true'"!]
                    /* Can Controller Offset on chip: Can_A=offset 0, Can_B=offset 1, .. -u8ControllerOffset */
                    [!IF "CanControllerActivation = 'true'"!]
                        (uint8)FLEXCAN_[!"substring-after(CanHwChannel,'FlexCAN_')"!]_OFFSET,
                    [!ELSE!]
                        (uint8)CAN_43_FLEXCAN_NULL_OFFSET,
                    [!ENDIF!]

                    /* pControllerBaudrateConfigsPtr - pControllerBaudrateConfigsPtr */
                    ControllerBaudrateCfgSet[!"$CSET_NR"!]_PC_[!"CanControllerId"!],

                    #if (CAN_43_FLEXCAN_ERROR_NOTIFICATION_ENABLE == STD_ON)
                    /* Pointer to Error INTERRUPT notification function (ESR[ERR_INT]). - Can_ErrorNotification */
                    [!IF "(CanErrorControllerNotifEn = 'true') and (normalize-space(CanErrorControllerNotification) != 'NULL_PTR')"!]
                        [!"normalize-space(CanErrorControllerNotification)"!],
                    [!ELSE!]
                        NULL_PTR,
                    [!ENDIF!]  
                    #endif

                    /* Maximum MBs supported for this controller. - u8NumberOfMB */
                    (uint8)[!"normalize-space(ecu:get(concat('Can.CanConfigSet.',CanHwChannel)))"!]U,
                    
                    [!IF "(node:value(../../../CanGeneral/CanPublicIcomSupport)='true') and (ecu:get('Can.CanConfigSet.CanPretendedNetworking')='STD_ON')"!]
                    /* ===== Pretended Network Support ===== */
                    #if (CAN_43_FLEXCAN_PUBLIC_ICOM_SUPPORT == STD_ON)
                        [!IF "CanControllerIcomSupported = 'true'"!]
                            (boolean)TRUE,
                        [!ELSE!]
                            (boolean)FALSE,
                        [!ENDIF!]
                    #endif
                    [!ENDIF!]
                    /* ===== Controller Options ===== */
                    (uint32)(
                                [!INDENT "20"!]
                                [!IF "CanBusoffProcessing = 'POLLING'"!]
                                    CAN_CONTROLLERCONFIG_BOPOL_EN_U32 | /* BusOffPoll Enabled */
                                [!ELSE!]
                                    /* BusOff select by INTERRUPT */
                                [!ENDIF!]
                                0U
                                [!ENDINDENT!]
                    [!WS "9"!])
                [!ELSE!]
                    /* Can Controller Offset on chip: Can_A=offset 0, Can_B=offset 1, .. -u8ControllerOffset */
                    (uint8)FLEXCAN_NULL_OFFSET_U8,
                    /* pControllerBaudrateConfigsPtr - pControllerBaudrateConfigsPtr */
                    ControllerBaudrateCfgSet[!"$CSET_NR"!]_PC_[!"CanControllerId"!],
                #if (CAN_43_FLEXCAN_ERROR_NOTIFICATION_ENABLE == STD_ON)
                    /* Pointer to Error INTERRUPT notification function (ESR[ERR_INT]). - Can_ErrorNotification */             
                    NULL_PTR,
                #endif
                    /* Maximum MBs supported for this controller. - u8NumberOfMB */
                    (uint8)[!"normalize-space(ecu:get(concat('Can.CanConfigSet.',CanHwChannel)))"!]U,

                    [!IF "(node:value(../../../CanGeneral/CanPublicIcomSupport)='true') and (ecu:get('Can.CanConfigSet.CanPretendedNetworking')='STD_ON')"!]
                        #if (CAN_43_FLEXCAN_PUBLIC_ICOM_SUPPORT == STD_ON)
                            (boolean)FALSE,
                        #endif
                    [!ENDIF!]
                    /* ===== Controller Options ===== */
                    (uint32)(0U)
                [!ENDIF!]
                [!ENDINDENT!]
            }[!//
            [!VAR "END_COMMA4"="$END_COMMA4 + 1"!][!//
            [!IF "$END_COMMA4 < $MASK_COUNT4"!][!//
                , /* ControlerDescriptors CanController_[!"node:value(CanControllerId)"!] end */
            [!ENDIF!]
            [!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
    [!ENDINDENT!]
[!ENDSELECT!]
/*==================================================================================================*/
/**
* @brief          Top level structure containing all Can driver configurations
* @details        Top level structure containing all Can driver configurations
*
*/
[!VAR "LoopVar"="0"!]
[!SELECT "CanConfigSet"!]
    [!INDENT "0"!]
    /* @violates @ref Can_43_FLEXCAN_Cfg_c_REF_4 MISRA 2012 Advisory Rule 8.9 */
    CONST(CanStatic_43_FLEXCAN_ConfigType, CAN_CONST) CanStatic_43_FLEXCAN_ConfigSet =
    {
        [!INDENT "4"!]
        /* Number of CAN controllers configured - u8ControllersConfigured*/
        (uint8) [!"num:i(count(CanController/*))"!]U,
        /* FlexCAN controller description - ControlerDescriptors*/
        CanStatic_43_FLEXCAN_ControlerDescriptors,
        /*Maximum Object IDs configured - u32CanMaxObjectId*/
        (uint32)[!"num:i(count(CanHardwareObject/*))"!]U
        [!IF "(../CanGeneral/CanPublicIcomSupport  = 'true') and (ecu:get('Can.CanConfigSet.CanPretendedNetworking')='STD_ON')"!]
            /*Number of CanIcomConfig: u8NumCanIcomConfigs */ 
            ,[!"num:i(count(CanIcom/CanIcomConfig/*))"!]U
            /*Pointer to CanIcomCofig - pCanIcomConfigs*/
            ,&Can_PnConfig[0U]
        [!ENDIF!]
        [!ENDINDENT!]
    };
    [!ENDINDENT!]
[!ENDSELECT!]

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

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

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


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

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

/*
@file  Can_PBcfg.c
*/
#define CAN_43_FLEXCAN_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/* @violates @ref Can_43_FLEXCAN_Cfg_c_REF_1 MISRA 2012 Required Directive 4.10 */
/* @violates @ref Can_43_FLEXCAN_Cfg_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_43_FLEXCAN_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */
