/**********************************************************************************************************************
 *  COPYRIGHT
 *  -------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *
 *                 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *                 Property of Texas Instruments, Unauthorized reproduction and/or distribution
 *                 is strictly prohibited.  This product  is  protected  under  copyright  law
 *                 and  trade  secret law as an  unpublished work.
 *                 (C) Copyright Texas Instruments.  All rights reserved.
 *
 *  \endverbatim
 *  -------------------------------------------------------------------------------------------------------------------
 * 
 *  -------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  -------------------------------------------------------------------------------------------------------------------
 *         File:  Can.h
 *    Component:  Tms570_AutosarCanDriver
 *       Module:  CanDriver
 *    Generator:  -
 *
 *  Description:  API to hardware abstraction of the CAN-driver             
 * ---------------------------------------------------------------------------------------------------------------------
 * Author:  Vishwanath Reddy
 *---------------------------------------------------------------------------------------------------------------------
 * Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version        Date         Author               Change ID        Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.10.00       10Feb2013    Vishwanath Reddy    0000000000000    Initial Version adapted from TMS570LS31xx v1.10.00
 * 02.20.00       23Aug2013    Vishwanath Reddy    SDOCM00103356    Version Info update.
 *                                                                  Prototypes added for implementing Safety API's.
 * 02.20.01       10Apr2014    Vishwanath Reddy    SDOCM00107321    Version Info update. 
 *                                                                  Add design tags.
 *                                                                  CAN_BAUD_RATE_CHECK_CHANGE_API modified to 
 *                                                                  CAN_CHANGE_BAUDRATE_API.   
 * 02.21.00       30Sep2014    Vineeth T Alex      SDOCM00113179    Changes for Production release.
 *                                                                  Device compatibility
 * 02.21.01       03Nov2014    Vineeth T Alex      SDOCM00113685    Version Update.
 * 02.21.02       01Mar2016    Vishwanath Reddy    SDOCM00121479    Version Update.
 * 02.30.00       01Dec2016    Sudhakar Singh          None         Update version info
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834    Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/
#ifndef CAN_H
#define CAN_H

/**********************************************************************************************************************/
/* INCLUDES                                                                                                           */
/**********************************************************************************************************************/
#include "ComStack_Types.h"
#include "Can_GeneralTypes.h"
#include "Can_Cfg.h"

/**********************************************************************************************************************/
/* VERSION CHECK                                                                                                      */
/**********************************************************************************************************************/
#define CAN_SW_MAJOR_VERSION               (5U)
#define CAN_SW_MINOR_VERSION               (30U)
#define CAN_SW_PATCH_VERSION               (0U)

#define CAN_AR_RELEASE_MAJOR_VERSION     (4U)
#define CAN_AR_RELEASE_MINOR_VERSION     (0U)
#define CAN_AR_RELEASE_REVISION_VERSION  (3U)

/*********************************************************************************************************************/
/* GLOBAL CONSTANT MACROS                                                                                            */
/*********************************************************************************************************************/
#define CAN_VENDOR_ID   44U
#define CAN_MODULE_ID   80U


/* Module Id's */
#define CAN_INIT_ID                 (uint8)0x00U
#define CAN_MAINFCT_WRITE_ID        (uint8)0x01U
#define CAN_SETCTR_ID               (uint8)0x03U
#define CAN_DIINT_ID                (uint8)0x04U
#define CAN_ENINT_ID                (uint8)0x05U
#define CAN_WRITE_ID                (uint8)0x06U
#define CAN_VERSION_ID              (uint8)0x07U
#define CAN_MAINFCT_READ_ID         (uint8)0x08U
#define CAN_MAINFCT_BO_ID           (uint8)0x09U
#define CAN_MAINFCT_WU_ID           (uint8)0x0AU
#define CAN_CKWAKEUP_ID             (uint8)0x0BU
#define CAN_CHKBAUDRATE_ID          (uint8)0x0EU
#define CAN_CHNGBAUDRATE_ID         (uint8)0x0DU
#define CAN_MAINFCT_MODE_ID         (uint8)0x0CU
#define CAN_LOOPBACK_ID             (uint8)0x0FU
#define CAN_RXPROCESS_ID            (uint8)0x10U
#define CAN_INITCTR_ID              (uint8)0x02U

/* Internal Id's */
#define CAN_RXINDI_ID               0x10U
#define CAN_TXCNF_ID                0x11U
#define CAN_CTRWAKEUP_ID            0x12U
#define CAN_CTRBUSOFF_ID            0x13U

/* Error Codes */
/* SourceId : CAN_SourceId_039 */
/* DesignId : CAN_DesignId_005 */
/* Requirements : AR_CAN_SR116 */
#ifndef CAN_E_PARAM_POINTER
#define CAN_E_PARAM_POINTER         (uint8)0x01U
#endif
#ifndef CAN_E_PARAM_HANDLE
#define CAN_E_PARAM_HANDLE          (uint8)0x02U
#endif
#ifndef CAN_E_PARAM_DLC
#define CAN_E_PARAM_DLC             (uint8)0x03U
#endif
#ifndef CAN_E_PARAM_CONTROLLER
#define CAN_E_PARAM_CONTROLLER      (uint8)0x04U
#endif
#ifndef CAN_E_UNINIT
#define CAN_E_UNINIT                (uint8)0x05U
#endif
#ifndef CAN_E_TRANSITION
#define CAN_E_TRANSITION            (uint8)0x06U
#endif
#ifndef CAN_E_DATALOST
#define CAN_E_DATALOST				(uint8)0x07U
#endif
#ifndef CAN_E_TIMEOUT_DET
#define CAN_E_TIMEOUT_DET           (uint8)0x08U
#endif
#ifndef CAN_E_PARAM_BAUDRATE
#define CAN_E_PARAM_BAUDRATE        (uint8)0x09U
#endif
#ifndef CAN_E_RXQUEUE
#define CAN_E_RXQUEUE               (uint8)0x10U
#endif


/*********************************************************************************************************************/
/* TYPE DEFINITIONS                                                                                       */
/*********************************************************************************************************************/

typedef P2CONST(Can_PduType,TYPEDEF, APPL_VAR) Can_PduInfoPtrType;
/*SAFETYMCUSW 74 S MR:18.4 <APPROVED> "Reason - Union declaration is required here because of CAN data handling."*/
typedef union can_dataTag
{
  uint8       ucData[8U];
  uint16      usData[4U];
  uint32      ulData[2U];
} can_data;

#if(STD_ON == CAN_SAFETI_API)
/* CAN Config registers */
typedef struct Can_CanConfigRegTag
{
	uint32              Can_ReaBack_CTL;	                     /* Control Register             	*/
	uint32              Can_ReaBack_BTR;	                     /* Bit Timing Register          	*/
	uint32              Can_ReaBack_ABOTR;                       /* Auto Bus On Time Register       */
	uint32              Can_ReaBack_INTMUXx[4U];                 /* Interrupt Multiplexer Registers */
} Can_CanConfigReg;
extern Can_CanConfigReg Can_CanConfig;
#endif


/*********************************************************************************************************************/
/* API AND FUNCTION PROTOTYPES                                                                                        */
/*********************************************************************************************************************/

#if (CAN_VERSION_INFO_API == STD_ON)
FUNC(void, CAN_CODE)  Can_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, CAN_APPL_DATA) VersionInfo );
#endif

FUNC(void, CAN_CODE) Can_Init(P2CONST( Can_ConfigType, AUTOMATIC, CAN_PBCFG) ConfigPtr );
FUNC(Can_ReturnType, CAN_CODE) Can_SetControllerMode( uint8 Controller, Can_StateTransitionType Transition );
FUNC(Can_ReturnType, CAN_CODE) Can_Write( uint8 Hth, Can_PduInfoPtrType PduInfo );
FUNC(Can_ReturnType, CAN_CODE) Can_CheckWakeup( uint8 Controller );

/* function for hw access */
FUNC(void, CAN_CODE)  Can_DisableControllerInterrupts( uint8 Controller );
FUNC(void, CAN_CODE)  Can_EnableControllerInterrupts( uint8 Controller );

/* polling functions (always available for non polled systems also)*/
FUNC(void, CAN_CODE)  Can_MainFunction_Write( void );
FUNC(void, CAN_CODE)  Can_MainFunction_BusOff( void );
FUNC(void, CAN_CODE)  Can_MainFunction_Read( void );
FUNC(void, CAN_CODE)  Can_MainFunction_Wakeup( void );
FUNC(void, CAN_CODE)  Can_MainFunction_Mode( void );

/* Baud rate functions*/
#if (CAN_CHANGE_BAUDRATE_API == STD_ON)
FUNC(Std_ReturnType, CAN_CODE) Can_ChangeBaudrate( uint8 Controller, const uint16 Baudrate );
FUNC(Std_ReturnType, CAN_CODE) Can_CheckBaudrate( uint8 Controller, const uint16 Baudrate );
#endif

#if (CAN_LOOPBACK_ENABLE == STD_ON)
FUNC(Std_ReturnType, CAN_CODE) Can_TestLoopBackModeEnable(uint8 controller, uint8 mode);
FUNC(Std_ReturnType, CAN_CODE) Can_TestLoopBackModeDisable(uint8 controller, uint8 mode);
#endif

#if(STD_ON == CAN_SAFETI_API)
FUNC(Std_ReturnType, CAN_CODE) Can_ConfigRegReadBack(VAR(uint8, AUTOMATIC) controller);
#endif

FUNC(void, CAN_CODE) Can_0_Int0ISR_Fun(  void );
FUNC(void, CAN_CODE) Can_1_Int0ISR_Fun(  void );
FUNC(void, CAN_CODE) Can_2_Int0ISR_Fun(  void );

#if (IRQ_CAT1 == STD_ON)
FUNC(void, CAN_CODE) Can_0_Int0ISR( void );
FUNC(void, CAN_CODE) Can_1_Int0ISR( void );
FUNC(void, CAN_CODE) Can_2_Int0ISR( void );
#endif


#endif /* CAN_H end file*/
/*********************************************************************************************************************
 *  End of File: Can.h
 *********************************************************************************************************************/

