/**********************************************************************************************************************
 *  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 - 2014.  All rights reserved.
 *
 *  \endverbatim
 *  -------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  -------------------------------------------------------------------------------------------------------------------
 *  File:         Can_PBcfg.c
 *  Project:      Tms570_AutosarCanDriver
 *  Module:       Can
 *  Generator:    EB Tresos
 *
 *
 *  Description:  The Can Driver provides the low level functions for the CAN interface layer.
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Vishwanath Reddy
 *---------------------------------------------------------------------------------------------------------------------
 * Template 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.
 *                                                                  Added requirement tags for traceability. 
 * 02.20.01       10Apr2014    Vishwanath Reddy    SDOCM00107321    Version Info update.
 *                                                                  Add design tags.
 * 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.
 *********************************************************************************************************************/
/**********************************************************************************************************************
    Project: [!"$project"!]
	Date   : [!"$datetime"!] 
	
	This file is generated by EB Tresos
    Do not modify this file, otherwise the software may behave in unexpected way.
 *********************************************************************************************************************/
/*
 * Module switch
 */
#define CAN_PBCFG_SOURCE
/**********************************************************************************************************************
 *  INCLUDES
 *********************************************************************************************************************/
 #include "Can.h"
 #include "Can_Cfg.h"

/**********************************************************************************************************************
 *  VERSION CHECK
 *********************************************************************************************************************/
#define CAN_CFG_C_MAJOR_VERSION               (5U)
#define CAN_CFG_C_MINOR_VERSION               (30U)
#define CAN_CFG_C_PATCH_VERSION               (0U)

/*  Version checking  */
 #if (   (CAN_SW_MAJOR_VERSION != CAN_CFG_C_MAJOR_VERSION)||\
         (CAN_SW_MINOR_VERSION != CAN_CFG_C_MINOR_VERSION))
  #error "Version numbers of Can_PBcfg.c and Can.h are inconsistent!"
#endif

#if (   (CAN_CFG_MAJOR_VERSION != CAN_CFG_C_MAJOR_VERSION) || \
        (CAN_CFG_MINOR_VERSION != CAN_CFG_C_MINOR_VERSION))
  #error "Version numbers of Can_PBcfg.c and Can_Cfg.h are inconsistent!"
#endif

/**********************************************************************************************************************
 *  GLOBAL DATA
 *********************************************************************************************************************/
#define CAN_START_SEC_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

/* Filter masks for all the config sets */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanController/*"!][!LOOP "CanFilterMask/*"!]Can_MaskType  [!"../../../../@name"!]_[!"../../@name"!]_[!"@name"!] = 
{
  [!"CanFilterMaskValue"!]U  /* Mask Value */
};

[!ENDLOOP!][!ENDLOOP!][!ENDLOOP!]

/* SourceId : CAN_SourceId_034 */
/* DesignId : CAN_DesignId_001 */
/* Requirements : AR_CAN_SR278, AR_CAN_SR279 */
/*List of the FilterMask structures */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanController/*"!][!VAR "test" = "node:exists(CanFilterMask/*)"!][!IF "$test='true'"!]Can_MaskType *[!"../../@name"!]_[!"@name"!]_FilterMaskList []=
{ 
  [!LOOP "CanFilterMask/*"!]  &[!"../../../../@name"!]_[!"../../@name"!]_[!"@name"!],
  [!ENDLOOP!]
};
[!ELSE!][!ENDIF!][!ENDLOOP!][!ENDLOOP!] 

/* SourceId : CAN_SourceId_033 */
/* DesignId : CAN_DesignId_001 */
/* Requirements : AR_CAN_SR263, AR_CAN_SR264, AR_CAN_SR265, AR_CAN_SR266, AR_CAN_SR267, AR_CAN_SR268 */
/* Baud Rate Structure for all configsets */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanController/*"!][!LOOP "CanControllerBaudrateConfig/*"!]Can_BaudConfigType  [!"../../../../@name"!]_[!"../../@name"!]_[!"@name"!] = 
{
  [!"CanControllerBaudRate"!]U,     /* in KB */
  [!"CanControllerPropSeg"!]U, 
  [!"CanControllerSeg1"!]U, 
  [!"CanControllerSeg2"!]U,
  [!"CanControllerSyncJumpWidth"!]U,
  [!"num:i(CanControllerPropSeg+CanControllerSeg1+CanControllerSeg2)"!]U,  /* Sum of all timing parameters  */
  [!VAR "AVCLK" = "num:i(as:modconf('Can')/CanGeneral/AVCLK)"!][!"num:i(num:i(round(($AVCLK*1000)div(CanControllerBaudRate*(1+CanControllerPropSeg+CanControllerSeg1+CanControllerSeg2)))))"!]U, /* Controller BRP value for Baud */
};

[!ENDLOOP!][!ENDLOOP!][!ENDLOOP!]

/* SourceId : CAN_SourceId_035 */
/* DesignId : CAN_DesignId_001 */
/* Requirements : AR_CAN_SR280 */
/*List of the Baudrate structures */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanController/*"!]Can_BaudConfigType *[!"../../@name"!]_[!"@name"!]_BaudRateConfigList[]=
{ 
  [!LOOP "CanControllerBaudrateConfig/*"!]  &[!"../../../../@name"!]_[!"../../@name"!]_[!"@name"!],
  [!ENDLOOP!]
};

[!ENDLOOP!][!ENDLOOP!]  

/* SourceId : CAN_SourceId_016 */
/* DesignId : CAN_DesignId_001 */
/* Requirements : AR_CAN_SR115, AR_CAN_SR252, AR_CAN_SR253, AR_CAN_SR254, AR_CAN_SR255, AR_CAN_SR256, AR_CAN_SR257,AR_CAN_SR258, AR_CAN_SR259, AR_CAN_SR260, AR_CAN_SR251   */
/* Controller structure defined here for all config sets */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanController/*"!]Can_ControllerType  [!"../../@name"!]_[!"@name"!] = 
{
  [!"CanControllerId "!]U,      /* Id as provided by GUI */
  [!IF "CanControllerActivation = 'true'"!]  TRUE[!ELSE!]  FALSE[!ENDIF!],   /* Contoller is used=1 or not_used=0*/
  [!"num:inttohex(CanControllerBaseAddress)"!]U, /* Pointer to CanReg structure */  
  [!IF "CanWakeupSupport = 'true'"!]TRUE[!ELSE!]FALSE[!ENDIF!],   /* Automatic wakeup via bus activity */
  [!IF "CanRxProcessing   = 'INTERRUPT'"!]TRUE[!ELSE!]FALSE[!ENDIF!],  /* TRUE = Interrupt FALSE = Polling */
  [!IF "CanTxProcessing   = 'INTERRUPT'"!]TRUE[!ELSE!]FALSE[!ENDIF!],  /* TRUE = Interrupt FALSE = Polling */
  [!IF "CanBusoffProcessing = 'INTERRUPT'"!]TRUE[!ELSE!]FALSE[!ENDIF!],   /* TRUE = Interrupt FALSE = Polling */
  [!IF "CanWakeupProcessing = 'INTERRUPT'"!]TRUE[!ELSE!]FALSE[!ENDIF!],   /* TRUE = Interrupt FALSE = Polling */
  &[!"text:replace(text:replace(substring-after(substring-after(substring-after(CanControllerDefaultBaudrate,'/'),'/'),'/'),'/','_'),'/','_')"!],  /* pointer to default Baud structure */
  [!IF "CanRxProcessing ='INTERRUPT' or CanTxProcessing = 'INTERRUPT'"!]0x02U[!ELSE!]0x00U[!ENDIF!],  /* Contoller Interrupt Mask */
  [!"../../@name"!]_[!"@name"!]_BaudRateConfigList,  /* List of available Baudrate structs */
  [!VAR "test11"="node:exists(CanFilterMask/*)"!][!IF "$test11='false'"!]NULL_PTR[!ELSE!][!"../../@name"!]_[!"@name"!]_FilterMaskList[!ENDIF!]       /* List of Avialable masks */
};


[!ENDLOOP!][!ENDLOOP!]  

/*List of the Controller structures */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!]Can_ControllerType *[!"@name"!]_CanController_List[]= 
{ 
  [!LOOP "CanController/*"!]  &[!"../../@name"!]_[!"@name"!],
  [!ENDLOOP!]
};

[!ENDLOOP!]

[!VAR "x" = "1"!] [!VAR "var1" = "1"!] [!VAR "var2" = "1"!] [!VAR "var3" = "1"!] [!VAR "cntId" = "0"!] [!VAR "mask" = "0"!] [!VAR "maskXist" = "0"!] [!VAR "maskCntr" = "0"!]
[!VAR "CanName"="as:path(as:modconf('Can')[1])"!][!VAR "CanName2"="substring-after(substring-after($CanName,'/'),'/')"!]
/* All the Mailbox objects(MB's) will be defined here for all config sets */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!][!LOOP "CanHardwareObject/*"!]Can_MailboxType  [!"../../@name"!]_[!"@name"!] = 
{
  [!IF "CanHandleType ='FULL'"!]0U[!ELSE!]1U[!ENDIF!],  /*  CanHandleType 0=Full, 1=Basic */ 
  [!IF "CanIdType = 'EXTENDED'"!]1U[!ELSEIF "CanIdType = 'STANDARD'"!]0U[!ELSE!]2U[!ENDIF!],  /* CanIdType 0=standard 1=Extended 2=Mixed*/ [!IF "CanIdType = 'MIXED' and CanObjectType = 'RECEIVE'"!][!ERROR "CAN: Mixed mode is not supported for Receive"!][!ENDIF!][!CR!]
  [!"CanIdValue"!]U,  /* ID value extended will have MSB set */
  [!"CanObjectId"!]U,  /* CanObjectId - Holds handle Id */
  [!VAR "cntId" = "node:value(concat("/AUTOSAR/TOP-LEVEL-PACKAGES/Can/ELEMENTS/",$CanName2,"/CanConfigSet/",substring-before(substring-after(substring-after(substring-after(CanControllerRef,'/'),'/'),'/'),'/'),"/CanController/",substring-after(substring-after(substring-after(substring-after(as:modconf('Can')[1]/CanConfigSet/*[1]/CanHardwareObject/*[num:i($x)]/CanControllerRef,'/'),'/'),'/'),'/'),"/CanControllerId"))"!][!IF "$cntId ='0' "!][!"num:i($var1)"!][!VAR "var1" = "$var1+1"!][!ASSERT "$var1 != '64'  ","STOP: HWHandle more than 64 for a controller is not allowed"!][!ELSEIF " $cntId = '1'"!][!"num:i($var2)"!][!VAR "var2" = "$var2+1"!][!ASSERT "$var2 != '64'  ","STOP: HWHandle more than 64 for a controller is not allowed"!][!ELSEIF "$cntId = '2'"!][!"num:i($var3)"!][!VAR "var3" = "$var3+1"!][!ASSERT "$var3 != '64'  ","STOP: HWHandle more than 64 for a controller is not allowed"!][!ENDIF!]U,  /* HwHandle */ /* Mailbox - Hw object in the controller*/
  [!IF "CanObjectType = 'TRANSMIT'"!]1U[!ELSE!]0U[!ENDIF!],  /* CanObjectType - Direction of Mailbox,0= Rx or 1= Tx*/
  &[!"text:replace(substring-after(substring-after(substring-after(CanControllerRef,'/'),'/'),'/'),'/','_')"!],  /* Controller */ 
  [!VAR "node1"="node:exists(CanFilterMaskRef)"!][!IF "$node1='false'"!]NULL_PTR[!ELSE!]&[!"text:replace(text:replace(substring-after(substring-after(substring-after(CanFilterMaskRef,'/'),'/'),'/'),'/','_'),'/','_')"!][!ENDIF!],  /* ptr to Mask for the RX filtering */
  8U   /* Length of the Mailbox */
};

[!ENDLOOP!][!VAR "x" = "$x+1"!][!ENDLOOP!]

/* List of the Mailboxes */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!]Can_MailboxType *[!"@name"!]_CanHardwareObject_List[] = 
{
  [!LOOP "CanHardwareObject/*"!] &[!"../../@name"!]_[!"@name"!],
  [!ENDLOOP!]
};
[!ENDLOOP!]

/*SAFETYMCUSW 580 S MR:1.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#define CAN_STOP_SEC_PBCFG
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"

/*SAFETYMCUSW 580 S MR:1.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#define CAN_START_SEC_PBCFG_ROOT
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h"
/* SourceId : CAN_SourceId_012 */
/* DesignId : CAN_DesignId_001 */
/* Requirements : AR_CAN_SR83, AR_CAN_SR84 */
/*Can Config struct */
[!LOOP "as:modconf('Can')[1]/CanConfigSet/*"!]const Can_ConfigType  [!"@name"!] = 
{
   [!"@name"!]_CanController_List, /* List of all controllers in this config set */
   [!VAR "maxController" = "0"!]  [!LOOP "./CanController/*"!][!VAR "maxController" = "$maxController+1"!][!ENDLOOP!]([!"num:i($maxController)"!]U),  /* max Controllers */      
   [!"@name"!]_CanHardwareObject_List,
   [!VAR "varmax" = "0"!][!LOOP "./CanHardwareObject/*"!][!VAR "varmax" = "$varmax+1"!][!ENDLOOP!]([!"num:i($varmax)"!]U)/* total number of mail boxes in this configset */
};
[!ENDLOOP!]

/*SAFETYMCUSW 580 S MR:1.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#define  CAN_STOP_SEC_PBCFG_ROOT
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Reason - This is the format to use for specifying memorysections."*/
#include "MemMap.h" 
/*********************************************************************************************************************
 *  End of File: Can_PBcfg.c
 *********************************************************************************************************************/
