can4linux - the Linux CAN driver
 All Data Structures Files Functions Variables Pages
can4linux.h
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-2011 oe @ port GmbH Halle/Saale
9  * Copyright (c) 2013 Heinz-Jürgen Oertel <hj.oertel@t-online.de>
10  *------------------------------------------------------------------
11  *
12  */
13 
14 
26 #ifndef __CAN_H
27 #define __CAN_H
28 
29 
30 #define CAN4LINUXVERSION 0x0403 /* Version 4.3 */
31 
32 #ifndef __KERNEL__
33 #include <sys/time.h>
34 #endif
35  /*---------- the can message structure */
36 
37 #if defined CANFD
38 # define CAN_MSG_LENGTH 64
39 #else
40 # define CAN_MSG_LENGTH 8
41 #endif
42 
43 
44 /* values of the canmsg.flags field */
45 #define MSG_ACTIVE (0)
46 #define MSG_BASE (0)
47 #define MSG_RTR (1<<0)
48 #define MSG_OVR (1<<1)
49 #define MSG_EXT (1<<2)
50 #define MSG_SELF (1<<3)
51 #define MSG_PASSIVE (1<<4)
52 #define MSG_BUSOFF (1<<5)
53 #define MSG_WARNING (1<<6)
54 #define MSG_BOVR (1<<7)
56 #define MSG_CANFD (1<<8)
57 #define MSG_RESI (1<<9)
61 #define MSG_ERR_MASK (MSG_OVR+MSG_PASSIVE+MSG_BUSOFF+MSG_BOVR+MSG_WARNING)
62 
63 
64 /* valid bits in CAN ID for frame formats */
65 #define CAN_SFF_MASK 0x000007FFU /* base frame format (SFF) */
66 #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
67 #define CANDRIVERERROR 0xFFFFFFFFul /* invalid CAN ID == Error */
68 
76 typedef struct {
78  int flags;
79  int cob;
80  unsigned long id;
84  struct timeval timestamp;
85  short int length;
86  unsigned char data[CAN_MSG_LENGTH];
89 } canmsg_t;
90 
91 
92 
95 /* Use 'c' as magic number, follow chapter 6 of LDD3 */
96 #define CAN4L_IOC_MAGIC 'c'
97 
98 #define CAN_IOCTL_COMMAND 0
99 #define CAN_IOCTL_CONFIG 1
100 #define CAN_IOCTL_SEND 2
101 #define CAN_IOCTL_CONFIGURERTR 4
102 #define CAN_IOCTL_STATUS 5
104 /*---------- CAN ioctl parameter types */
105 
107 struct command_par {
108  int cmd;
109  int target;
110  unsigned long val1;
111  unsigned long val2;
112  int error;
113  unsigned long retval;
114 };
115 
116 
119 typedef struct command_par command_par_t;
122 typedef struct command_par config_par_t;
127 typedef struct can_statuspar {
128  unsigned int baud;
129  unsigned int status;
130  unsigned int error_warning_limit;
131  unsigned int rx_errors;
132  unsigned int tx_errors;
133  unsigned int error_code;
134  unsigned int rx_buffer_size;
135  unsigned int rx_buffer_used;
136  unsigned int tx_buffer_size;
137  unsigned int tx_buffer_used;
138  unsigned long retval;
139  unsigned int type;
141 
144 #define CAN_TYPE_UNSPEC 0
145 #define CAN_TYPE_SJA1000 1
146 #define CAN_TYPE_FlexCAN 2
147 #define CAN_TYPE_TouCAN 3
148 #define CAN_TYPE_82527 4
149 #define CAN_TYPE_TwinCAN 5
150 #define CAN_TYPE_BlackFinCAN 6
151 #define CAN_TYPE_AT91SAM9263 7
152 #define CAN_TYPE_MCP2515 8
153 #define CAN_TYPE_XCANPS 9
154 #define CAN_TYPE_DCAN 10
155 #define CAN_TYPE_IFI_CAN_FD 11
156 #define CAN_TYPE_VIRTUAL 100
157 
158 
161 typedef struct send_par {
163  int error;
164  unsigned long retval;
165 } send_par_t;
166 
169 typedef struct receive_par {
171  int error;
172  unsigned long retval;
173 } receive_par_t;
174 
177 typedef struct configure_rtr_par {
178  unsigned message;
180  int error;
181  unsigned long retval;
183 
187 # define CMD_START 1
188 # define CMD_STOP 2
189 # define CMD_RESET 3
190 # define CMD_CLEARBUFFERS 4
191 # define CMD_CTRL_LED 5 /* on board LEDS */
192 # define CMD_CTRL_TERM 6 /* termination resistor */
193 
194 
195 /* LEDs on Interface Boards (can4linux-examples/canled.c) */
196 enum can_led_color {
197  green = 1,
198  yellow = 2,
199  red = 4
200  };
201 enum can_led_state {
202  off = 0,
203  on
204  };
205 
206 enum can_termination_state {
207  term_off = 0,
208  term_on
209  };
210 
211 
215 # define CONF_ACC 0 /* mask and code */
216 # define CONF_ACCM 1 /* mask only */
217 # define CONF_ACCC 2 /* code only */
218 # define CONF_TIMING 3 /* bit timing */
219 # define CONF_OMODE 4 /* output control register */
220 # define CONF_FILTER 5
221 # define CONF_FENABLE 6
222 # define CONF_FDISABLE 7
223 # define CONF_LISTEN_ONLY_MODE 8 /* for SJA1000 PeliCAN */
224 # define CONF_SELF_RECEPTION 9 /* */
225 # define CONF_BTR 10 /* set direct bit timing registers
226  (SJA1000) */
227 # define CONF_TIMESTAMP 11 /* use TS in received messages */
228 # define CONF_WAKEUP 12 /* wake up processes */
229 # define CONF_SPEEDFACTOR 13 /* speedfactor for CAN-FD second bitrate*/
230 
231 # define CONF_ACC1 100 /* for addidional code/mask settings */
232 # define CONF_ACC2 101 /* for addidional code/mask settings */
233 # define CONF_ACC3 102 /* for addidional code/mask settings */
234 # define CONF_ACC4 103 /* for addidional code/mask settings */
235 # define CONF_ACC5 104 /* for addidional code/mask settings */
236 # define CONF_ACC6 105 /* for addidional code/mask settings */
237 # define CONF_ACC7 106 /* for addidional code/mask settings */
238 
239 #endif /* __CAN_H */
unsigned int type
CAN controller / driver type.
Definition: can4linux.h:139
unsigned message
CAN message ID.
Definition: can4linux.h:178
unsigned long retval
return value
Definition: can4linux.h:164
unsigned int rx_buffer_size
size of rx buffer
Definition: can4linux.h:134
unsigned int status
CAN controller status register.
Definition: can4linux.h:129
unsigned long retval
return value
Definition: can4linux.h:172
canmsg_t * tx
CAN message struct.
Definition: can4linux.h:179
unsigned long val2
Definition: can4linux.h:111
unsigned int tx_errors
content of TX error counter
Definition: can4linux.h:132
unsigned int rx_buffer_used
number of messages
Definition: can4linux.h:135
unsigned int tx_buffer_used
number of messages
Definition: can4linux.h:137
canmsg_t * tx
CAN message struct.
Definition: can4linux.h:162
unsigned long retval
return value
Definition: can4linux.h:113
IOCTL ConfigureRTR request parameter structure.
Definition: can4linux.h:177
unsigned int error_warning_limit
the error warning limit
Definition: can4linux.h:130
unsigned long retval
return value
Definition: can4linux.h:138
int cob
CAN object number, used in Full CAN.
Definition: can4linux.h:79
IOCTL Receive request parameter structure.
Definition: can4linux.h:169
int error
return value for errno
Definition: can4linux.h:163
unsigned long retval
return value
Definition: can4linux.h:181
unsigned long id
CAN message ID, 4 bytes if in receive mode an id 0xFFFF.FFFF is received...
Definition: can4linux.h:80
IOCTL Command request parameter structure.
Definition: can4linux.h:107
int cmd
special driver command
Definition: can4linux.h:108
short int length
number of bytes in the CAN message
Definition: can4linux.h:85
IOCTL generic CAN controller status request parameter structure.
Definition: can4linux.h:127
unsigned int rx_errors
content of RX error counter
Definition: can4linux.h:131
unsigned long val1
Definition: can4linux.h:110
unsigned int tx_buffer_size
size of tx buffer
Definition: can4linux.h:136
int error
return value
Definition: can4linux.h:112
unsigned int error_code
content of error code register
Definition: can4linux.h:133
int error
return value for errno
Definition: can4linux.h:171
int target
special configuration target
Definition: can4linux.h:109
canmsg_t * rx
CAN message struct.
Definition: can4linux.h:170
int error
return value for errno
Definition: can4linux.h:180
unsigned int baud
actual bit rate
Definition: can4linux.h:128
IOCTL Send request parameter structure.
Definition: can4linux.h:161
int flags
flags, indicating or controlling special message properties
Definition: can4linux.h:78
The CAN message structure.
Definition: can4linux.h:76