00001 #ifndef __PCAN_H__
00002 #define __PCAN_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <linux/types.h>
00039 #include <linux/ioctl.h>
00040
00041
00042
00043
00044
00045
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
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
00072
00073
00074 #define CAN_MAX_STANDARD_ID 0x7ff
00075 #define CAN_MAX_EXTENDED_ID 0x1fffffff
00076
00077
00078
00079 #define CAN_ERR_OK 0x0000 // no error
00080 #define CAN_ERR_XMTFULL 0x0001 // transmit buffer full
00081 #define CAN_ERR_OVERRUN 0x0002 // overrun in receive buffer
00082 #define CAN_ERR_BUSLIGHT 0x0004 // bus error, errorcounter limit reached
00083 #define CAN_ERR_BUSHEAVY 0x0008 // bus error, errorcounter limit reached
00084 #define CAN_ERR_BUSOFF 0x0010 // bus error, 'bus off' state entered
00085 #define CAN_ERR_QRCVEMPTY 0x0020 // receive queue is empty
00086 #define CAN_ERR_QOVERRUN 0x0040 // receive queue overrun
00087 #define CAN_ERR_QXMTFULL 0x0080 // transmit queue full
00088 #define CAN_ERR_REGTEST 0x0100 // test of controller registers failed
00089 #define CAN_ERR_NOVXD 0x0200 // Win95/98/ME only
00090 #define CAN_ERR_RESOURCE 0x2000 // can't create resource
00091 #define CAN_ERR_ILLPARAMTYPE 0x4000 // illegal parameter
00092 #define CAN_ERR_ILLPARAMVAL 0x8000 // value out of range
00093 #define CAN_ERRMASK_ILLHANDLE 0x1C00 // wrong handle, handle error
00094
00095
00096
00097 #define MSGTYPE_STATUS 0x80 // used to mark a status TPCANMsg
00098 #define MSGTYPE_EXTENDED 0x02 // declares a extended frame
00099 #define MSGTYPE_RTR 0x01 // marks a remote frame
00100 #define MSGTYPE_STANDARD 0x00 // marks a standard frame
00101
00102
00103
00104 #define VERSIONSTRING_LEN 64
00105
00106
00107
00108 typedef struct
00109 {
00110 WORD wBTR0BTR1;
00111 BYTE ucCANMsgType;
00112 BYTE ucListenOnly;
00113 } TPCANInit;
00114
00115 typedef struct
00116 {
00117 DWORD ID;
00118 BYTE MSGTYPE;
00119 BYTE LEN;
00120 BYTE DATA[8];
00121 } TPCANMsg;
00122
00123 typedef struct
00124 {
00125 TPCANMsg Msg;
00126 DWORD dwTime;
00127 WORD wUsec;
00128 } TPCANRdMsg;
00129
00130 typedef struct
00131 {
00132 WORD wErrorFlag;
00133 int nLastError;
00134 } TPSTATUS;
00135
00136 typedef struct
00137 {
00138 WORD wType;
00139 DWORD dwBase;
00140 WORD wIrqLevel;
00141 DWORD dwReadCounter;
00142 DWORD dwWriteCounter;
00143 DWORD dwIRQcounter;
00144 DWORD dwErrorCounter;
00145 WORD wErrorFlag;
00146 int nLastError;
00147 int nOpenPaths;
00148 char szVersionString[VERSIONSTRING_LEN];
00149 } TPDIAG;
00150
00151 typedef struct
00152 {
00153 DWORD dwBitRate;
00154 WORD wBTR0BTR1;
00155 } TPBTR0BTR1;
00156
00157 typedef struct
00158 {
00159 WORD wErrorFlag;
00160 int nLastError;
00161 int nPendingReads;
00162 int nPendingWrites;
00163 } TPEXTENDEDSTATUS;
00164
00165 typedef struct
00166 {
00167 DWORD FromID;
00168 DWORD ToID;
00169 BYTE MSGTYPE;
00170 } TPMSGFILTER;
00171
00172
00173
00174 #define SF_GET_SERIALNUMBER 1 // to get the serial number (currently only pcan-usb)
00175 #define SF_SET_SERIALNUMBER 2 // to set the serial number (currently only pcan-usb)
00176 #define SF_GET_HCDEVICENO 3 // request hardcoded device number (currently only pcan-usb)
00177 #define SF_SET_HCDEVICENO 4 // to set hardcoded device number (currently only pcan-usb)
00178
00179 typedef struct
00180 {
00181 int nSubFunction;
00182 union
00183 {
00184 DWORD dwSerialNumber;
00185 BYTE ucHCDeviceNo;
00186 } func;
00187 } TPEXTRAPARAMS;
00188
00189
00190
00191 #define PCAN_MAGIC_NUMBER 'z'
00192 #define MYSEQ_START 0x80
00193
00194
00195
00196 #define PCAN_INIT _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START, TPCANInit)
00197 #define PCAN_WRITE_MSG _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 1, TPCANMsg)
00198 #define PCAN_READ_MSG _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 2, TPCANRdMsg)
00199 #define PCAN_GET_STATUS _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 3, TPSTATUS)
00200 #define PCAN_DIAG _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 4, TPDIAG)
00201 #define PCAN_BTR0BTR1 _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 5, TPBTR0BTR1)
00202 #define PCAN_GET_EXT_STATUS _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 6, TPEXTENDEDSTATUS)
00203 #define PCAN_MSG_FILTER _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 7, TPMSGFILTER)
00204 #define PCAN_EXTRA_PARAMS _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 8, TPEXTRAPARAMS)
00205
00206 #endif // __PCAN_H__