/**
*   @file    Can_Cfg.h
*   @implements Can_Cfg.h_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Can - module interface
*   @details Configuration settings generated by user settings.
*
*   @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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/
/*
@brief   (CAN023) The consistency of the configuration must be checked by the configuration tool(s).
@brief   (CAN022) The code configurator of the Can module is CAN controller specific.
         If the CAN controller is sited on-chip, the code generation tool for the Can module is Controller specific.
         If the CAN controller is an external device the generation tool must not be Controller specific.
@brief   (CAN024) The valid values that can be configured are hardware dependent.
         Therefore the rules and constraints can't be given in the standard.
         The configuration tool is responsible to do a static configuration checking, also regarding dependencies between modules (i.e. Port driver, MCU driver etc.)
*/
/*
* @file    Can_Cfg.h
*/

#ifndef CAN_CFG_H
#define CAN_CFG_H

#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_h_REF_1
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
*
* @section Can_Cfg_h_REF_2
* Violates MISRA 2012 Advisory Rule 4.9, A function should be used in preference to a function-like macro where they are interchangeable.
*
*/

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

[!AUTOSPACING!]
[!NOCODE!][!//
[!INCLUDE "Can_VersionCheck_Inc.m"!][!//
[!ENDNOCODE!][!//

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/*
* @file           Can_Cfg.h
*/
#define CAN_VENDOR_ID_CFG_H                         43
#define CAN_MODULE_ID_CFG_H                         80
#define CAN_AR_RELEASE_MAJOR_VERSION_CFG_H          4
#define CAN_AR_RELEASE_MINOR_VERSION_CFG_H          3
#define CAN_AR_RELEASE_REVISION_VERSION_CFG_H       1
#define CAN_SW_MAJOR_VERSION_CFG_H                  1
#define CAN_SW_MINOR_VERSION_CFG_H                  0
#define CAN_SW_PATCH_VERSION_CFG_H                  0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Std_Types.h file are of the same Autosar version */
    #if ((CAN_AR_RELEASE_MAJOR_VERSION_CFG_H != STD_AR_RELEASE_MAJOR_VERSION) || \
         (CAN_AR_RELEASE_MINOR_VERSION_CFG_H != STD_AR_RELEASE_MINOR_VERSION)    \
        )
        #error "AutoSar Version Numbers of Can_Cfg.h and Std_Types.h are different"
    #endif
#endif


/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/
[!NOCODE!]
/* Export Driver Configuration Macro */
[!MACRO "CanExportDriverConfiguration"!]
    [!NOCODE!]
        [!VAR "configName" = "as:name(CanConfigSet)"!][!//
        [!CODE!]#define CAN_CONF_PB \[!ENDCODE!][!CR!]
        [!IF "var:defined('postBuildVariant')"!][!//
            [!VAR "variantIndex"="0"!]
            [!VAR "variantNumber"="variant:size()"!]
            [!LOOP "variant:all()"!][!VAR "variantIndex"="$variantIndex + 1"!]
                [!CODE!][!WS "4"!]extern CONST(Can_ConfigType, CAN_CONST) Can_[!"$configName"!]_[!"."!];[!IF "$variantIndex < $variantNumber"!]\[!ENDIF!][!CR!][!ENDCODE!]
            [!ENDLOOP!]
        [!ELSE!]
            [!CODE!][!WS "4"!]extern CONST(Can_ConfigType, CAN_CONST) Can_[!"$configName"!];[!CR!][!ENDCODE!]
        [!ENDIF!]
    [!ENDNOCODE!]
[!ENDMACRO!]

/* Checking the arrangement of HRH and HTH. If HRH and HTH have already configured in configuration, they are must arrange in order as follow HRH first then HTH */
[!SELECT "CanConfigSet"!]
    [!VAR "MaxObjectIdForReceiveHO" = "0"!]
    [!LOOP "CanHardwareObject/*"!]
        [!IF "CanObjectType = 'RECEIVE'"!]
            [!IF "$MaxObjectIdForReceiveHO < CanObjectId"!]
                [!VAR "MaxObjectIdForReceiveHO" = "CanObjectId"!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDLOOP!]
    [!LOOP "CanHardwareObject/*"!]
        [!IF "CanObjectType = 'TRANSMIT'"!]
            [!IF "$MaxObjectIdForReceiveHO > CanObjectId"!]
                [!ERROR!]
                    The CanHardwareObject with CanObjectType is "RECEIVE" must be arranged before "TRANSMIT"
                [!ENDERROR!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]

/* Checking the configuration has configured at least one HRH or HTH polling */
[!VAR "tx_pol_en" = "0"!]
[!VAR "rx_pol_en" = "0"!]
[!VAR "int_en" = "0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "CanHardwareObject/*"!]
        [!IF "(((node:exists(CanHardwareObjectUsesPolling) and node:value(CanHardwareObjectUsesPolling) = 'true') or node:ref(CanControllerRef)/CanRxProcessing = 'POLLING') and node:value(CanObjectType) = 'RECEIVE')"!]
            [!VAR "rx_pol_en" = "1"!]
        [!ELSEIF "(((node:exists(CanHardwareObjectUsesPolling) and node:value(CanHardwareObjectUsesPolling) = 'true') or node:ref(CanControllerRef)/CanTxProcessing = 'POLLING') and node:value(CanObjectType) = 'TRANSMIT')"!]
            [!VAR "tx_pol_en" = "1"!]
        [!ELSE!]
            [!VAR "int_en" = "1"!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]

/* Checking the configuration has configured interrupt */
[!VAR "Wakeup_pol" = "0"!]
[!VAR "Busoff_pol" = "0"!]
[!VAR "MRAF_pol" = "0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!IF "(CanWakeupProcessing = 'INTERRUPT') or (CanBusoffProcessing = 'INTERRUPT') or (CanSupportMRAFprocessing = 'INTERRUPT') or (CanErrorControllerNotifEn = 'true')"!]
            [!VAR "int_en" = "1"!]
        [!ENDIF!]
        [!IF "CanBusoffProcessing = 'POLLING'"!]
            [!VAR "Busoff_pol" = "1"!]
        [!ENDIF!]
        [!IF "CanWakeupSupport = 'true' and CanWakeupProcessing = 'POLLING'"!]
            [!VAR "Wakeup_pol" = "1"!]
        [!ENDIF!]
        [!IF "../../../../CanGeneral/CanSupportMRAFEvent = 'true' and CanSupportMRAFprocessing = 'POLLING'"!]
            [!VAR "MRAF_pol" = "1"!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]

/* Compute the highest of Tx Buffers configured for a controller in whole controller configured*/
[!VAR "MaxTxMBUsed" = "1"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "node:order(CanController/*, 'CanControllerId')"!]
        [!IF "CanControllerActivation = 'true'"!]
            [!VAR "maxmbcount" = "0"!]
            [!VAR "CtrlId" = "CanControllerId"!]
            [!LOOP "../../CanHardwareObject/*"!]
                [!IF "(CanObjectType = 'TRANSMIT') and (node:ref(CanControllerRef)/CanControllerId = $CtrlId)"!]
                    [!VAR "maxmbcount" = "$maxmbcount + CanHwObjectCount"!]
                [!ENDIF!]
            [!ENDLOOP!]
            [!IF "$MaxTxMBUsed < $maxmbcount"!]
                [!VAR "MaxTxMBUsed" = "$maxmbcount"!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDNOCODE!]

/**
* @brief          Expose MCan driver configurations
*
*/
[!IF "((IMPLEMENTATION_CONFIG_VARIANT != 'VariantPostBuild') and (variant:size()>1)) or (IMPLEMENTATION_CONFIG_VARIANT = 'VariantPostBuild')"!]
    [!CALL "CanExportDriverConfiguration"!]
[!ENDIF!]

/*
* @brief          Extended identifiers.
* @details        Extended identifiers.
                   - (STD_ON)  - if at least one extended identifier is used.
                   - (STD_OFF) - if no extended identifiers are used at all
                  If no extended identifiers are used then the IDs and MASKs can be stored in uint16 rather than uint32.
*
*/
#define CAN_EXTENDEDID [!WS "1"!][!IF "CanGeneral/CanExtendedIDSupport = 'true'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]


/*
* @brief          Instance # of the driver - used for Det_ReportError().
* @details        Instance # of the driver - used for Det_ReportError().
*
*/
#define CAN_INSTANCE [!WS "1"!][!"num:i(CanGeneral/CanIndex)"!]U

[!NOCODE!]
[!VAR "fifo_overflow"="0"!]
[!VAR "fifo_warning_notification"="0"!]
[!LOOP "CanConfigSet/CanController/*"!]
    [!VAR "fifo_overflow"="num:i($fifo_overflow + count(CanRxFifo/*))"!]                
[!ENDLOOP!]

[!LOOP "CanConfigSet/CanController/*/CanRxFifo/*"!]
    [!LOOP "CanFifoWatermask"!]
        [!IF "node:value(CanFifoWatermarkEnable) = 'true' "!]
            [!VAR "fifo_warning_notification"="$fifo_warning_notification +1"!]            
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDLOOP!]
[!ENDNOCODE!]

/*
* @brief          Warning notification enabled or disabled on all configurations. Disable at precompile Fifo Warning for code optimization.
* @details        Warning notification enabled or disabled on all configurations. Disable at precompile Fifo Warning for code optimization.
*
*/

[!IF "$fifo_warning_notification !=0"!]
    #define CAN_FIFO_WARNING_NOTIFICATION  (STD_ON)
[!ELSE!]
    #define CAN_FIFO_WARNING_NOTIFICATION  (STD_OFF)
[!ENDIF!]

/*
* @brief          Support for Rx Fifo
* @details        Support for Rx Fifo - If at least one controller supports RxFifo, then this define is set to STD_ON.
*                 This define is global for the entire hardware unit (all controllers). Every controller has particular
*                 configuration for Rx Fifo (see Can_ControllerConfigType structure).
*
*/
[!IF "$fifo_overflow !=0"!]
    #define CAN_RXFIFO_ENABLE  (STD_ON)
[!ELSE!]
    #define CAN_RXFIFO_ENABLE  (STD_OFF)
[!ENDIF!]

/*
* @brief          Maximum possible controllers per specific derivative.
* @details        Maximum possible controllers per specific derivative.
*
*/
#define CAN_MAXCTRL_SUPPORTED [!WS "1"!][!"num:i(ecu:get('MCan.CanConfigSet.CanController'))"!]U



[!NOCODE!]
[!VAR "intmraf_en_a"="0"!]
[!VAR "intmraf_en_b"="0"!]
[!VAR "pol_en"="0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!IF "CanSupportMRAFprocessing = 'POLLING'"!]
                [!VAR "pol_en" = "1"!]
        [!ELSE!]
            [!IF "CanHwChannel = 'MCAN_1'"!]
                [!IF "CanSupportMRAFprocessing = 'INTERRUPT'"!]
                    [!VAR "intmraf_en_a" = "1"!]
                [!ENDIF!]
            [!ENDIF!]
            [!IF "CanHwChannel = 'MCAN_2'"!]
                [!IF "CanSupportMRAFprocessing = 'INTERRUPT'"!]
                    [!VAR "intmraf_en_b" = "1"!]
                [!ENDIF!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!][!ENDNOCODE!]


#define CAN_MRAFINT_SUPPORTED   [!WS "1"!][!IF "($intmraf_en_a + $intmraf_en_b) >= 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/*
* @brief          Maximum number of MB Filters configured.
* @details        Maximum number of MB Filters configured.
*
*/
[!LOOP "CanConfigSet/*"!]
    #define CAN_MAXFILTERCOUNT_[!"@index"!] [!WS "1"!][!"num:i(num:i(count(CanController/*/CanRxFilterElement/*)) + num:i(count(CanController/*/CanFilterMask/*)))"!]U[!CR!]
[!ENDLOOP!]

/*
* @brief          Maximum number of Filters configured.
* @details        Maximum number of Filters configured.
*
*/
[!SELECT "CanConfigSet"!]
    [!VAR "TableIdCount" = "num:i(count(CanHardwareObject/*[CanObjectType='RECEIVE']))"!]
    [!LOOP "CanController/*"!]    
    [!VAR "TableIdCount" = "$TableIdCount + num:i(count(CanRxFilterElement/*))"!]
    [!ENDLOOP!]
    [!IF "$TableIdCount != 0"!]
        #define CAN_MAX_RX_FILTER_TABLE [!WS "4"!][!"num:i($TableIdCount)"!]U[!CR!]
    [!ENDIF!]
[!ENDSELECT!]


[!NOCODE!]
[!VAR "interror_en_a"="0"!]
[!VAR "interror_en_b"="0"!]
[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!IF "CanHwChannel = 'MCAN_1'"!]
            [!IF "CanErrorControllerNotifEn = 'true'"!]
                [!VAR "interror_en_a" = "1"!]
            [!ENDIF!]
        [!ENDIF!]
        [!IF "CanHwChannel = 'MCAN_2'"!]
            [!IF "CanErrorControllerNotifEn = 'true'"!]
                [!VAR "interror_en_b" = "1"!]
            [!ENDIF!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]
[!ENDNOCODE!]
[!IF "$interror_en_a = 1 or $interror_en_b = 1"!]
    #define CAN_ERROR_NOTIFICATION_ENABLE  (STD_ON)
[!ELSE!]
    #define CAN_ERROR_NOTIFICATION_ENABLE  (STD_OFF)
[!ENDIF!]


[!SELECT "CanConfigSet"!]
    [!LOOP "CanController/*"!]
        [!IF "CanHwChannel = 'MCAN_1'"!]
            /*
            * @brief          Index into the configuration structures.
            * @details        Index into the configuration structures.Indexes used for accessing the 'Can_ControlerDescriptorType' structure.
            *                 NOTE that index order from hardware (where CAN_A has always index 0, ..)
            *                 may not be the same with the order from the 'Can_ControlerDescriptorType' structure (where user can define controllers in any order).
            *                 Count also the number of controllers that have interrupts enabled.
            *
            */
            #define CAN_FCA_INDEX       ((uint8)[!"num:i(CanControllerId)"!]U)

            /*
            * @brief          Index into the hardware platform.
            * @details        Index into the hardware platform.Indexes used for accessing the 'Can_ControlerDescriptorType' structure.
            *
            */
            #define MCAN_1_OFFSET    ((uint8)0U)

            /*
            * @brief          RxFifo Functionality enabled/disabled. Used for interrupts mapping in Can_Irq.c file.
            * @details        RxFifo Functionality enabled/disabled. Used for interrupts mapping in Can_Irq.c file.
            *
            */

            /*
            * @brief          Error notification enabled/disabled.
            * @details        Enables/Disables the Error Controller Notification. Used for interrupts mapping in Can_Irq.c file.
            *
            */
            #define CAN_A_ERROR_NOTIFICATION_ENABLE  [!WS "1"!][!IF "CanErrorControllerNotifEn = 'true'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

        [!ELSEIF "CanHwChannel = 'MCAN_2'"!]
            /*
            * @brief          Index into the configuration structures.
            * @details        Index into the configuration structures.
            *
            */
            #define CAN_FCB_INDEX       ((uint8)[!"num:i(CanControllerId)"!]U)


            /*
            * @brief          Index into the hardware platform.
            * @details        Index into the hardware platform.
            *
            */
            #define MCAN_2_OFFSET    ((uint8)1U)
            /*
            * @brief          RxFifo Functionality enabled/disabled. Used for interrupts mapping in Can_Irq.c file.
            * @details        RxFifo Functionality enabled/disabled. Used for interrupts mapping in Can_Irq.c file.
            *
            */


            /*
            * @brief          Error notification enabled/disabled.
            * @details        Enables/Disables the Error Controller Notification. Used for interrupts mapping in Can_Irq.c file.
            *
            */
            #define CAN_B_ERROR_NOTIFICATION_ENABLE  [!WS "1"!][!IF "CanErrorControllerNotifEn = 'true'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDSELECT!]





/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
[!INDENT "0"!]

/**
* @brief          Precompile Support.
* @details        VARIANT-PRE-COMPILE: Only pre-compile configuration parameters
*
*/
[!IF "IMPLEMENTATION_CONFIG_VARIANT = 'VariantPreCompile' and (variant:size()<=1)"!]
    #define CAN_PRECOMPILE_SUPPORT [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_PRECOMPILE_SUPPORT [!WS "4"!](STD_OFF)
[!ENDIF!]


/**
* @brief          Support for User Mode feature.
* @details        This parameter is enabled only in order to support the write access to some registers are protected in user mode.
*/
[!IF "CanGeneral/CanEnableUserModeSupport = 'true'"!]
    #define CAN_ENABLE_USER_MODE_SUPPORT [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_ENABLE_USER_MODE_SUPPORT [!WS "4"!](STD_OFF)
[!ENDIF!]

#ifndef MCAL_ENABLE_USER_MODE_SUPPORT
    #ifdef CAN_ENABLE_USER_MODE_SUPPORT
        #if (STD_ON == CAN_ENABLE_USER_MODE_SUPPORT)
            #error MCAL_ENABLE_USER_MODE_SUPPORT is not enabled. For running Can in user mode the MCAL_ENABLE_USER_MODE_SUPPORT needs to be defined
        #endif /* (STD_ON == CAN_ENABLE_USER_MODE_SUPPORT) */
    #endif /* ifndef CAN_ENABLE_USER_MODE_SUPPORT */
#endif /* ifndef MCAL_ENABLE_USER_MODE_SUPPORT */

/**
* @brief          Support for Special MB Abort API
* @details        Enable an additional API
*
*/
#define CAN_API_ENABLE_ABORT_MB [!WS "4"!][!SELECT "CanGeneral"!][!IF "node:exists(CanAbortApi) and CanAbortApi = 'true'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!ENDSELECT!][!CR!]

/**
* @brief            Support whether detect MRAF (Message RAM access Failture) 
*/
[!IF "CanGeneral/CanSupportMRAFEvent='true'"!]
    #define CAN_SUPPORT_MRAF_EVENT [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_SUPPORT_MRAF_EVENT [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Enable/Desable Lpdu Callout Function 
* @details        CanLPduReceiveCalloutFunction - This parameter sets the name of the LPDU callout.
*
*/
[!IF "node:exists(CanGeneral/CanLPduReceiveCalloutFunction) and (normalize-space(CanGeneral/CanLPduReceiveCalloutFunction) != 'NULL_PTR')"!]
    #define CAN_LPDU_NOTIFICATION_ENABLE [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_LPDU_NOTIFICATION_ENABLE [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Enable/Disable Can_SetBaudrate API support
* @details        If STD_ON the Can_SetBaudrate API shall be supported. Otherwise the API is not supported.
*
*/
[!IF "((node:exists(CanGeneral/CanSetBaudrateApi)) and (CanGeneral/CanSetBaudrateApi ='true'))"!]
    #define CAN_SET_BAUDRATE_API [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_SET_BAUDRATE_API [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Pretended Networking
* @details        (ECUC_Can_00483) Selects support of Pretended Network features in Can driver.
*
*/
[!IF "(CanGeneral/CanPublicIcomSupport='true') and (ecu:get('MCan.CanConfigSet.CanPretendedNetworking')='STD_ON')"!]
    #define CAN_PUBLIC_ICOM_SUPPORT [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_PUBLIC_ICOM_SUPPORT [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Enable Non-Autosar API for Dual-Clock support.
* @details        Enable Non-Autosar API for Dual-Clock support.
*                 This can be set to STD_ON only if it is activated from Resource file (Can.CanConfig.DualClockMode = STD_ON)
*
*/
[!IF "ecu:get('MCan.CanConfig.DualClockMode') = 'STD_ON' and (CanGeneral/CanEnableDualClockMode) = 'true'"!]
    #define CAN_DUAL_CLOCK_MODE [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_DUAL_CLOCK_MODE [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Error notification enabled/disabled.
* @details        Enables/Disables the Error Controller Notification. Used for INTERRUPTs mapping in Can_Irq.c file.
*
*/
[!IF "CanConfigSet/CanController/*/CanErrorControllerNotifEn = 'true'"!]
    #define CAN_ERROR_NOTIFICATION_ENABLE [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_ERROR_NOTIFICATION_ENABLE [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Set if Rx Fifo events (Warning/Overflow/FrameAvailable) are configured on the same int on INTC vector table.
* @details        Set if Rx Fifo events (Warning/Overflow/FrameAvailable) are configured on the same int on INTC vector table.
*                 Based on this define separate INTERRUPTs handlers or not will be used for the 3 events of the RxFifo.
*/
[!IF "ecu:get('MCan.CanConfigSet.RxFifoEventsUnified')='STD_ON'"!]
    #define CAN_RXFIFO_EVENT_UNIFIED [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_RXFIFO_EVENT_UNIFIED [!WS "4"!](STD_OFF)
[!ENDIF!]
/**
* @brief          Can FD enable/disable
* @details        Can FD enable/disable
*                 
*/
[!IF "ecu:get('MCan.CanConfigSet.CanFdEnable')='STD_ON' and node:exists(CanConfigSet/CanController/*/CanControllerBaudrateConfig/*/CanControllerFdBaudrateConfig)"!]
    #define CAN_FD_MODE_ENABLE [!WS "4"!](STD_ON)
    #define CAN_REAL_PAYLOAD_U8 [!WS "4"!]((uint8)[!"substring-before(substring-after(CanGeneral/MBDSR,'_'),'_')"!]U)
[!ELSE!]
    #define CAN_FD_MODE_ENABLE [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Switches the Development Error Detection and Notification ON or OFF.
* @details        Call the Development Error Tracer when DET is switched on and the Can module detects an error.
                  The detection of development errors is configurable (ON / OFF) at pre- compile time.
                  The switch CanDevErrorDetection (see chapter 10) shall activate or deactivate the detection of all development errors.
*
*/
[!IF "CanGeneral/CanDevErrorDetect = 'true'"!]
    #define CAN_DEV_ERROR_DETECT [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_DEV_ERROR_DETECT [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          Support for version info API
* @details        Switches the Can_GetVersionInfo() API ON or OFF.
*/
[!IF "CanGeneral/CanVersionInfoApi = 'true'"!]
    #define CAN_VERSION_INFO_API [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_VERSION_INFO_API [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief          The define in order to check the trigger transmit feature is enabled or disabled.
* @details        The define in order to check the trigger transmit feature is enabled or disabled.
*
*/
[!IF "num:i(count(CanConfigSet/CanHardwareObject/*[CanTriggerTransmitEnable = 'true'])) > 0"!]
    #define CAN_TRIGGER_TRANSMIT_EN (STD_ON)
[!ELSE!]
    #define CAN_TRIGGER_TRANSMIT_EN (STD_OFF)
[!ENDIF!]

/**
* @brief          Support for Multiplexed Transmision
* @details        MB set for Tx is put on bus from any TxMB that is available (free).
*                 (ECUC_Can_00095) The Can module shall allow that the functionality Multiplexed Transmission is statically configurable (ON | OFF) at pre-compile time.
*
*/
[!IF "CanGeneral/CanMultiplexedTransmission = 'true'"!]
    #define CAN_MULTIPLEXED_TRANSMISSION [!WS "4"!](STD_ON)
[!ELSE!]
    #define CAN_MULTIPLEXED_TRANSMISSION [!WS "4"!](STD_OFF)
[!ENDIF!]

/**
* @brief    Macro used to define the maximum of Can object IDs configured  .
*/
#define CAN_MAX_OBJECT_ID [!WS "4"!]([!"num:i(count(CanConfigSet/CanHardwareObject/*))"!]U)

/**
* @brief          Periods for cyclic call of Main function Mode
* @details        (ECUC_Can_00376) This parameter describes the period for cyclic call to Can_MainFunction_Mode. Unit is seconds.
*/
#define CAN_MAINFUNCTION_MODE_PERIOD   [!WS "4"!][!"num:i(CanGeneral/CanMainFunctionModePeriod)"!]U

/**
* @brief          Periods for cyclic call of Main function
* @details        (ECUC_Can_00484) This parameter describes the period for cyclic call to Can_MainFunction_Read or Can_MainFunction_Write depending on the referring item. Unit is seconds. 
*                 Different poll-cycles will be configurable if more than one CanMainFunctionPeriod is configured. 
*                 In this case multiple Can_MainFunction_Read() or Can_MainFunction_Write() will be provided by the CAN Driver module..
*
*/
[!IF "num:i(count(CanGeneral/CanMainFunctionRWPeriods/*)) = 1"!]
    #define CAN_MAINFUNCTION_PERIOD         ([!"CanGeneral/CanMainFunctionRWPeriods/*[1]/CanMainFunctionPeriod"!]F)
    [!IF "$rx_pol_en = 1"!]
        #define CAN_MAINFUNCTION_PERIOD_READ    ([!"CanGeneral/CanMainFunctionRWPeriods/*[1]/CanMainFunctionPeriod"!]F)
        #define CAN_MAINFUNCTION_MULTIPLE_READ  (STD_OFF)
    [!ENDIF!]
    [!IF "$tx_pol_en = 1"!]
        #define CAN_MAINFUNCTION_PERIOD_WRITE   ([!"CanGeneral/CanMainFunctionRWPeriods/*[1]/CanMainFunctionPeriod"!]F)  
        #define CAN_MAINFUNCTION_MULTIPLE_WRITE (STD_OFF)
    [!ENDIF!]
[!ELSE!]
    [!IF "$rx_pol_en = 1"!]
        #define CAN_MAINFUNCTION_MULTIPLE_READ   (STD_ON)
    [!ENDIF!]
    [!IF "$tx_pol_en = 1"!]
        #define CAN_MAINFUNCTION_MULTIPLE_WRITE   (STD_ON)
    [!ENDIF!]
    [!LOOP "CanGeneral/CanMainFunctionRWPeriods/*"!]
        #define CAN_MAINFUNCTION_PERIOD_[!"@index"!]       ([!"CanMainFunctionPeriod"!]F)
        [!IF "$rx_pol_en = 1"!]
            #define CAN_MAINFUNCTION_PERIOD_READ_[!"@index"!]       ([!"CanMainFunctionPeriod"!]F)
        [!ENDIF!]
        [!IF "$tx_pol_en = 1"!]
            #define CAN_MAINFUNCTION_PERIOD_WRITE_[!"@index"!]       ([!"CanMainFunctionPeriod"!]F)
        [!ENDIF!]
    [!ENDLOOP!]
[!ENDIF!]

[!IF "node:exists(CanGeneral/CanMainFunctionBusoffPeriod)"!]
/**
* @brief          Periods for cyclic call of Main function
* @details        (ECUC_Can_00355) CanMainFunctionBusoffPeriod - This parameter describes the period for cyclic call to Can_MainFunction_Busoff. Unit is seconds.
*/
#define CAN_MAINFUNCTION_PERIOD_BUSOFF  [!WS "4"!]([!"num:i(CanGeneral/CanMainFunctionBusoffPeriod)"!]F)
[!ENDIF!]

[!IF "node:exists(CanGeneral/CanMainFunctionWakeupPeriod)"!]
/**
* @brief          Periods for cyclic call of Main function
* @details        (ECUC_Can_00357) CanMainFunctionWakeupPeriod - This parameter describes the period for cyclic call to Can_MainFunction_Wakeup. Unit is seconds.
*
*/
#define CAN_MAINFUNCTION_PERIOD_WAKEUP  [!WS "4"!]([!"num:i(CanGeneral/CanMainFunctionWakeupPeriod)"!]F)
[!ENDIF!]

/**
* @brief          Maximum No. of supported controllers (vary according to Processor Family).
* @details        Maximum No. of supported controllers (vary according to Processor Family).
*/
#define CAN_MAXCONTROLLERCOUNT [!WS "4"!][!"num:i(count(CanConfigSet/CanController/*))"!]U
    
/**
* @brief          Symbolic Names generated for CanObjectId
*/
[!LOOP "node:order(CanConfigSet/CanHardwareObject/*, 'CanObjectId')"!]
    [!CODE!]#define [!"@name"!][!WS "4"!][!"num:i(CanObjectId)"!]U  /* [!"CanObjectType"!] object of Controller Id [!"node:ref(CanControllerRef)/CanControllerId"!] */[!ENDCODE!][!CR!]
[!ENDLOOP!]

/**
* @brief          Symbolic Names generated for CanControllerId
*/
[!LOOP "node:order(CanConfigSet/CanController/*, 'CanControllerId')"!]
    [!CODE!]#define [!"@name"!][!WS "4"!][!"num:i(CanControllerId)"!]U  /* [!"CanHwChannel"!] */[!ENDCODE!][!CR!]
[!ENDLOOP!]

[!IF "CanGeneral/CanAllowLoopAsCycle = 'true'"!]
/**
* @brief          Specifies the maximum time for blocking function until a timeout is detected (implement as loop cycles).
* @details        The Can module shall use the free running timer provided by the system service for timeout detection in case the hardware does not react
*                  in the expected time (hardware malfunction) to prevent endless loops.
*
*/
#define CAN_TIMEOUT_DURATION [!WS "4"!][!"num:i(CanGeneral/CanNumberOfTimeOutLoop)"!]U[!CR!]

/**
* @brief          Define timeout as loop
* @details        Define that timeout implemented as loop cycle
*
*/
#define CAN_TIMEOUT_AS_LOOP [!WS "4"!](STD_ON)

[!ELSE!]
/**
* @brief          Specifies the maximum time for blocking function until a timeout is detected (implement as second).
* @details        The Can module shall use the free running timer provided by the system service for timeout detection in case the hardware does not react
*                  in the expected time (hardware malfunction) to prevent endless loops.
*
*/
#define CAN_TIMEOUT_DURATION [!WS "4"!][!"CanGeneral/CanTimeoutDuration * 1000000000"!]F[!CR!]

    [!SELECT "node:ref(CanGeneral/CanOsCounterRef)"!]
/**
* @brief          Reference to OS counter
* @details        Define the OS counter used by Candriver
*
*/
#define CAN_TIMEOUT_COUNTER_NAME   [!"@name"!]

/**
* @brief          Wrap macro to convert TimeOut
* @details        Define the ns time specify by 1 tick
*
*/
#define CAN_TIMEOUT_COUNTER_TICK2NS()   OS_TicksToNs_[!"@name"!](1U)
    [!ENDSELECT!]
[!ENDIF!]

/**
* @brief          Combined Interrupt.
* @details        Combined Interrupt or Not
                   - (STD_ON)  - Combined interrupt is supported for Controller .
                   - (STD_OFF) - Don't support combined interrupt
*
*/
#define CAN_COMBINED_INTERRUPT [!WS "4"!][!IF "ecu:get('MCan.CanConfig.CombinedInterrupt')='STD_ON'"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!]

/**
* @brief          This macro enables Can_MainFunction_Write() if at least one controller is set to process Tx in POLLING Mode.
* @details        This macro enables Can_MainFunction_Write() if at least one controller is set to process Tx in POLLING Mode.
*
*/
#define CAN_TXPOLL_SUPPORTED [!WS "4"!][!IF "$tx_pol_en = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          This macro enables Can_MainFunction_Read() if at least one controller is set to process Rx in POLLING Mode.
* @details        This macro enables Can_MainFunction_Read() if at least one controller is set to process Rx in POLLING Mode.
*
*/
#define CAN_RXPOLL_SUPPORTED [!WS "4"!][!IF "$rx_pol_en = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          This macro enables Can_MainFunction_CheckMRAF() if at least one controller is set to process MRAF processing in POLLING Mode.
* @details        This macro enables Can_MainFunction_CheckMRAF() if at least one controller is set to process MRAF processing in POLLING Mode.
*
*/
#define CAN_MRAFPOLL_SUPPORTED [!WS "4"!][!IF "$MRAF_pol = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          This macro enables Can_MainFunction_BusOff() if at least one controller is set to process BusOff in POLLING Mode.
* @details        This macro enables Can_MainFunction_BusOff() if at least one controller is set to process BusOff in POLLING Mode.
*
*/
#define CAN_BUSOFFPOLL_SUPPORTED [!WS "4"!][!IF "$Busoff_pol = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          This macro enables Can_MainFunction_Wakeup() if at least one controller is set to process WakeUp in POLLING Mode.
* @details        This macro enables Can_MainFunction_Wakeup() if at least one controller is set to process WakeUp in POLLING Mode.
*
*/
#define CAN_WAKEUPPOLL_SUPPORTED [!WS "4"!][!IF "$Wakeup_pol = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          This macro enables Can_MainFunction_Read() if at least one controller is set to process Rx in POLLING Mode.
* @details        This macro enables Can_MainFunction_Read() if at least one controller is set to process Rx in POLLING Mode.
*
*/
#define CAN_INTERRUPT_SUPPORTED [!WS "4"!][!IF "$int_en = 1"!](STD_ON)[!ELSE!](STD_OFF)[!ENDIF!][!CR!]

/**
* @brief          Maximum number of Message Buffers configured.
* @details        Maximum number of Message Buffers configured.
*
*/
#define CAN_MAXMBCOUNT [!WS "4"!][!SELECT "CanConfigSet"!][!"num:i(count(CanHardwareObject/*))"!]U[!ENDSELECT!][!CR!]

/**
* @brief          Maximum possible Message Buffers for Tx Buffer
* @details        Maximum possible Message Buffers for Tx Buffer
*
*/
#define CAN_MAX_TX_MB_CONFIG [!WS "4"!][!"num:i($MaxTxMBUsed)"!]U
/*==================================================================================================
*                                             ENUMS
==================================================================================================*/

/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/
[!SELECT "CanGeneral"!]
    [!IF "node:exists(CanLPduReceiveCalloutFunction)"!]
        [!IF "(normalize-space(CanLPduReceiveCalloutFunction) != 'NULL_PTR')"!]
/**
* @brief    This inclusion shall be made here, after the definition of other defines  which are used by the included file.
*/
#define Can_LPduReceiveCalloutFunction     [!WS "1"!][!"normalize-space(CanLPduReceiveCalloutFunction)"!][!CR!]
        [!ENDIF!]
    [!ENDIF!]
[!ENDSELECT!]

[!ENDINDENT!]

#ifdef __cplusplus
}
#endif

#endif /* _CAN_CFG_H_ */

/** @} */
