summaryrefslogtreecommitdiffstats
path: root/include/socket-can/can.h
blob: 126caee18834d7e9a9b8849827b66e959b21ab69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * can.h (userspace)
 *
 * Copyright (C) 2004, 2005
 *
 * - Robert Schwebel, Benedikt Spranger, Marc Kleine-Budde, Pengutronix
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the version 2 of the GNU General Public License 
 * as published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _SOCKET_CAN_CAN_H
#define _SOCKET_CAN_CAN_H

//#include <stdint.h>

#define CAN_ID_EXT_MASK   0x1FFFFFFF	/* contains CAN id */
#define CAN_ID_STD_MASK   0x000007FF
#define CAN_FLAG_ALL      0x20000000	/* filter all messages */
#define CAN_FLAG_RTR      0x40000000	/* remote transmission flag*/
#define CAN_FLAG_EXTENDED 0x80000000	/* extended frame */

#define SIOCSCANBAUDRATE	(SIOCPROTOPRIVATE + 0)
#define SIOCGCANBAUDRATE	(SIOCPROTOPRIVATE + 1)
#define SIOCSCANMODE		(SIOCPROTOPRIVATE + 2)
#define SIOCGCANSTATE		(SIOCPROTOPRIVATE + 3)


enum CAN_BAUD {
   /*!
   ** Baudrate 10 kBit/sec
   */
   CAN_BAUD_10K = 0,

   /*!
   ** Baudrate 20 kBit/sec
   */
   CAN_BAUD_20K,

   /*!
   ** Baudrate 50 kBit/sec
   */
   CAN_BAUD_50K,

   /*!
   ** Baudrate 100 kBit/sec
   */
   CAN_BAUD_100K,

   /*!
   ** Baudrate 125 kBit/sec
   */
   CAN_BAUD_125K,

   /*!
   ** Baudrate 250 kBit/sec
   */
   CAN_BAUD_250K,

   /*!
   ** Baudrate 500 kBit/sec
   */
   CAN_BAUD_500K,

   /*!
   ** Baudrate 800 kBit/sec
   */
   CAN_BAUD_800K,

   /*!
   ** Baudrate 1 MBit/sec
   */
   CAN_BAUD_1M,

   /*!
   ** Max value, beside CAN_BAUD_BTR
   */
   CAN_BAUD_MAX,

   /*!
   ** Use values for btr0, btr1 and btr2
   */
   CAN_BAUD_BTR = 0x80,
};


enum CAN_MODE {
   /*!   Set controller in Stop mode (no reception / transmission possible)
   */
   CAN_MODE_STOP = 0,

   /*!   Set controller into normal operation
   */
   CAN_MODE_START,

   /*!	Start Autobaud Detection
   */
   CAN_MODE_AUTO_BAUD,
   /*!	Set controller into Sleep mode
   */
   CAN_MODE_SLEEP
};


enum CAN_STATE {
	/*!
	**	CAN controller is active, no errors
	*/
	CAN_STATE_ACTIVE    = 0,

	/*!
	**	CAN controller is in stopped mode
	*/
	CAN_STATE_STOPPED,

	/*!
	**	CAN controller is in Sleep mode
	*/
	CAN_STATE_SLEEPING,

	/*!
	**	CAN controller is active, warning level is reached
	*/
	CAN_STATE_BUS_WARN  = 6,

 	/*!
	**	CAN controller is error passive
	*/
	CAN_STATE_BUS_PASSIVE,

	/*!
	**	CAN controller went into Bus Off
	*/
	CAN_STATE_BUS_OFF,

	/*!
	**	General failure of physical layer detected (if supported by hardware)
	*/
	CAN_STATE_PHY_FAULT = 10,

	/*!
	**	Fault on CAN-H detected (Low Speed CAN)
	*/
	CAN_STATE_PHY_H,

	/*!
	**	Fault on CAN-L detected (Low Speed CAN)
	*/
	CAN_STATE_PHY_L,

	CAN_STATE_ERR_BIT   = 0x10,
	CAN_STATE_ERR_STUFF = 0x20,
	CAN_STATE_ERR_FORM  = 0x30,
	CAN_STATE_ERR_CRC   = 0x40,
	CAN_STATE_ERR_ACK   = 0x50
};


struct can_baudrate {
	enum CAN_BAUD	baudrate;
	unsigned char	btr[3];
};


union can_settings {
	enum CAN_MODE	mode;
	enum CAN_STATE	state;
};


#define AF_CAN		30	/* CAN Bus                      */
#define PF_CAN		AF_CAN

enum CAN_PROTO {
	CAN_PROTO_RAW,
	CAN_PROTO_MAX,
};

struct sockaddr_can {
    sa_family_t  can_family;
    int          can_ifindex;
    int          can_id;
};

struct can_frame {
	int	can_id;
	int	can_dlc;
	union {
                int64_t    data_64;
                int32_t    data_32[2];
                int16_t    data_16[4];
                int8_t     data_8[8];
		u_int64_t  data_u64;
		u_int32_t  data_u32[2];
		u_int16_t  data_u16[4];
		u_int8_t   data_u8[8];
		int8_t     data[8]; 		/* shortcut */
	} payload;
};

#endif /* !_SOCKET_CAN_CAN_H */