/**
*   @file    Can_Mcan.h
*   @implements MCan.h_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Can - MCan module interface.
*   @details Low Level Driver header file for IPV = FlexCan.
*
*   @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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/


#ifndef CAN_MCAN_H
#define CAN_MCAN_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_Mcan_h_REF_1
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Declaration is reserved for future feature.
*
* @section Can_Mcan_h_REF_2
* 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].
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
/*
* @file           Can_MCan.h
*/
#include "Mcal.h"
#include "Can_GeneralTypes.h"
#include "Can.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @file           Can_Mcan.h
*/
#define CAN_VENDOR_ID_MCAN_H                    43
/* @violates @ref Can_Mcan_h_REF_1 MISRA 2012 Advisory Rule 2.5 */
#define CAN_MODULE_ID_MCAN_H                    80
#define CAN_AR_RELEASE_MAJOR_VERSION_MCAN_H     4
#define CAN_AR_RELEASE_MINOR_VERSION_MCAN_H     3
#define CAN_AR_RELEASE_REVISION_VERSION_MCAN_H  1
#define CAN_SW_MAJOR_VERSION_MCAN_H             1
#define CAN_SW_MINOR_VERSION_MCAN_H             0
#define CAN_SW_PATCH_VERSION_MCAN_H             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Can header file are of the same vendor */
#if (CAN_VENDOR_ID_MCAN_H != CAN_VENDOR_ID)
    #error "Can_Mcan.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_MCAN_H    != CAN_AR_RELEASE_MAJOR_VERSION) || \
     (CAN_AR_RELEASE_MINOR_VERSION_MCAN_H    != CAN_AR_RELEASE_MINOR_VERSION) || \
     (CAN_AR_RELEASE_REVISION_VERSION_MCAN_H != CAN_AR_RELEASE_REVISION_VERSION))
    #error "AutoSar Version Numbers of Can_Mcan.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_MCAN_H != CAN_SW_MAJOR_VERSION) || \
     (CAN_SW_MINOR_VERSION_MCAN_H != CAN_SW_MINOR_VERSION) || \
     (CAN_SW_PATCH_VERSION_MCAN_H != CAN_SW_PATCH_VERSION))
    #error "Software Version Numbers of Can_Mcan.c and Can.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    #if ((CAN_AR_RELEASE_MAJOR_VERSION_MCAN_H != MCAL_AR_RELEASE_MAJOR_VERSION) || \
         (CAN_AR_RELEASE_MINOR_VERSION_MCAN_H != MCAL_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Can_Mcan.h and Mcal.h are different"
    #endif
#endif
/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/

/**
* @brief          CAN Interrupts state.
* @details        CAN Interrupts state.
*
*/
typedef enum
    {
        CAN_INTERRUPT_DISABLED = 0U,  /*< @brief Interrupts disabled */
        CAN_INTERRUPT_ENABLED         /*< @brief Interrupts enabled */
    } Can_InterruptStateType;

/**
* @brief          CAN Share Ram initialized state.
* @details        CAN Share Ram initialized state.
*
*/
typedef enum
    {
        MCAN_SRAM_UNINITIALIZED = 0U,  /*< @brief Share ram uninitialized */
        MCAN_SRAM_INITIALIZED        /*< @brief Share ram initialized */
    } Can_SramStateType;



/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
/**
* @brief          Records the status of a CAN Controller during runtime.
* @details        Records the status of a CAN Controller during runtime.
*
* @note           This structure is not configured by Tresos.
*/
typedef struct
    {
        /*< @brief Guard bits for EXCLUSIVE ACCESS to Tx MBs */
        VAR(uint32, CAN_VAR) u32TxGuard;
        /*< @brief Pre-calculated MB INT masks (used in Can_EnableControllerInterrupts) */
        VAR(uint32, CAN_VAR) u32MBInterruptMask;
        /*< @brief Storage space for PDU_ID (supplied in call to Can_Write and needed after Tx in CanIf_TxConfirmation) */
        VAR(PduIdType, CAN_VAR) u32TxPduId[CAN_MAX_TX_MB_CONFIG];
        /*< @brief Storage space for Can_DisableControllerInterrupts nesting level */
        volatile VAR(sint8, CAN_VAR) s8IntDisableLevel;
        /*< @brief Global interrupt autorization state */
        VAR(Can_InterruptStateType, CAN_VAR) eInterruptMode; /*< @brief Global interrupt autorization state */
        /*< @brief Map for every MB the HOH assigned according to configuration. */
        VAR(Can_HwHandleType, CAN_VAR) MbTxMapping[CAN_MAX_TX_MB_CONFIG];
        VAR(uint32, CAN_VAR) Tx_complete_guard;
    } Can_ControllerStatusType;

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

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/
#define CAN_START_SEC_CODE
/* @violates @ref Can_Mcan_h_REF_2 MISRA 2012 Required Directive 4.10 */
#include "Can_MemMap.h"

FUNC (void, CAN_CODE) Can_MCan_InitVariables( void);
#if (STD_ON == CAN_TRIGGER_TRANSMIT_EN)
    FUNC(Std_ReturnType, CAN_CODE) Can_MCan_CheckBufferFree(Can_HwHandleType Hth);
#endif
FUNC (void, CAN_CODE) Can_MCan_InitController(VAR(uint8, AUTOMATIC) controller);

FUNC (void, CAN_CODE) Can_MCan_DeInitController(VAR(uint8, AUTOMATIC) Controller);

FUNC(Can_ControllerStateType, CAN_CODE) Can_MCan_GetControllerMode(VAR(uint8, AUTOMATIC) Controller);

FUNC(Can_ErrorStateType, CAN_CODE)  Can_MCan_GetControllerErrorState(VAR(uint8, AUTOMATIC) Controller);

FUNC (Std_ReturnType, CAN_CODE) Can_MCan_SetControllerMode( VAR(uint8, AUTOMATIC) controller,
                                                            P2CONST(Can_ControlerDescriptorType, AUTOMATIC, CAN_APPL_CONST) pCanControlerDescriptor,
                                                            VAR(Can_ControllerStateType, AUTOMATIC) Transition,
                                                            VAR(boolean, AUTOMATIC) canif_notification_required
                                                          );

FUNC (void, CAN_CODE) Can_MCan_DisableControllerInterrupts( VAR(uint8, AUTOMATIC) controller );

FUNC (void, CAN_CODE) Can_MCan_EnableControllerInterrupts( VAR(uint8, AUTOMATIC) controller,
                                                           P2CONST(Can_ControlerDescriptorType, AUTOMATIC, CAN_APPL_CONST) pCanControlerDescriptor
                                                         );



#if (CAN_API_ENABLE_ABORT_MB == STD_ON)

FUNC(void, CAN_CODE) Can_MCan_AbortMb( VAR(Can_HwHandleType, AUTOMATIC) Hth );

#endif


FUNC (Std_ReturnType, CAN_CODE) Can_MCan_Write( Can_HwHandleType Hth,
                                                P2CONST(Can_PduType, AUTOMATIC, CAN_APPL_CONST) PduInfo
                                              );
#if (CAN_TXPOLL_SUPPORTED == STD_ON)

FUNC (void, CAN_CODE) Can_MCan_MainFunctionWrite( void);
FUNC (void, CAN_CODE) Can_MCan_MainFunctionMultipleWritePoll( VAR(uint8, AUTOMATIC) writepoll);

#endif /* (CAN_TXPOLL_SUPPORTED == STD_ON) */

#if (CAN_RXPOLL_SUPPORTED == STD_ON)

FUNC (void, CAN_CODE) Can_MCan_MainFunctionRead( void);
FUNC (void, CAN_CODE) Can_MCan_MainFunctionMultipleReadPoll( VAR(uint8, AUTOMATIC) readpoll);

#endif /* (CAN_RXPOLL_SUPPORTED == STD_ON) */


FUNC (void, CAN_CODE) Can_MCan_ProcessBusOff( CONST(uint8, CAN_CONST) controller);


FUNC (Std_ReturnType, CAN_CODE) Can_MCan_CheckBusOff( VAR(uint8, AUTOMATIC) controller);


FUNC (void, CAN_CODE) Can_MCan_MainFunctionMode( void);

FUNC (Std_ReturnType, CAN_CODE) Can_MCan_SetBaudrate(VAR(uint8, AUTOMATIC) Controller, VAR(uint16, AUTOMATIC) BaudRateConfigID);

#if (CAN_DUAL_CLOCK_MODE == STD_ON)

FUNC(Std_ReturnType, CAN_CODE) Can_MCan_SetClockMode( VAR(uint8, AUTOMATIC) u8Controller, VAR(Can_ClockModeType, AUTOMATIC) can_clk_mode);

#endif /* CAN_DUAL_CLOCK_MODE == STD_ON */

#ifdef CAN_SUPPORT_MRAF_EVENT
  #if (CAN_SUPPORT_MRAF_EVENT == STD_ON)
    #if (CAN_MRAFPOLL_SUPPORTED == STD_ON)
FUNC (void, CAN_CODE) Can_MCan_MainFunction_CheckMRAF( void);
    #endif
  #endif /* (CAN_SUPPORT_MRAF_EVENT == STD_OFF) */
#endif /* defined(CAN_SUPPORT_MRAF_EVENT) */
#ifdef ERR_IPV_MCAN_0002 
  #if (ERR_IPV_MCAN_0002 == STD_ON)
FUNC (void, CAN_CODE) Can_MCan_DummyRead(VAR(uint8, AUTOMATIC) u8Controller);
  #endif
#endif

#if (STD_ON == CAN_INTERRUPT_SUPPORTED)
FUNC (void, CAN_CODE) Can_MCan_Isr_common_process_interrupt(CONST(uint8, CAN_CONST) controller);

#endif

#ifdef ERR_IPV_MCAN_0004
    #if (STD_ON == ERR_IPV_MCAN_0004)
        FUNC(uint8, CAN_CODE) Can_MCan_GetControllerCommunicationState(uint8 Controller);
    #endif
#endif

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

#ifdef __cplusplus
}
#endif

#endif /* CAN_MCAN_H */

/** @} */
