📄 can_drv.c
字号:
/* Copyright 2000 Delphi Delco Electronics Systems *//** MECEL Revision history ****************************************** $Revision: 1.9 $** $Date: Mar 19 2001 08:58:50 $**** $Log: J:\PROJ\1240VW_Cluster\PVCS\can_drv.c_v $ * * Rev 2.3 Mar 19 2001 08:58:50 MLA * NOPs to allow time for PSW modification to take effect * * Rev 2.2 Jan 08 2001 13:32:26 MLA * Interrupt switch-off protection added. * * Rev 2.1 Oct 12 2000 13:44:02 LI * Added handling of Busoff counter.******************************************************************//*****************************************************************************| Project Name: C A N - D R I V E R| File Name: CAN_DRV.C|| Description: Implementation of the CAN driver| Target systems: external intel 82527 or| SAB 80C16X with internal CAN or| C515C with internal CAN or| C505C with internal CAN| Compiler: Tasking V6R2| Keil PK51, V5.50a||-----------------------------------------------------------------------------| C O P Y R I G H T|-----------------------------------------------------------------------------| Copyright (c) 1996-1998 by Vector Informatik GmbH. All rights reserved.|| Alle Rechte an der Software verbleiben bei der| Vector Informatik GmbH.| Vector Informatik GmbH r鋟mt dem Lizenznehmer das unwider-| rufliche, geographisch und zeitlich nicht beschr鋘kte,| jedoch nicht ausschlie遧iche Nutzungsrecht innerhalb des| Lizenznehmers ein. Die Weitergabe des Nutzungsrechts| durch den Lizenznehmer ist auf dessen Zulieferer| beschr鋘kt. Die Zulieferer sind zu verpflichten, die| Software nur im Rahmen von Projekten f黵 den Lizenznehmer| zu verwenden; weitere Rechte der Zulieferer sind| auszuschlie遝n.||-----------------------------------------------------------------------------| A U T H O R I D E N T I T Y|-----------------------------------------------------------------------------| Initials Name Company| -------- --------------------- ------------------------------------| Eb Volker Ebner Vector Informatik GmbH| St Heiko Schmidt Vector Informatik GmbH| Ra Andreas Raisch Vector Informatik GmbH| dH Gunnar de Haan Vector Informatik GmbH| Hn Stephan Hoffmann Vector Informatik GmbH| Hp Armin Happel Vector Informatik GmbH| Lz Rainer Lutz Vector Informatik GmbH| Ba Bernd Baudermann Vector Informatik GmbH|-----------------------------------------------------------------------------| R E V I S I O N H I S T O R Y|-----------------------------------------------------------------------------| Date Ver Author Description| --------- --- ------ --------------------------------------------------| 01-Nov-96 1.0 Eb Creation| 22-Jan-97 1.02 Eb Optimizations| 01-Dez-97 1.03 St event or task functionality after a receive and transmit| 27-Jan-98 1.04 St Goal functionality| 10-Feb-98 1.05 St Full and Basic use the same structures| functions c_getStatus and c_setStatus are renamed| to CanSetStatus and CanGetStatus| 19-Feb-98 1.06 St Bug in FULL CAN Goal removed| 25-Feb-98 1.07 St canSetStatus renamed to canOnline() and canOffline()| 02-Apr-98 2.00 Eb/Ra New API for variable DLC: canTransmitVarDLC| CanEcuNumber and CanRxActualDLC will be calculated if| a precopy function is defined. DLC will be stored| into RAM, TxDLC_RAM[]. ROM values from CanTxDLC[] are| copied at canInit().| 15-Mai-98 2.10 Ra/dH New API for changing FullCan-ReceiveMask while system| is running.| CanEcuNumber will be calculated to 8 Bit within| precopy routines. For CanEcuNumber usage within NM| an unneeded "&0xE0" was removed! Interrupt uses| kCanNoCopyData for decision to copy data after precopy| 28-Mai-98 2.11 dH removed Bug in switch/case statement of copy CanRxData| with C_OPTIMIZE_SPEED| removed Bugs in Port-Routines (structure access)| New PreTransmit routine| 5-Jun-98 2.12 dH, Hn support for transport layer added| 9-Jun-98 2.13 dH, Hn CanEcuNumber calculation corrected for TP, if TP message| is Full-CAN or Basic-CAN object.| 17-Jun-98 2.14 dH Init-Structures changed to arrays; init-handle added| 3-Jul-98 dH CanSetPassive : added clear TxQueue| 7-Aug-98 dH/Hp support for Borland compiler added| 12-Aug-98 dH removed Goal part, added Message Manager support| CanTestChip now also available if defined C_ENABLE_TEST_CHIP| 09-Sep-98 2.15 Lz/Ba support for 80C5x5 and Keil compiler added| 13-Aug-98 2.20 dH corrected ISR function header| 19-Aug-98 dH CanEcuNumber calculation corrected, subtraction of| TP_RX_BASE_ADDRESS is not longer done in CAN_DRV.C| Indication and Confirmatin functions: parameter type changed| from pChipDataPtr to CanReceiveHandle / CanTransmitHandle| 17-Sep-98 2.21 dH remerged C16x and C5x5 sources to one single source| 30-Sep-98 2.22 dH Bugfix in function CanInit| 05-Oct-98 2.23 dH added CanInterruptOldStatus to save interrupt status to restore| this status when gInterruptCounter==0 in CanInterruptRestore| 07-Oct-98 2.24 Ba recursion depth decreased from 255 to 127 (gInterruptCounter now int8)| #ifdef C_DISABLE_TP_SUPPORT deleted| 07-Oct-98 2.25 dH CanInterruptDisable & CanInterruptRestore optimized| 05-Nov-98 2.26 Hn ifdef for timeout added| 10-Nov-98 2.27 dH copy data to buffer only if buffer exists| 11-Nov-98 2.28 dH support for OSEK added,return of Goal part,some beautifying| 12-Nov-98 2.29 Ba Disable and restore of interrupt state can realized| by the application (in this case no register bank| switching will be done): depending on the configuration| two Call-Back functions will be called. Special| functions will be called to do this, instead of| pragma DISABLE.| Address mode of CAN chip access can configured as| pdata or xdata.| Local variables of CanInit are changed to static,| to avoid Linker warnings caused by not relevant| recursive call.| Bugfixing: Init of src pointer in CanTransmit will| be done after the interrupts are disabled| 26-Nov-98 2.30 dH,Ba conversion to new Vector programming guidelines| Hp New datatypes| kTrue/kFalse replaced by 0/1| declaration of TxDLC_RAM removed because of changed| to external| CanWakeUp CanSleep CanPowerDown : moved #ifdef into function| Supporting HIGHTEC GNU-Compiler on C167| Interrutps in CanOffline only will be disabled if| Queue version is used| missing } in CanPortBitWrite added, deTAB| CanInterruptDisable changed| keyword "register" for complex variables with Keil compiler for C16X removed| assertCanInterrupt added|****************************************************************************//***************************************************************************//* Include files *//***************************************************************************/#ifdef C_ENABLE_OSEK#include <vrm.h>#define VRM_MAJ_REL_NUM 1 /* means 1.08 */#define VRM_MIN_REL_NUM 8#include <vrm.h>#include <stddef.h>#include <osek.h>#endif /* C_ENABLE_OSEK */#include "can_inc.h"#if defined( C_COMP_TASKING_C16x ) || \ defined( C_COMP_KEIL_C16x )#include <reg167.h> /* needed for dis/enable Irpt IEN =0/1 */#endif#if defined( C_COMP_KEIL_C16x ) #include "can_decl.h"#endif#if defined( C_ENABLE_GOAL ) #include "goal.h"#endif/***************************************************************************//* Version check *//***************************************************************************/#if( CAN_DRIVER_VERSION != 0x0230 ) #error "Source and Header file are inconsistent!"#endif/***************************************************************************//* Defines *//***************************************************************************//* NM related defines */#if defined( C_COMP_KEIL_C5X5C ) sbit EA = 0xAF; /* needed for dis/enable Irpt EA =0/1 */ sfr XPAGE = 0x91; /* XDATA base register */#endif#if defined( C_NM_VAG_OSEK ) #define C_NWM_BASE_ID_HI (0x04 << 5) /* base address for NWM msg=0x400 */ #define C_NWM_ACCEPT_MASK (0xF8) /* mask to select NWM message 0-64 */ #define C_NWM_MASK (0xFC) /* mask to calculate ECU nmbr 0-31 */#endif//#define _DEBUG_ 1 /* define to 1 to check internal queue state */#undef _DEBUG_ /* NOTE: very time consuming !! *//* Define chiphardware *//* Constants concerning 82527-registers *//* control registers for msg objects */#define kResetMsgVal 0x7f /* 01111111 */ /* Reset=01;Set=10;Unchanged=11*/#define kSetMsgVal 0xbf /* 10111111 */#define kTestMsgVal 0x80 /* 10000000 */#define kResetTxIE 0xdf /* 11011111 */#define kSetTxIE 0xef /* 11101111 */#define kResetRxIE 0xf7 /* 11110111 */#define kSetRxIE 0xfb /* 11111011 */#define kResetIntPnd 0xfd /* 11111101 */#define kSetIntPnd 0xfe /* 11111110 */#define kTestIntPnd 0x02 /* 00000010 */#define kResetTxRqst 0xdf /* 11011111 */#define kSetTxRqst 0xef /* 11101111 */#define kTestTxRqst 0x20 /* 00100000 */#define kResetCPUUpd 0xf7 /* 11110111 */#define kSetCPUUpd 0xfb /* 11111011 */#define kResetMsgLost 0xf7 /* 11110111 */#define kSetMsgLost 0xfB /* 11111011 */#define kTestMsgLost 0x08 /* 00001000 */#define kResetNewDat 0xfd /* 11111101 */#define kSetNewDat 0xfe /* 11111110 */#define kTestNewDat 0x02 /* 00000010 */#define kInitTmt 0x66 /* 01100110 : ----> ResetRmtPnd | SetTxRqst */ /* | ResetCPUUpd | SetNewDat */#define ReadMsgDlc(reg) ((reg)>>4)#define IsMsgTmt(obj) ((obj->ucMsgConf)&0x08)#define IsMsgLst(reg) ((reg)&kTestMsgLst)#define IsNoMsgLst(reg) ((reg)&kTestNoMsgLst)/* Bit masks for command register */#define kGotoSleep 0x08 /* Goto Sleep */#define kGotoPwd 0x10 /* Goto Powerdown *//* Bit masks for status register */#define kTxOk 0x08 /* Transmission success */#define kRxOk 0x10 /* Reception success */#define kWakeUp 0x20 /* chip was waked up */#define kErrWarn 0x40 /* Error: Warning Limit reached */#define kErrBusOff 0x80 /* Error: Busoff Limit reached */#define kLECUnused 0x07 /* LastErrorCode unused *//* Bit masks for control register */#define kEIE 0x08 /* Error Interrupt Enable */#define kSIE 0x04 /* Status Change Interrupt Enable */#define kIE 0x02 /* Interrupt Enable */#define kInit 0x01 /* Initialziation */#define kCCE 0x40 /* Control Change Enable *//* Bit masks for CPUInterface register */#define kRstSt 0x80 /* Hardware Reset status */#define kDSC 0x40 /* Divide System Cloc */#define kDMC 0x20 /* Divide Memory Clock */#define kPwD 0x10 /* Power Down Mode Enable */#define kSleep 0x08 /* Sleep Mode Enable */#define kMUX 0x04 /* Multiplex for ISO low speed */#define kCE 0x01 /* Clock out enable *//* wait time counter values; used for external 82527 only ! */#define kWaitReset 0xffff /* wait for chip reset */#define kWaitTime1 10000 /* wait for register access */#define kWaitTime2 100 /* wait for register access *//* macros used to check chip hardware e.g. driver internal state */#if defined ( C_ENABLE_HARDWARE_CHECK ) #define assertCan(p,e) if (!(p)) ApplFatalError(e);#else #define assertCan(a,b)#endif#define assertCanInterrupt(q,f) if (!(q)) ApplFatalError(f);/***************************************************************************//* Defines / data types / structs / unions *//***************************************************************************//* Define CAN Chip hardware; segment must be located in locator file *//* register layout of the can chip *//* For some compilers the register layout is defined in a seperate file *//* because they need this (for example Keil for 80C16x ) */#if defined( C_COMP_TASKING_C16x ) || \ defined( C_COMP_KEIL_C5X5C )#define ucExCLKOUT sMsg1Obj.aucSomeBytes[9]#define ucExBCR sMsg2Obj.aucSomeBytes[9]#define ucExBt0Reg sMsg3Obj.aucSomeBytes[9]#define ucExBt1Reg sMsg4Obj.aucSomeBytes[9]#define ucExIntrReg sMsg5Obj.aucSomeBytes[9]#define ucExP1CONF sMsg9Obj.aucSomeBytes[9]#define ucExP2CONF sMsg10Obj.aucSomeBytes[9]#define ucExP1IN sMsg11Obj.aucSomeBytes[9]#define ucExP2IN sMsg12Obj.aucSomeBytes[9]#define ucExP1OUT sMsg13Obj.aucSomeBytes[9]#define ucExP2OUT sMsg14Obj.aucSomeBytes[9]#define ucExSerResAddr sMsg15Obj.aucSomeBytes[9]#define aucCanData(i) aucSomeBytes[i+1]#define ucMsgConf aucSomeBytes[0]typedef volatile struct tCanMsgObj{ canuint8 ucCntrl0; /* Control Register */ canuint8 ucCntrl1; /* Control Register */ /* 16-Bit access reserved for optimization */ canuint8 aucArbitrFld[4]; /* ! High-Byte first */ canuint8 aucSomeBytes[10];} CanMsgObj ;typedef volatile struct sCan82527AddrMapNamed{ canuint8 ucCntrlReg; /* Control-Register */ canuint8 ucStatReg; /* Status-Register */ union { struct { canuint8 ucCPUIntf; /* CPU-Interface */ canuint8 ucReserved1; /* Reserved */ canuint16 uiHiSpeedRead; /* High-Speed-Read */ } ex; /* external 82527 ---------------*/ struct { canuint8 ucIntrReg; /* Interrupt-Register */ canuint8 dummy;#ifdef C_COMP_KEIL_C5X5C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -