source: pacpussensors/trunk/CanGateway/driver/pcan.h@ 81

Last change on this file since 81 was 1, checked in by DHERBOMEZ Gérald, 11 years ago

ajout des capteurs CanGateway et Alasca

File size: 8.6 KB
Line 
1#ifndef __PCAN_H__
2#define __PCAN_H__
3
4//****************************************************************************
5// Copyright (C) 2001-2010 PEAK System-Technik GmbH
6//
7// linux@peak-system.com
8// www.peak-system.com
9//
10// This program is free software; you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation; either version 2 of the License, or
13// (at your option) any later version.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23//
24// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
25//****************************************************************************
26
27//****************************************************************************
28//
29// pcan.h
30// constants and definitions to access the drivers
31//
32// $Id: pcan.h 615 2010-02-14 22:38:55Z khitschler $
33//
34//****************************************************************************
35
36//****************************************************************************
37// INCLUDES
38#include <linux/types.h>
39#include <linux/ioctl.h>
40
41//****************************************************************************
42// DEFINES
43
44//****************************************************************************
45// compatibilty defines
46#if defined(DWORD) || defined(WORD) || defined(BYTE)
47#error "double define for DWORD, WORD, BYTE found"
48#endif
49
50#ifdef __KERNEL__
51#define DWORD u32
52#define WORD u16
53#define BYTE u8
54#else
55#define DWORD __u32
56#define WORD __u16
57#define BYTE __u8
58#endif
59
60//****************************************************************************
61// parameter wHardwareType, used by open
62#define HW_ISA 1 // not supported with LINUX, 82C200 chip
63#define HW_DONGLE_SJA 5
64#define HW_DONGLE_SJA_EPP 6
65#define HW_DONGLE_PRO 7 // not yet supported with LINUX
66#define HW_DONGLE_PRO_EPP 8 // not yet supported with LINUX
67#define HW_ISA_SJA 9 // use this also for PC/104
68#define HW_PCI 10 // PCI carries always SJA1000 chips
69#define HW_USB 11 // don't know if this is common over peak products
70#define HW_PCCARD 12 // not aligned to other OS
71
72//****************************************************************************
73// mask for standard and extended CAN identifiers
74#define CAN_MAX_STANDARD_ID 0x7ff
75#define CAN_MAX_EXTENDED_ID 0x1fffffff
76
77//****************************************************************************
78// error codes
79#define CAN_ERR_OK 0x0000 // no error
80#define CAN_ERR_XMTFULL 0x0001 // transmit buffer full
81#define CAN_ERR_OVERRUN 0x0002 // overrun in receive buffer
82#define CAN_ERR_BUSLIGHT 0x0004 // bus error, errorcounter limit reached
83#define CAN_ERR_BUSHEAVY 0x0008 // bus error, errorcounter limit reached
84#define CAN_ERR_BUSOFF 0x0010 // bus error, 'bus off' state entered
85#define CAN_ERR_QRCVEMPTY 0x0020 // receive queue is empty
86#define CAN_ERR_QOVERRUN 0x0040 // receive queue overrun
87#define CAN_ERR_QXMTFULL 0x0080 // transmit queue full
88#define CAN_ERR_REGTEST 0x0100 // test of controller registers failed
89#define CAN_ERR_NOVXD 0x0200 // Win95/98/ME only
90#define CAN_ERR_RESOURCE 0x2000 // can't create resource
91#define CAN_ERR_ILLPARAMTYPE 0x4000 // illegal parameter
92#define CAN_ERR_ILLPARAMVAL 0x8000 // value out of range
93#define CAN_ERRMASK_ILLHANDLE 0x1C00 // wrong handle, handle error
94
95//****************************************************************************
96// MSGTYPE bits of element MSGTYPE in structure TPCANMsg
97#define MSGTYPE_STATUS 0x80 // used to mark a status TPCANMsg
98#define MSGTYPE_EXTENDED 0x02 // declares a extended frame
99#define MSGTYPE_RTR 0x01 // marks a remote frame
100#define MSGTYPE_STANDARD 0x00 // marks a standard frame
101
102//****************************************************************************
103// maximum length of the version string (attention: used in driver too)
104#define VERSIONSTRING_LEN 64
105
106//****************************************************************************
107// structures to communicate via ioctls
108typedef struct
109{
110 WORD wBTR0BTR1; // merged BTR0 and BTR1 register of the SJA1000
111 BYTE ucCANMsgType; // 11 or 29 bits - put MSGTYPE_... in here
112 BYTE ucListenOnly; // listen only mode when != 0
113} TPCANInit; // for PCAN_INIT
114
115typedef struct
116{
117 DWORD ID; // 11/29 bit code
118 BYTE MSGTYPE; // bits of MSGTYPE_*
119 BYTE LEN; // count of data bytes (0..8)
120 BYTE DATA[8]; // data bytes, up to 8
121} TPCANMsg; // for PCAN_WRITE_MSG
122
123typedef struct
124{
125 TPCANMsg Msg; // the above message
126 DWORD dwTime; // a timestamp in msec, read only
127 WORD wUsec; // remainder in micro-seconds
128} TPCANRdMsg; // for PCAN_READ_MSG
129
130typedef struct
131{
132 WORD wErrorFlag; // same as in TPDIAG, is cleared in driver after access
133 int nLastError; // is cleared in driver after access
134} TPSTATUS; // for PCAN_GET_STATUS
135
136typedef struct
137{
138 WORD wType; // the type of interface hardware - see HW_....
139 DWORD dwBase; // the base address or port of this device
140 WORD wIrqLevel; // the irq level of this device
141 DWORD dwReadCounter; // counts all reads to this device from start
142 DWORD dwWriteCounter; // counts all writes
143 DWORD dwIRQcounter; // counts all interrupts
144 DWORD dwErrorCounter; // counts all errors
145 WORD wErrorFlag; // gathers all errors
146 int nLastError; // the last local error for this device
147 int nOpenPaths; // number of open paths for this device
148 char szVersionString[VERSIONSTRING_LEN]; // driver version string
149} TPDIAG; // for PCAN_DIAG, in opposition to PCAN_GET_STATUS nothing is cleared
150
151typedef struct
152{
153 DWORD dwBitRate; // in + out, bitrate in bits per second
154 WORD wBTR0BTR1; // out only: the result
155} TPBTR0BTR1;
156
157typedef struct
158{
159 WORD wErrorFlag; // same as in TPDIAG, is cleared in driver after access
160 int nLastError; // is cleared in driver after access
161 int nPendingReads; // count of unread telegrams
162 int nPendingWrites; // count of unsent telegrams
163} TPEXTENDEDSTATUS; // for PCAN_GET_ESTATUS
164
165typedef struct
166{
167 DWORD FromID; // First CAN ID to accept
168 DWORD ToID; // Last CAN ID to accept
169 BYTE MSGTYPE; // bits of MSGTYPE_*
170} TPMSGFILTER;
171
172//****************************************************************************
173// currently available sub-functions
174#define SF_GET_SERIALNUMBER 1 // to get the serial number (currently only pcan-usb)
175#define SF_SET_SERIALNUMBER 2 // to set the serial number (currently only pcan-usb)
176#define SF_GET_HCDEVICENO 3 // request hardcoded device number (currently only pcan-usb)
177#define SF_SET_HCDEVICENO 4 // to set hardcoded device number (currently only pcan-usb)
178
179typedef struct
180{
181 int nSubFunction; // a sub-function number SF_... to determine the union element used
182 union
183 {
184 DWORD dwSerialNumber; // to get and set the pcan-usb serial number
185 BYTE ucHCDeviceNo; // only for USB-devices to get or set a hard assigned number
186 } func;
187} TPEXTRAPARAMS;
188
189//****************************************************************************
190// some predefines for ioctls
191#define PCAN_MAGIC_NUMBER 'z'
192#define MYSEQ_START 0x80
193
194//****************************************************************************
195// ioctls control codes
196#define PCAN_INIT _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START, TPCANInit)
197#define PCAN_WRITE_MSG _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 1, TPCANMsg)
198#define PCAN_READ_MSG _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 2, TPCANRdMsg)
199#define PCAN_GET_STATUS _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 3, TPSTATUS)
200#define PCAN_DIAG _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 4, TPDIAG)
201#define PCAN_BTR0BTR1 _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 5, TPBTR0BTR1)
202#define PCAN_GET_EXT_STATUS _IOR (PCAN_MAGIC_NUMBER, MYSEQ_START + 6, TPEXTENDEDSTATUS)
203#define PCAN_MSG_FILTER _IOW (PCAN_MAGIC_NUMBER, MYSEQ_START + 7, TPMSGFILTER)
204#define PCAN_EXTRA_PARAMS _IOWR(PCAN_MAGIC_NUMBER, MYSEQ_START + 8, TPEXTRAPARAMS)
205
206#endif // __PCAN_H__
Note: See TracBrowser for help on using the repository browser.