|
1 /* |
|
2 * can4linux.h - can4linux CAN driver module |
|
3 * |
|
4 * This file is subject to the terms and conditions of the GNU General Public |
|
5 * License. See the file "COPYING" in the main directory of this archive |
|
6 * for more details. |
|
7 * |
|
8 * Copyright (c) 2001 port GmbH Halle/Saale |
|
9 *------------------------------------------------------------------ |
|
10 * $Header$ |
|
11 * |
|
12 *-------------------------------------------------------------------------- |
|
13 * |
|
14 * |
|
15 * modification history |
|
16 * -------------------- |
|
17 * $Log$ |
|
18 * Revision 1.1 2008-01-22 09:27:13 groke6 |
|
19 * Added can4linux driver support. |
|
20 * |
|
21 * Revision 1.1 2004/08/12 10:14:31 jschoew |
|
22 * add can4linux examples |
|
23 * |
|
24 * Revision 1.5 2004/05/14 10:02:54 oe |
|
25 * - started supporting CPC-Card |
|
26 * - version number in can4linux.h available |
|
27 * - only one structure type for Config_par_t Command_par_t |
|
28 * - new ioctl command CMD_CLEARBUFFERS |
|
29 * |
|
30 * Revision 1.4 2003/08/27 17:49:04 oe |
|
31 * - New CanStatusPar structure |
|
32 * |
|
33 * Revision 1.3 2002/08/20 05:57:22 oe |
|
34 * - new write() handling, now not ovrwriting buffer content if buffer fill |
|
35 * - ioctl() get status returns buffer information |
|
36 * |
|
37 * Revision 1.2 2002/08/08 17:50:46 oe |
|
38 * - MSG_ERR_MASK extended |
|
39 * |
|
40 * Revision 1.1 2002/01/10 19:13:19 oe |
|
41 * - application header file changed name can.h -> can4linux.h |
|
42 * |
|
43 * Revision 1.2 2001/09/14 14:58:09 oe |
|
44 * first free release |
|
45 * |
|
46 * Revision 1.1.1.1 2001/06/11 18:30:54 oe |
|
47 * minimal version can4linux embedded, compile time Konfigurierbar |
|
48 * |
|
49 * |
|
50 * |
|
51 * |
|
52 *-------------------------------------------------------------------------- |
|
53 */ |
|
54 |
|
55 /** |
|
56 * \file can.h |
|
57 * \author Heinz-Jrgen Oertel, port GmbH |
|
58 * $Revision$ |
|
59 * $Date$ |
|
60 * |
|
61 * can4linux interface definitions |
|
62 * |
|
63 * |
|
64 * |
|
65 */ |
|
66 |
|
67 |
|
68 #ifndef __CAN_H |
|
69 #define __CAN_H |
|
70 |
|
71 #ifdef __cplusplus |
|
72 extern "C" { |
|
73 #endif |
|
74 |
|
75 |
|
76 #define CAN4LINUXVERSION 0x0301 /*(Version 3.1)*/ |
|
77 |
|
78 #ifndef __KERNEL__ |
|
79 #include <sys/time.h> |
|
80 #endif |
|
81 /*---------- the can message structure */ |
|
82 |
|
83 #define CAN_MSG_LENGTH 8 /**< maximum length of a CAN frame */ |
|
84 |
|
85 |
|
86 #define MSG_RTR (1<<0) /**< RTR Message */ |
|
87 #define MSG_OVR (1<<1) /**< CAN controller Msg overflow error */ |
|
88 #define MSG_EXT (1<<2) /**< extended message format */ |
|
89 #define MSG_PASSIVE (1<<4) /**< controller in error passive */ |
|
90 #define MSG_BUSOFF (1<<5) /**< controller Bus Off */ |
|
91 #define MSG_ (1<<6) /**< */ |
|
92 #define MSG_BOVR (1<<7) /**< receive/transmit buffer overflow */ |
|
93 /** |
|
94 * mask used for detecting CAN errors in the canmsg_t flags field |
|
95 */ |
|
96 #define MSG_ERR_MASK (MSG_OVR + MSG_PASSIVE + MSG_BUSOFF + MSG_BOVR) |
|
97 |
|
98 /** |
|
99 * The CAN message structure. |
|
100 * Used for all data transfers between the application and the driver |
|
101 * using read() or write(). |
|
102 */ |
|
103 typedef struct { |
|
104 /** flags, indicating or controlling special message properties */ |
|
105 int flags; |
|
106 int cob; /**< CAN object number, used in Full CAN */ |
|
107 unsigned long id; /**< CAN message ID, 4 bytes */ |
|
108 struct timeval timestamp; /**< time stamp for received messages */ |
|
109 short int length; /**< number of bytes in the CAN message */ |
|
110 unsigned char data[CAN_MSG_LENGTH]; /**< data, 0...8 bytes */ |
|
111 } canmsg_t; |
|
112 |
|
113 |
|
114 |
|
115 /** |
|
116 ---------- IOCTL requests */ |
|
117 |
|
118 #define COMMAND 0 /**< IOCTL command request */ |
|
119 #define CONFIG 1 /**< IOCTL configuration request */ |
|
120 #define SEND 2 /**< IOCTL request */ |
|
121 #define RECEIVE 3 /**< IOCTL request */ |
|
122 #define CONFIGURERTR 4 /**< IOCTL request */ |
|
123 #define STATUS 5 /**< IOCTL status request */ |
|
124 |
|
125 /*---------- CAN ioctl parameter types */ |
|
126 /** |
|
127 IOCTL Command request parameter structure */ |
|
128 struct Command_par { |
|
129 int cmd; /**< special driver command */ |
|
130 int target; /**< special configuration target */ |
|
131 unsigned long val1; /**< 1. parameter for the target */ |
|
132 unsigned long val2; /**< 2. parameter for the target */ |
|
133 int error; /**< return value */ |
|
134 unsigned long retval; /**< return value */ |
|
135 }; |
|
136 |
|
137 |
|
138 typedef struct Command_par Command_par_t ; |
|
139 /** |
|
140 PSW made them all the same |
|
141 IOCTL Configuration request parameter structure */ |
|
142 typedef struct Command_par Config_par_t ; |
|
143 |
|
144 |
|
145 /** |
|
146 IOCTL generic CAN controller status request parameter structure */ |
|
147 typedef struct CanStatusPar { |
|
148 unsigned int baud; /**< actual bit rate */ |
|
149 unsigned int status; /**< CAN controller status register */ |
|
150 unsigned int error_warning_limit; /**< the error warning limit */ |
|
151 unsigned int rx_errors; /**< content of RX error counter */ |
|
152 unsigned int tx_errors; /**< content of TX error counter */ |
|
153 unsigned int error_code; /**< content of error code register */ |
|
154 unsigned int rx_buffer_size; /**< size of rx buffer */ |
|
155 unsigned int rx_buffer_used; /**< number of messages */ |
|
156 unsigned int tx_buffer_size; /**< size of tx buffer */ |
|
157 unsigned int tx_buffer_used; /**< number of messages */ |
|
158 unsigned long retval; /**< return value */ |
|
159 unsigned int type; /**< CAN controller / driver type */ |
|
160 } CanStatusPar_t; |
|
161 |
|
162 /** |
|
163 IOCTL CanStatusPar.type CAN controller hardware chips */ |
|
164 #define CAN_TYPE_UNSPEC 0 |
|
165 #define CAN_TYPE_SJA1000 1 |
|
166 #define CAN_TYPE_FlexCAN 2 |
|
167 #define CAN_TYPE_TouCAN 3 |
|
168 #define CAN_TYPE_82527 4 |
|
169 #define CAN_TYPE_TwinCAN 5 |
|
170 |
|
171 |
|
172 /** |
|
173 IOCTL Send request parameter structure */ |
|
174 typedef struct Send_par { |
|
175 canmsg_t *Tx; /**< CAN message struct */ |
|
176 int error; /**< return value for errno */ |
|
177 unsigned long retval; /**< return value */ |
|
178 } Send_par_t ; |
|
179 |
|
180 /** |
|
181 IOCTL Receive request parameter structure */ |
|
182 typedef struct Receive_par { |
|
183 canmsg_t *Rx; /**< CAN message struct */ |
|
184 int error; /**< return value for errno */ |
|
185 unsigned long retval; /**< return value */ |
|
186 } Receive_par_t ; |
|
187 |
|
188 /** |
|
189 IOCTL ConfigureRTR request parameter structure */ |
|
190 typedef struct ConfigureRTR_par { |
|
191 unsigned message; /**< CAN message ID */ |
|
192 canmsg_t *Tx; /**< CAN message struct */ |
|
193 int error; /**< return value for errno */ |
|
194 unsigned long retval; /**< return value */ |
|
195 } ConfigureRTR_par_t ; |
|
196 |
|
197 /** |
|
198 ---------- IOCTL Command subcommands and there targets */ |
|
199 |
|
200 # define CMD_START 1 |
|
201 # define CMD_STOP 2 |
|
202 # define CMD_RESET 3 |
|
203 # define CMD_CLEARBUFFERS 4 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 /** |
|
209 ---------- IOCTL Configure targets */ |
|
210 |
|
211 # define CONF_ACC 0 /* mask and code */ |
|
212 # define CONF_ACCM 1 /* mask only */ |
|
213 # define CONF_ACCC 2 /* code only */ |
|
214 # define CONF_TIMING 3 /* bit timing */ |
|
215 # define CONF_OMODE 4 /* output control register */ |
|
216 # define CONF_FILTER 5 |
|
217 # define CONF_FENABLE 6 |
|
218 # define CONF_FDISABLE 7 |
|
219 |
|
220 #ifdef __cplusplus |
|
221 } |
|
222 #endif |
|
223 |
|
224 #endif /* __CAN_H */ |