pcan.h
Go to the documentation of this file.
00001 #ifndef __PCAN_H__
00002 #define __PCAN_H__
00003 
00004 //****************************************************************************
00005 // Copyright (C) 2001-2010  PEAK System-Technik GmbH
00006 //
00007 // linux@peak-system.com 
00008 // www.peak-system.com
00009 //
00010 // This program is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU General Public License as published by
00012 // the Free Software Foundation; either version 2 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // This program is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with this program; if not, write to the Free Software
00022 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023 //
00024 // Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
00025 //****************************************************************************
00026 
00027 //****************************************************************************
00028 //
00029 // pcan.h
00030 // constants and definitions to access the drivers 
00031 //
00032 // $Id: pcan.h 615 2010-02-14 22:38:55Z khitschler $
00033 //
00034 //****************************************************************************
00035 
00036 //****************************************************************************
00037 // INCLUDES
00038 #include <linux/types.h>
00039 #include <linux/ioctl.h>
00040 
00041 //****************************************************************************
00042 // DEFINES
00043 
00044 //****************************************************************************
00045 // compatibilty defines
00046 #if defined(DWORD) || defined(WORD) || defined(BYTE)
00047 #error "double define for DWORD, WORD, BYTE found"
00048 #endif
00049 
00050 #ifdef __KERNEL__
00051 #define DWORD  u32
00052 #define WORD   u16
00053 #define BYTE   u8
00054 #else
00055 #define DWORD  __u32
00056 #define WORD   __u16
00057 #define BYTE   __u8
00058 #endif
00059 
00060 //****************************************************************************
00061 // parameter wHardwareType, used by open 
00062 #define HW_ISA             1 // not supported with LINUX, 82C200 chip 
00063 #define HW_DONGLE_SJA      5
00064 #define HW_DONGLE_SJA_EPP  6 
00065 #define HW_DONGLE_PRO      7 // not yet supported with LINUX
00066 #define HW_DONGLE_PRO_EPP  8 // not yet supported with LINUX
00067 #define HW_ISA_SJA         9 // use this also for PC/104
00068 #define HW_PCI            10 // PCI carries always SJA1000 chips
00069 #define HW_USB            11 // don't know if this is common over peak products
00070 #define HW_PCCARD         12 // not aligned to other OS
00071 #define HW_USB_PRO        13 
00072 
00073 //****************************************************************************
00074 // mask for standard and extended CAN identifiers
00075 #define CAN_MAX_STANDARD_ID     0x7ff
00076 #define CAN_MAX_EXTENDED_ID     0x1fffffff
00077 
00078 //****************************************************************************
00079 // error codes
00080 #define CAN_ERR_OK             0x0000  // no error
00081 #define CAN_ERR_XMTFULL        0x0001  // transmit buffer full
00082 #define CAN_ERR_OVERRUN        0x0002  // overrun in receive buffer
00083 #define CAN_ERR_BUSLIGHT       0x0004  // bus error, errorcounter limit reached
00084 #define CAN_ERR_BUSHEAVY       0x0008  // bus error, errorcounter limit reached
00085 #define CAN_ERR_BUSOFF         0x0010  // bus error, 'bus off' state entered
00086 #define CAN_ERR_QRCVEMPTY      0x0020  // receive queue is empty
00087 #define CAN_ERR_QOVERRUN       0x0040  // receive queue overrun
00088 #define CAN_ERR_QXMTFULL       0x0080  // transmit queue full 
00089 #define CAN_ERR_REGTEST        0x0100  // test of controller registers failed
00090 #define CAN_ERR_NOVXD          0x0200  // Win95/98/ME only
00091 #define CAN_ERR_RESOURCE       0x2000  // can't create resource
00092 #define CAN_ERR_ILLPARAMTYPE   0x4000  // illegal parameter
00093 #define CAN_ERR_ILLPARAMVAL    0x8000  // value out of range
00094 #define CAN_ERRMASK_ILLHANDLE  0x1C00  // wrong handle, handle error
00095 
00096 //****************************************************************************
00097 // MSGTYPE bits of element MSGTYPE in structure TPCANMsg
00098 #define MSGTYPE_STATUS        0x80     // used to mark a status TPCANMsg
00099 #define MSGTYPE_EXTENDED      0x02     // declares a extended frame
00100 #define MSGTYPE_RTR           0x01     // marks a remote frame
00101 #define MSGTYPE_STANDARD      0x00     // marks a standard frame
00102 
00103 //****************************************************************************
00104 // maximum length of the version string (attention: used in driver too)
00105 #define VERSIONSTRING_LEN     64  
00106 
00107 //****************************************************************************
00108 // structures to communicate via ioctls
00109 typedef struct
00110 {
00111   WORD wBTR0BTR1;        // merged BTR0 and BTR1 register of the SJA1000
00112   BYTE ucCANMsgType;     // 11 or 29 bits - put MSGTYPE_... in here
00113   BYTE ucListenOnly;     // listen only mode when != 0
00114 } TPCANInit;             // for PCAN_INIT
00115 
00116 typedef struct 
00117 {
00118   DWORD ID;              // 11/29 bit code
00119   BYTE  MSGTYPE;         // bits of MSGTYPE_*
00120   BYTE  LEN;             // count of data bytes (0..8)
00121   BYTE  DATA[8];         // data bytes, up to 8
00122 } TPCANMsg;              // for PCAN_WRITE_MSG
00123 
00124 typedef struct
00125 {
00126   TPCANMsg Msg;          // the above message
00127   DWORD    dwTime;       // a timestamp in msec, read only
00128   WORD     wUsec;        // remainder in micro-seconds
00129 } TPCANRdMsg;            // for PCAN_READ_MSG
00130 
00131 typedef struct 
00132 {
00133   WORD  wErrorFlag;      // same as in TPDIAG, is cleared in driver after access
00134   int   nLastError;      // is cleared in driver after access
00135 } TPSTATUS;              // for PCAN_GET_STATUS
00136 
00137 typedef struct
00138 {
00139   WORD  wType;           // the type of interface hardware - see HW_....
00140   DWORD dwBase;          // the base address or port of this device
00141   WORD  wIrqLevel;       // the irq level of this device
00142   DWORD dwReadCounter;   // counts all reads to this device from start
00143   DWORD dwWriteCounter;  // counts all writes
00144   DWORD dwIRQcounter;    // counts all interrupts
00145   DWORD dwErrorCounter;  // counts all errors
00146   WORD  wErrorFlag;      // gathers all errors
00147   int   nLastError;      // the last local error for this device
00148   int   nOpenPaths;      // number of open paths for this device
00149   char  szVersionString[VERSIONSTRING_LEN]; // driver version string
00150 } TPDIAG;                // for PCAN_DIAG, in opposition to PCAN_GET_STATUS nothing is cleared
00151   
00152 typedef struct
00153 {
00154   DWORD dwBitRate;       // in + out, bitrate in bits per second
00155   WORD  wBTR0BTR1;       // out only: the result
00156 } TPBTR0BTR1;
00157 
00158 typedef struct 
00159 {
00160   WORD  wErrorFlag;      // same as in TPDIAG, is cleared in driver after access
00161   int   nLastError;      // is cleared in driver after access
00162   int   nPendingReads;   // count of unread telegrams
00163   int   nPendingWrites;  // count of unsent telegrams
00164 } TPEXTENDEDSTATUS;      // for PCAN_GET_ESTATUS
00165 
00166 typedef struct
00167 {
00168   DWORD FromID;          // First CAN ID to accept
00169   DWORD ToID;            // Last CAN ID to accept
00170   BYTE  MSGTYPE;         // bits of MSGTYPE_*
00171 } TPMSGFILTER;
00172 
00173 //****************************************************************************
00174 // currently available sub-functions
00175 #define SF_GET_SERIALNUMBER 1 // to get the serial number (currently only pcan-usb)
00176 #define SF_SET_SERIALNUMBER 2 // to set the serial number (currently only pcan-usb)
00177 #define SF_GET_HCDEVICENO   3 // request hardcoded device number (currently only pcan-usb)
00178 #define SF_SET_HCDEVICENO   4 // to set hardcoded device number (currently only pcan-usb)
00179 
00180 typedef struct
00181 {
00182   int   nSubFunction;    // a sub-function number SF_... to determine the union element used
00183   union
00184   {
00185     DWORD dwSerialNumber; // to get and set the pcan-usb serial number
00186     BYTE  ucHCDeviceNo;   // only for USB-devices to get or set a hard assigned number
00187   } func;
00188 } TPEXTRAPARAMS;
00189 
00190 //****************************************************************************
00191 // some predefines for ioctls
00192 #define PCAN_MAGIC_NUMBER  'z'
00193 #define MYSEQ_START        0x80
00194 
00195 //****************************************************************************
00196 // ioctls control codes
00197 #define PCAN_INIT           _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START,     TPCANInit)
00198 #define PCAN_WRITE_MSG      _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 1, TPCANMsg)
00199 #define PCAN_READ_MSG       _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 2, TPCANRdMsg)
00200 #define PCAN_GET_STATUS     _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 3, TPSTATUS)
00201 #define PCAN_DIAG           _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 4, TPDIAG)
00202 #define PCAN_BTR0BTR1       _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 5, TPBTR0BTR1)
00203 #define PCAN_GET_EXT_STATUS _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 6, TPEXTENDEDSTATUS)
00204 #define PCAN_MSG_FILTER     _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 7, TPMSGFILTER)
00205 #define PCAN_EXTRA_PARAMS   _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 8, TPEXTRAPARAMS)
00206 
00207 #endif // __PCAN_H__


libpcan
Author(s): Florian Weisshardt
autogenerated on Fri Aug 28 2015 10:21:51