serial core: fix new kernel-doc warnings
[linux/fpc-iii.git] / drivers / staging / cpc-usb / cpc.h
blobb2fda5d14c1d878301ac711381b09d2da058b840
1 /*
2 * CPC CAN Interface Definitions
4 * Copyright (C) 2000-2008 EMS Dr. Thomas Wuensche
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 */
10 #ifndef CPC_HEADER
11 #define CPC_HEADER
14 * the maximum length of the union members within a CPC_MSG
15 * this value can be defined by the customer, but has to be
16 * >= 64 bytes
17 * however, if not defined before, we set a length of 64 byte
19 #if !defined(CPC_MSG_LEN) || (CPC_MSG_LEN < 64)
20 #undef CPC_MSG_LEN
21 #define CPC_MSG_LEN 64
22 #endif
25 * Transmission of events from CPC interfaces to PC can be individually
26 * controlled per event type. Default state is: don't transmit
27 * Control values are constructed by bit-or of Subject and Action
28 * and passed to CPC_Control()
31 /* Control-Values for CPC_Control() Command Subject Selection */
32 #define CONTR_CAN_Message 0x04
33 #define CONTR_Busload 0x08
34 #define CONTR_CAN_State 0x0C
35 #define CONTR_SendAck 0x10
36 #define CONTR_Filter 0x14
37 #define CONTR_CmdQueue 0x18 /* reserved, do not use */
38 #define CONTR_BusError 0x1C
40 /* Control Command Actions */
41 #define CONTR_CONT_OFF 0
42 #define CONTR_CONT_ON 1
43 #define CONTR_SING_ON 2
45 * CONTR_SING_ON doesn't change CONTR_CONT_ON state, so it should be
46 * read as: transmit at least once
49 /* defines for confirmed request */
50 #define DO_NOT_CONFIRM 0
51 #define DO_CONFIRM 1
53 /* event flags */
54 #define EVENT_READ 0x01
55 #define EVENT_WRITE 0x02
58 * Messages from CPC to PC contain a message object type field.
59 * The following message types are sent by CPC and can be used in
60 * handlers, others should be ignored.
62 #define CPC_MSG_T_RESYNC 0 /* Normally to be ignored */
63 #define CPC_MSG_T_CAN 1 /* CAN data frame */
64 #define CPC_MSG_T_BUSLOAD 2 /* Busload message */
65 #define CPC_MSG_T_STRING 3 /* Normally to be ignored */
66 #define CPC_MSG_T_CONTI 4 /* Normally to be ignored */
67 #define CPC_MSG_T_MEM 7 /* Normally not to be handled */
68 #define CPC_MSG_T_RTR 8 /* CAN remote frame */
69 #define CPC_MSG_T_TXACK 9 /* Send acknowledge */
70 #define CPC_MSG_T_POWERUP 10 /* Power-up message */
71 #define CPC_MSG_T_CMD_NO 11 /* Normally to be ignored */
72 #define CPC_MSG_T_CAN_PRMS 12 /* Actual CAN parameters */
73 #define CPC_MSG_T_ABORTED 13 /* Command aborted message */
74 #define CPC_MSG_T_CANSTATE 14 /* CAN state message */
75 #define CPC_MSG_T_RESET 15 /* used to reset CAN-Controller */
76 #define CPC_MSG_T_XCAN 16 /* XCAN data frame */
77 #define CPC_MSG_T_XRTR 17 /* XCAN remote frame */
78 #define CPC_MSG_T_INFO 18 /* information strings */
79 #define CPC_MSG_T_CONTROL 19 /* used for control of interface/driver behaviour */
80 #define CPC_MSG_T_CONFIRM 20 /* response type for confirmed requests */
81 #define CPC_MSG_T_OVERRUN 21 /* response type for overrun conditions */
82 #define CPC_MSG_T_KEEPALIVE 22 /* response type for keep alive conditions */
83 #define CPC_MSG_T_CANERROR 23 /* response type for bus error conditions */
84 #define CPC_MSG_T_DISCONNECTED 24 /* response type for a disconnected interface */
85 #define CPC_MSG_T_ERR_COUNTER 25 /* RX/TX error counter of CAN controller */
87 #define CPC_MSG_T_FIRMWARE 100 /* response type for USB firmware download */
90 * Messages from the PC to the CPC interface contain a command field
91 * Most of the command types are wrapped by the library functions and have therefore
92 * normally not to be used.
93 * However, programmers who wish to circumvent the library and talk directly
94 * to the drivers (mainly Linux programmers) can use the following
95 * command types:
97 #define CPC_CMD_T_CAN 1 /* CAN data frame */
98 #define CPC_CMD_T_CONTROL 3 /* used for control of interface/driver behaviour */
99 #define CPC_CMD_T_CAN_PRMS 6 /* set CAN parameters */
100 #define CPC_CMD_T_CLEARBUF 8 /* clears input queue; this is depricated, use CPC_CMD_T_CLEAR_MSG_QUEUE instead */
101 #define CPC_CMD_T_INQ_CAN_PARMS 11 /* inquire actual CAN parameters */
102 #define CPC_CMD_T_FILTER_PRMS 12 /* set filter parameter */
103 #define CPC_CMD_T_RTR 13 /* CAN remote frame */
104 #define CPC_CMD_T_CANSTATE 14 /* CAN state message */
105 #define CPC_CMD_T_XCAN 15 /* XCAN data frame */
106 #define CPC_CMD_T_XRTR 16 /* XCAN remote frame */
107 #define CPC_CMD_T_RESET 17 /* used to reset CAN-Controller */
108 #define CPC_CMD_T_INQ_INFO 18 /* miscellanous information strings */
109 #define CPC_CMD_T_OPEN_CHAN 19 /* open a channel */
110 #define CPC_CMD_T_CLOSE_CHAN 20 /* close a channel */
111 #define CPC_CMD_T_CNTBUF 21 /* this is depricated, use CPC_CMD_T_INQ_MSG_QUEUE_CNT instead */
112 #define CPC_CMD_T_CAN_EXIT 200 /* exit the CAN (disable interrupts; reset bootrate; reset output_cntr; mode = 1) */
114 #define CPC_CMD_T_INQ_MSG_QUEUE_CNT CPC_CMD_T_CNTBUF /* inquires the count of elements in the message queue */
115 #define CPC_CMD_T_INQ_ERR_COUNTER 25 /* request the CAN controllers error counter */
116 #define CPC_CMD_T_CLEAR_MSG_QUEUE CPC_CMD_T_CLEARBUF /* clear CPC_MSG queue */
117 #define CPC_CMD_T_CLEAR_CMD_QUEUE 28 /* clear CPC_CMD queue */
118 #define CPC_CMD_T_FIRMWARE 100 /* reserved, must not be used */
119 #define CPC_CMD_T_USB_RESET 101 /* reserved, must not be used */
120 #define CPC_CMD_T_WAIT_NOTIFY 102 /* reserved, must not be used */
121 #define CPC_CMD_T_WAIT_SETUP 103 /* reserved, must not be used */
122 #define CPC_CMD_T_ABORT 255 /* Normally not to be used */
124 /* definitions for CPC_MSG_T_INFO information sources */
125 #define CPC_INFOMSG_T_UNKNOWN_SOURCE 0
126 #define CPC_INFOMSG_T_INTERFACE 1
127 #define CPC_INFOMSG_T_DRIVER 2
128 #define CPC_INFOMSG_T_LIBRARY 3
130 /* information types */
131 #define CPC_INFOMSG_T_UNKNOWN_TYPE 0
132 #define CPC_INFOMSG_T_VERSION 1
133 #define CPC_INFOMSG_T_SERIAL 2
135 /* definitions for controller types */
136 #define PCA82C200 1 /* Philips basic CAN controller, replaced by SJA1000 */
137 #define SJA1000 2 /* Philips basic CAN controller */
138 #define AN82527 3 /* Intel full CAN controller */
139 #define M16C_BASIC 4 /* M16C controller running in basic CAN (not full CAN) mode */
141 /* channel open error codes */
142 #define CPC_ERR_NO_FREE_CHANNEL -1 /* no more free space within the channel array */
143 #define CPC_ERR_CHANNEL_ALREADY_OPEN -2 /* the channel is already open */
144 #define CPC_ERR_CHANNEL_NOT_ACTIVE -3 /* access to a channel not active failed */
145 #define CPC_ERR_NO_DRIVER_PRESENT -4 /* no driver at the location searched by the library */
146 #define CPC_ERR_NO_INIFILE_PRESENT -5 /* the library could not find the inifile */
147 #define CPC_ERR_WRONG_PARAMETERS -6 /* wrong parameters in the inifile */
148 #define CPC_ERR_NO_INTERFACE_PRESENT -7 /* 1. The specified interface is not connected */
149 /* 2. The interface (mostly CPC-USB) was disconnected upon operation */
150 #define CPC_ERR_NO_MATCHING_CHANNEL -8 /* the driver couldn't find a matching channel */
151 #define CPC_ERR_NO_BUFFER_AVAILABLE -9 /* the driver couldn't allocate buffer for messages */
152 #define CPC_ERR_NO_INTERRUPT -10 /* the requested interrupt couldn't be claimed */
153 #define CPC_ERR_NO_MATCHING_INTERFACE -11 /* no interface type related to this channel was found */
154 #define CPC_ERR_NO_RESOURCES -12 /* the requested resources could not be claimed */
155 #define CPC_ERR_SOCKET -13 /* error concerning TCP sockets */
157 /* init error codes */
158 #define CPC_ERR_WRONG_CONTROLLER_TYPE -14 /* wrong CAN controller type within initialization */
159 #define CPC_ERR_NO_RESET_MODE -15 /* the controller could not be set into reset mode */
160 #define CPC_ERR_NO_CAN_ACCESS -16 /* the CAN controller could not be accessed */
162 /* transmit error codes */
163 #define CPC_ERR_CAN_WRONG_ID -20 /* the provided CAN id is too big */
164 #define CPC_ERR_CAN_WRONG_LENGTH -21 /* the provided CAN length is too long */
165 #define CPC_ERR_CAN_NO_TRANSMIT_BUF -22 /* the transmit buffer was occupied */
166 #define CPC_ERR_CAN_TRANSMIT_TIMEOUT -23 /* The message could not be sent within a */
167 /* specified time */
169 /* other error codes */
170 #define CPC_ERR_SERVICE_NOT_SUPPORTED -30 /* the requested service is not supported by the interface */
171 #define CPC_ERR_IO_TRANSFER -31 /* a transmission error down to the driver occurred */
172 #define CPC_ERR_TRANSMISSION_FAILED -32 /* a transmission error down to the interface occurred */
173 #define CPC_ERR_TRANSMISSION_TIMEOUT -33 /* a timeout occurred within transmission to the interface */
174 #define CPC_ERR_OP_SYS_NOT_SUPPORTED -35 /* the operating system is not supported */
175 #define CPC_ERR_UNKNOWN -40 /* an unknown error ocurred (mostly IOCTL errors) */
177 #define CPC_ERR_LOADING_DLL -50 /* the library 'cpcwin.dll' could not be loaded */
178 #define CPC_ERR_ASSIGNING_FUNCTION -51 /* the specified function could not be assigned */
179 #define CPC_ERR_DLL_INITIALIZATION -52 /* the DLL was not initialized correctly */
180 #define CPC_ERR_MISSING_LICFILE -55 /* the file containing the licenses does not exist */
181 #define CPC_ERR_MISSING_LICENSE -56 /* a required license was not found */
183 /* CAN state bit values. Ignore any bits not listed */
184 #define CPC_CAN_STATE_BUSOFF 0x80
185 #define CPC_CAN_STATE_ERROR 0x40
187 /* Mask to help ignore undefined bits */
188 #define CPC_CAN_STATE_MASK 0xc0
191 * CAN-Message representation in a CPC_MS
192 * Message object type is CPC_MSG_T_CAN or CPC_MSG_T_RTR
193 * or CPC_MSG_T_XCAN or CPC_MSG_T_XRTR
195 typedef struct CPC_CAN_MSG {
196 u32 id;
197 u8 length;
198 u8 msg[8];
199 } CPC_CAN_MSG_T;
201 /* representation of the CAN parameters for the PCA82C200 controller */
202 typedef struct CPC_PCA82C200_PARAMS {
203 u8 acc_code; /* Acceptance-code for receive, Standard: 0 */
204 u8 acc_mask; /* Acceptance-mask for receive, Standard: 0xff (everything) */
205 u8 btr0; /* Bus-timing register 0 */
206 u8 btr1; /* Bus-timing register 1 */
207 u8 outp_contr; /* Output-control register */
208 } CPC_PCA82C200_PARAMS_T;
210 /* representation of the CAN parameters for the SJA1000 controller */
211 typedef struct CPC_SJA1000_PARAMS {
212 u8 mode; /* enables single or dual acceptance filtering */
213 u8 acc_code0; /* Acceptance-code for receive, Standard: 0 */
214 u8 acc_code1;
215 u8 acc_code2;
216 u8 acc_code3;
217 u8 acc_mask0; /* Acceptance-mask for receive, Standard: 0xff (everything) */
218 u8 acc_mask1;
219 u8 acc_mask2;
220 u8 acc_mask3;
221 u8 btr0; /* Bus-timing register 0 */
222 u8 btr1; /* Bus-timing register 1 */
223 u8 outp_contr; /* Output-control register */
224 } CPC_SJA1000_PARAMS_T;
227 * representation of the CAN parameters for the M16C controller
228 * in basic CAN mode (means no full CAN)
230 typedef struct CPC_M16C_BASIC_PARAMS {
231 u8 con0;
232 u8 con1;
233 u8 ctlr0;
234 u8 ctlr1;
235 u8 clk;
236 u8 acc_std_code0;
237 u8 acc_std_code1;
238 u8 acc_ext_code0;
239 u8 acc_ext_code1;
240 u8 acc_ext_code2;
241 u8 acc_ext_code3;
242 u8 acc_std_mask0;
243 u8 acc_std_mask1;
244 u8 acc_ext_mask0;
245 u8 acc_ext_mask1;
246 u8 acc_ext_mask2;
247 u8 acc_ext_mask3;
248 } CPC_M16C_BASIC_PARAMS_T;
250 /* CAN params message representation */
251 typedef struct CPC_CAN_PARAMS {
252 u8 cc_type; /* represents the controller type */
253 union {
254 CPC_M16C_BASIC_PARAMS_T m16c_basic;
255 CPC_SJA1000_PARAMS_T sja1000;
256 CPC_PCA82C200_PARAMS_T pca82c200;
257 } cc_params;
258 } CPC_CAN_PARAMS_T;
260 /* CHAN init params representation */
261 typedef struct CPC_CHAN_PARAMS {
262 int fd;
263 } CPC_CHAN_PARAMS_T;
265 /* CAN init params message representation */
266 typedef struct CPC_INIT_PARAMS {
267 CPC_CHAN_PARAMS_T chanparams;
268 CPC_CAN_PARAMS_T canparams;
269 } CPC_INIT_PARAMS_T;
271 /* structure for confirmed message handling */
272 typedef struct CPC_CONFIRM {
273 u8 result; /* error code */
274 } CPC_CONFIRM_T;
276 /* structure for information requests */
277 typedef struct CPC_INFO {
278 u8 source; /* interface, driver or library */
279 u8 type; /* version or serial number */
280 char msg[CPC_MSG_LEN - 2]; /* string holding the requested information */
281 } CPC_INFO_T;
284 * OVERRUN
285 * In general two types of overrun may occur.
286 * A hardware overrun, where the CAN controller
287 * lost a message, because the interrupt was
288 * not handled before the next messgae comes in.
289 * Or a software overrun, where i.e. a received
290 * message could not be stored in the CPC_MSG
291 * buffer.
294 /* After a software overrun has occurred
295 * we wait until we have CPC_OVR_GAP slots
296 * free in the CPC_MSG buffer.
298 #define CPC_OVR_GAP 10
301 * Two types of software overrun may occur.
302 * A received CAN message or a CAN state event
303 * can cause an overrun.
304 * Note: A CPC_CMD which would normally store
305 * its result immediately in the CPC_MSG
306 * queue may fail, because the message queue is full.
307 * This will not generate an overrun message, but
308 * will halt command execution, until this command
309 * is able to store its message in the message queue.
311 #define CPC_OVR_EVENT_CAN 0x01
312 #define CPC_OVR_EVENT_CANSTATE 0x02
313 #define CPC_OVR_EVENT_BUSERROR 0x04
316 * If the CAN controller lost a message
317 * we indicate it with the highest bit
318 * set in the count field.
320 #define CPC_OVR_HW 0x80
322 /* structure for overrun conditions */
323 typedef struct {
324 u8 event;
325 u8 count;
326 } CPC_OVERRUN_T;
329 * CAN errors
330 * Each CAN controller type has different
331 * registers to record errors.
332 * Therefor a structure containing the specific
333 * errors is set up for each controller here
337 * SJA1000 error structure
338 * see the SJA1000 datasheet for detailed
339 * explanation of the registers
341 typedef struct CPC_SJA1000_CAN_ERROR {
342 u8 ecc; /* error capture code register */
343 u8 rxerr; /* RX error counter register */
344 u8 txerr; /* TX error counter register */
345 } CPC_SJA1000_CAN_ERROR_T;
348 * M16C error structure
349 * see the M16C datasheet for detailed
350 * explanation of the registers
352 typedef struct CPC_M16C_CAN_ERROR {
353 u8 tbd; /* to be defined */
354 } CPC_M16C_CAN_ERROR_T;
356 /* structure for CAN error conditions */
357 #define CPC_CAN_ECODE_ERRFRAME 0x01
358 typedef struct CPC_CAN_ERROR {
359 u8 ecode;
360 struct {
361 u8 cc_type; /* CAN controller type */
362 union {
363 CPC_SJA1000_CAN_ERROR_T sja1000;
364 CPC_M16C_CAN_ERROR_T m16c;
365 } regs;
366 } cc;
367 } CPC_CAN_ERROR_T;
370 * Structure containing RX/TX error counter.
371 * This structure is used to request the
372 * values of the CAN controllers TX and RX
373 * error counter.
375 typedef struct CPC_CAN_ERR_COUNTER {
376 u8 rx;
377 u8 tx;
378 } CPC_CAN_ERR_COUNTER_T;
380 /* If this flag is set, transmissions from PC to CPC are protected against loss */
381 #define CPC_SECURE_TO_CPC 0x01
383 /* If this flag is set, transmissions from CPC to PC are protected against loss */
384 #define CPC_SECURE_TO_PC 0x02
386 /* If this flag is set, the CAN-transmit buffer is checked to be free before sending a message */
387 #define CPC_SECURE_SEND 0x04
390 * If this flag is set, the transmission complete flag is checked
391 * after sending a message
392 * THIS IS CURRENTLY ONLY IMPLEMENTED IN THE PASSIVE INTERFACE DRIVERS
394 #define CPC_SECURE_TRANSMIT 0x08
396 /* main message type used between library and application */
397 typedef struct CPC_MSG {
398 u8 type; /* type of message */
399 u8 length; /* length of data within union 'msg' */
400 u8 msgid; /* confirmation handle */
401 u32 ts_sec; /* timestamp in seconds */
402 u32 ts_nsec; /* timestamp in nano seconds */
403 union {
404 u8 generic[CPC_MSG_LEN];
405 CPC_CAN_MSG_T canmsg;
406 CPC_CAN_PARAMS_T canparams;
407 CPC_CONFIRM_T confirmation;
408 CPC_INFO_T info;
409 CPC_OVERRUN_T overrun;
410 CPC_CAN_ERROR_T error;
411 CPC_CAN_ERR_COUNTER_T err_counter;
412 u8 busload;
413 u8 canstate;
414 } msg;
415 } CPC_MSG_T;
417 #endif /* CPC_HEADER */