[!AUTOSPACING!]
/**
*   @file    Can_Cfg.c
*   @version 1.0.0
*
*   @brief   AUTOSAR Can - module interface
*   @details Configuration Structures for PreCompile.
*
*   @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_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_Cfg_c_REF_2
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
*
* @section Can_Cfg_c_REF_3
* 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 in various parts of the code.
*
*/
/*==================================================================================================
*                                        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"

/**
* @file           Can_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_VersionCheck_Src.m"!][!//
[!ENDNOCODE!][!//

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/

#define CAN_VENDOR_ID_PCCFG_C                    43
#define CAN_AR_RELEASE_MAJOR_VERSION_PCCFG_C     4
#define CAN_AR_RELEASE_MINOR_VERSION_PCCFG_C     3
#define CAN_AR_RELEASE_REVISION_VERSION_PCCFG_C  1
#define CAN_SW_MAJOR_VERSION_PCCFG_C             1
#define CAN_SW_MINOR_VERSION_PCCFG_C             0
#define CAN_SW_PATCH_VERSION_PCCFG_C             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Can header file are of the same vendor */
#if (CAN_VENDOR_ID_PCCFG_C != CAN_VENDOR_ID)
    #error "Can_Cfg.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_PCCFG_C != CAN_AR_RELEASE_MAJOR_VERSION) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PCCFG_C != CAN_AR_RELEASE_MINOR_VERSION) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PCCFG_C != CAN_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Can_Cfg.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_PCCFG_C != CAN_SW_MAJOR_VERSION) || \
     (CAN_SW_MINOR_VERSION_PCCFG_C != CAN_SW_MINOR_VERSION) || \
     (CAN_SW_PATCH_VERSION_PCCFG_C != CAN_SW_PATCH_VERSION))
    #error "Software Version Numbers of Can_Cfg.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_PCCFG_C != CAN_IPW_VENDOR_ID_H)
    #error "Can_Cfg.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_PCCFG_C != CAN_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PCCFG_C != CAN_IPW_AR_RELEASE_MINOR_VERSION_H) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PCCFG_C != CAN_IPW_AR_RELEASE_REVISION_VERSION_H))
    #error "AutoSar Version Numbers of Can_Cfg.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_PCCFG_C != CAN_IPW_SW_MAJOR_VERSION_H) || \
     (CAN_SW_MINOR_VERSION_PCCFG_C != CAN_IPW_SW_MINOR_VERSION_H) || \
     (CAN_SW_PATCH_VERSION_PCCFG_C != CAN_IPW_SW_PATCH_VERSION_H))
    #error "Software Version Numbers of Can_Cfg.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_PCCFG_C != CAN_VENDOR_ID_REGM)
    #error "Can_Cfg.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_PCCFG_C != CAN_AR_RELEASE_MAJOR_VERSION_REGM) || \
     (CAN_AR_RELEASE_MINOR_VERSION_PCCFG_C != CAN_AR_RELEASE_MINOR_VERSION_REGM) || \
     (CAN_AR_RELEASE_REVISION_VERSION_PCCFG_C != CAN_AR_RELEASE_REVISION_VERSION_REGM))
    #error "AutoSar Version Numbers of Can_Cfg.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_PCCFG_C != CAN_SW_MAJOR_VERSION_REGM) || \
     (CAN_SW_MINOR_VERSION_PCCFG_C != CAN_SW_MINOR_VERSION_REGM) || \
     (CAN_SW_PATCH_VERSION_PCCFG_C != CAN_SW_PATCH_VERSION_REGM))
    #error "Software Version Numbers of Can_Cfg.c and Reg_eSys_MCan.h are different"
#endif

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

[!INDENT "0"!]
/*==================================================================================================
*                                   GLOBAL FUNCTION PROTOTYPES
==================================================================================================*/
/**
* @brief    Prototype of User Notifications
*/
[!NOCODE!]
[!INCLUDE "Can_SourceClock.m"!]
[!INCLUDE "Can_NotifyCheck_Src.m"!]
[!CALL "CanErrorControllerNotification_PC"!]
[!CALL "CanMRAFNotification_PC"!]
[!ENDNOCODE!]
/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/


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


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

/**
* @brief          Description of static configuration of individual Mcan controllers on chip
* @details        Description of static configuration of individual Mcan controllers on chip
*
*/
[!SELECT "CanConfigSet"!]
    static CONST(CanStatic_ControlerDescriptorType, CAN_CONST) CanStatic_ControlerDescriptors[CAN_MAXCONTROLLERCOUNT] =
    {
        [!INDENT "4"!]
        [!VAR "CanCtrlCfg"="num:i(count(CanController/*))"!]
        [!LOOP "node:order(CanController/*,'node:value(CanControllerId)')"!]
            /* Static Controler Descriptors of [!"@name"!] */
            {
                [!INDENT "8"!]
                    [!IF "CanControllerActivation = 'true'"!]
                            /* Controller Hardware Offset: [!"CanHwChannel"!] */
                            /* (uint8)[!"substring-after(CanHwChannel,'MCAN_')"!]U, */
                            [!IF "CanHwChannel = 'MCAN_1'"!]
                                0U,
                            [!ELSE!]
                                1U,
                            [!ENDIF!]
                        #if (CAN_SUPPORT_MRAF_EVENT == STD_ON)
                            /* Pointer to MRAF notification function */
                            [!IF "normalize-space(CanMRAFNotification) != 'NULL_PTR'"!]
                                &[!"normalize-space(CanMRAFNotification)"!],
                            [!ELSE!]
                                NULL_PTR,
                            [!ENDIF!]
                        #endif
                        #if (CAN_ERROR_NOTIFICATION_ENABLE == STD_ON)
                            /* Pointer to Error interrupt notification function */
                            [!IF "(CanErrorControllerNotifEn = 'true') and (normalize-space(CanErrorControllerNotification) != 'NULL_PTR')"!]
                                &[!"normalize-space(CanErrorControllerNotification)"!],
                            [!ELSE!]
                                NULL_PTR,
                            [!ENDIF!]
                        #endif
                        #if (CAN_PUBLIC_ICOM_SUPPORT == STD_ON)
                            /* Pretended Networking */
                            [!IF "CanControllerIcomSupported = 'true'"!]
                                (boolean)TRUE,
                            [!ELSE!]
                                (boolean)FALSE,
                            [!ENDIF!]
                        #endif
                            /* Controller Option */
                            (uint32)(
                                [!INDENT "12"!]
                                    [!IF "CanBusMonitoringMode = 'true'"!]
                                        /* This setting defines whether the integrated low-pass filter is applied to protect the Rx CAN input from spurious wake up. */
                                        CAN_CONTROLLERCONFIG_CCCR_MON_EN_U32 |
                                    [!ENDIF!]
                                    [!IF "CanASMMode = 'true' "!]
                                        /* Software BusOff Recovery */
                                        CAN_CONTROLLERCONFIG_CCCR_ASM_EN_U32 |
                                    [!ENDIF!]
                                    [!IF "CanTestEnableMode = 'true' "!]
                                        /* Can Test Mode Enabled */
                                        CAN_CONTROLLERCONFIG_CCCR_TEST_EN_U32 |
                                    [!ENDIF!]
                                #if (CAN_SUPPORT_MRAF_EVENT == STD_ON)
                                    [!IF "CanSupportMRAFprocessing = 'POLLING'"!]
                                        /* MRAF Poll Enabled */
                                        CAN_CONTROLLERCONFIG_MRAFPOL_EN_U32 |
                                    [!ENDIF!]
                                #endif
                                    [!IF "(CanErrorControllerNotifEn = 'true') and (normalize-space(CanErrorControllerNotification) != 'NULL_PTR')"!]
                                        /* Can Controller Error Notification handling enabled */
                                        CAN_CONTROLLERCONFIG_ERR_EN_U32 |
                                    [!ENDIF!]
                                    [!IF "CanRxProcessing = 'POLLING'"!]
                                        /* RxPoll Enabled */
                                        CAN_CONTROLLERCONFIG_RXPOL_EN_U32 |
                                    [!ENDIF!]
                                    [!IF "CanBusoffProcessing = 'POLLING'"!]
                                        /* BusOffPoll Enabled */
                                        CAN_CONTROLLERCONFIG_BOPOL_EN_U32 |
                                    [!ENDIF!]
                                        0U
                                [!ENDINDENT!]
                            )
                    [!ELSE!]
                        /* [!"@name"!] was inactive */
                            /* Controller Hardware Offset */
                            MCAN_NULL_OFFSET_U8,
                        #if (CAN_SUPPORT_MRAF_EVENT == STD_ON)
                            NULL_PTR,
                        #endif
                        #if (CAN_ERROR_NOTIFICATION_ENABLE == STD_ON)
                            NULL_PTR,
                        #endif
                        #if (CAN_PUBLIC_ICOM_SUPPORT == STD_ON)
                            /* Pretended Networking */
                            (boolean)FALSE,
                        #endif
                            /* Controller Option */
                            (uint32)0U
                    [!ENDIF!]
                [!ENDINDENT!]               
            }[!IF "CanControllerId < ($CanCtrlCfg - 1)"!],[!ENDIF!][!CR!]
        [!ENDLOOP!]
        [!ENDINDENT!]
    };
[!ENDSELECT!]
/*==================================================================================================
*                                      LOCAL VARIABLES
==================================================================================================*/

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


/**
* @brief          Top level structure containing all static Can driver configurations
* @details        Top level structure containing all static Can driver configurations
*
*/
[!SELECT "CanConfigSet"!]
    /* @violates @ref Can_Cfg_c_REF_3 MISRA 2012 Advisory Rule 8.9 */
    CONST(CanStatic_ConfigType, CAN_CONST) CanStatic_ConfigSet =
    {
        [!INDENT "4"!]
            /* Number of CAN controllers configured */
            (uint8)[!"num:i(count(CanController/*))"!]U,
            /* Pointer to the Static Controler Descriptors*/
            CanStatic_ControlerDescriptors,
            /* Maximum Object IDs configured */
            (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!]
    };
[!ENDSELECT!]
/*==================================================================================================
*                                      GLOBAL VARIABLES
==================================================================================================*/

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


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

/*==================================================================================================
*                                       GLOBAL FUNCTIONS
==================================================================================================*/
[!ENDINDENT!]
#define CAN_STOP_SEC_CONST_UNSPECIFIED
/* @violates @ref Can_Cfg_c_REF_1 MISRA 2012 Required Directive 4.10 */
/* @violates @ref Can_Cfg_c_REF_2 MISRA 2012 Advisory Rule 20.1 */
#include "Can_MemMap.h"

#ifdef __cplusplus
}
#endif

/** @} */
