yarp-devices
hico_api.h
1 /*EM_LICENSE*/
2 /*
3  * $Id: hico_api.h 1207 2009-05-11 13:36:51Z ny $
4  * Author: Martin Nylund
5  */
6 
7 #ifndef _HICO_API_H
8 #define _HICO_API_H
9 
10 
11 /* hicocan_mpci 'magic' number for the ioctl calls */
12 #ifdef __QNX__
13  #define IOC_MAGIC _DCMD_MISC
14  #include <ioctl.h>
15  #include <devctl.h>
16  #include <stdint.h>
17 #else /* Linux */
18  #define IOC_MAGIC 'E'
19  #ifndef __KERNEL__
20  #include <sys/ioctl.h>
21  #include <stdint.h>
22  #endif
23 #endif
24 
25 /* Macro for structure packing */
26 #define PACKED __attribute__((packed))
27 
28 
29 /* Endianness-related macros */
30 /* http://esr.ibiblio.org/?p=5095 */
31 #ifdef BSD
32  #include <sys/endian.h>
33 #else
34  #include <endian.h>
35 #endif
36 
37 /* Uncomment one of these if the test below fails for some reason */
38 /* #define HICO_BE */
39 /* #define HICO_LE */
40 #if !defined(HICO_LE) && !defined(HICO_BE) && !defined(__KERNEL__)
41  #ifdef __BYTE_ORDER
42  #if __BYTE_ORDER == __LITTLE_ENDIAN
43  #define HICO_LE
44  #elif __BYTE_ORDER == __BIG_ENDIAN
45  #define HICO_BE
46  #endif
47  #else
48  #error -- could not detect endianess!
49  #endif
50 #endif
51 
52 #if defined(HICO_LE) && defined(HICO_BE)
53  #error -- You cannot have both!
54 #endif
55 
56 
57 
58 /**************************************************************************/
59 #define IOC_RESET_BOARD _IO (IOC_MAGIC, 1)
60 /**************************************************************************/
61 /* Reset the board. Note that this command affects both of the CAN nodes on
62  * the board */
63 
64 /**************************************************************************/
65 #define IOC_START _IO (IOC_MAGIC, 5)
66 /**************************************************************************/
67 /* This will put the CAN node in active state - CAN telegrams are sent and
68  * received */
69 
70 /**************************************************************************/
71 #define IOC_START_PASSIVE _IO (IOC_MAGIC, 10)
72 /**************************************************************************/
73 /* Start the CAN node in passive mode. Listen to the CAN bus traffic but don't
74  * affect it in any way. CAN messages are received normally but transmission
75  * is disabled */
76 
77 /**************************************************************************/
78 #define IOC_START_BAUDSCAN _IO (IOC_MAGIC, 15)
79 /**************************************************************************/
80 /* This command will put the CAN node in baudscan mode. The node will probe
81  * for the correct baudrate on the CAN bus, but doesn't affect the traffic in
82  * any way. Of course, in order to the scan to succeed there has to be traffic
83  * on the bus. The first succesfully received message is put in the boards
84  * receive queue after which the node is in active state (like after givining
85  * IOC_START command ) */
86 
87 /**************************************************************************/
88 #define IOC_STOP _IO (IOC_MAGIC, 20)
89 /**************************************************************************/
90 /* This command will put the CAN node in reset state. No CAN telegrams are
91  * received or transmitted. */
92 
93 /**************************************************************************/
94 #define IOC_GET_MODE _IOR(IOC_MAGIC, 25, uint32_t)
95 /**************************************************************************/
96 /* Retrieve the nodes operation mode */
97 
98 /* node is in baudscan mode */
99 #define CM_BAUDSCAN 1
100 
101 /* node listens to the CAN bus traffic but don't affect it in any way */
102 #define CM_PASSIVE 2
103 
104 /* Normal usage mode. CAN messages are received and transmitted */
105 #define CM_ACTIVE 3
106 
107 /* In reset mode, no messages are received or transmitted. */
108 #define CM_RESET 4
109 
110 
111 
112 /**************************************************************************/
113 #define IOC_SET_BITRATE _IOW (IOC_MAGIC, 30, uint32_t)
114 /**************************************************************************/
115 /* Set the bitrate (aka. baudrate) for the given CAN nodes. Parameter is one
116  * of the BITRATE_* macros below */
117 
118 #define BITRATE_10k 0
119 #define BITRATE_20k 1
120 #define BITRATE_50k 2
121 #define BITRATE_100k 3
122 #define BITRATE_125k 4
123 #define BITRATE_250k 5
124 #define BITRATE_500k 6
125 #define BITRATE_800k 7
126 #define BITRATE_1000k 8
127 
128 /**************************************************************************/
129 #define IOC_SET_SJW_INCREMENT _IOW (IOC_MAGIC, 31, uint32_t)
130 /**************************************************************************/
131 /* Set a value which will be added to the Synchronisation Jump Width (SJW)
132  * on every bitrate. value can be from 0 to 3, and default is 0. This
133  * parameter might be useful to tweak if there are very long CAN cables or
134  * some CAN nodes, which are not that accurate with the bitrate. The value
135  * has to be set before calling IOC_SET_BITRATE. Normally you don't need
136  * to set this value */
137 
138 /**************************************************************************/
139 #define IOC_GET_BITRATE _IOR (IOC_MAGIC, 35, uint32_t)
140 /**************************************************************************/
141 /* Get the bitrate index number. The value corresponds one of the above
142  * defined bitrates BITRATE_*k */
143 
144 
145 
146 /**************************************************************************/
147 #define IOC_GET_CAN_STATUS _IOR (IOC_MAGIC, 40, uint32_t)
148 /**************************************************************************/
149 /* Returns the current status flags of the CAN node. */
150 
151 /* Passive error - one or both of the tx and rx error counter has reached the
152  * error warning limit (128) */
153 #define CS_ERROR_PASSIVE (1<<6)
154 
155 /* Bus off error - Transmit error counter has reached its limiting value 255.
156  * You can reset the error counter by setting the node in CM_RESET mode */
157 #define CS_ERROR_BUS_OFF (1<<7)
158 
159 /* Following macros extract the current tx/rx error counter values from the
160  * returned value */
161 #define CS_GET_RXERRCNT(status) ((status>>16)&0xff)
162 #define CS_GET_TXERRCNT(status) ((status>>24)&0xff)
163 
164 /* Other flags int the status value are not of intrest for applications */
165 
166 
167 /**************************************************************************/
168 #define IOC_GET_BOARD_STATUS _IOR (IOC_MAGIC, 45, uint32_t)
169 /**************************************************************************/
170 /* Reads the current status of the board. In normal operation the value should
171  * always be BS_RUNNING_OK. In case of an exception the values is something
172  * else. See dpm.h for more information */
173 #define BS_RUNNING_OK 0xf2f20000
174 
175 
176 /**************************************************************************/
177 #define IOC_SET_FILTER _IOW (IOC_MAGIC, 50, struct can_filter)
178 /**************************************************************************/
179 /* Add an acceptance filter into the list of active acceptance filters. By
180  * default, the acceptance masking is not active and all the messages are let
181  * through */
182 
183 /**************************************************************************/
184 #define IOC_CLEAR_FILTERS _IO (IOC_MAGIC, 55)
185 /**************************************************************************/
186 /* Clear all acceptance filters for the node and set the acceptance in default
187  * state (all messages let through)*/
188 
189 
190 /**************************************************************************/
191 #define IOC_MSGS_IN_RXBUF _IOR (IOC_MAGIC, 60, int)
192 /**************************************************************************/
193 /* Return the number of messages that can be read from the boards receive
194  * buffer */
195 
196 /**************************************************************************/
197 #define IOC_MSGS_IN_TXBUF _IOR (IOC_MAGIC, 61, int)
198 /**************************************************************************/
199 /* Return the number of messages that are written to the CAN nodes transmit
200  * buffer */
201 
202 /**************************************************************************/
203 #define IOC_GET_TXBUF_SIZE _IOR (IOC_MAGIC, 62, int)
204 /**************************************************************************/
205 /* Size of transmit buffer */
206 /**************************************************************************/
207 #define IOC_GET_RXBUF_SIZE _IOR (IOC_MAGIC, 63, int)
208 /**************************************************************************/
209 /* Size of the receive buffer */
210 
211 /**************************************************************************/
212 #define IOC_RESET_TIMESTAMP _IO (IOC_MAGIC, 65)
213 /**************************************************************************/
214 /* Reset the CAN message timestamp timer. Note that this command affects both
215  * of the nodes.*/
216 
217 /**************************************************************************/
218 #define IOC_GET_HW_ID _IOR (IOC_MAGIC, 70, uint32_t)
219 /**************************************************************************/
220 /* read the boards hardware ID. The function returns one of the following
221  * values */
222 /* HiCO.CAN-MiniPCI */
223 #define HW_HICOCAN_MPCI 0x10
224 /* HiCO.CAN-PCI-104 and PC/104+ */
225 #define HW_HICOCAN_PCI104 0x13
226 /* Unknown hardware Identifier */
227 #define HW_HICOCAN_UNKNOWN 0xff
228 
229 /**************************************************************************/
230 #define IOC_GET_FW2_VERSION _IOR (IOC_MAGIC, 71, uint32_t)
231 /**************************************************************************/
232 /* Read version number for the board firmware (FW1 is the internal
233  * bootloader and FW2 ist the actual firmware) */
234 
235 /**************************************************************************/
236 #define IOC_GET_DRIVER_VERSION _IOR (IOC_MAGIC, 72, uint32_t)
237 /**************************************************************************/
238 /* Get version number of the driver */
239 
240 /**************************************************************************/
241 #define IOC_GET_CAN_TYPE _IOR (IOC_MAGIC, 73, uint32_t)
242 /**************************************************************************/
243 /* Get CAN node type node_type gives information of the physical CAN
244  * interface */
245 #define CAN_TYPE_EMPTY 0 /* Tranceiver not mounted on the PCB */
246 #define CAN_TYPE_HS 1 /* High-Speed tranceiver */
247 #define CAN_TYPE_FT 2 /* Fault Tolerant tranceiver */
248 
249 /**************************************************************************/
250 #define IOC_GET_PCI104_POS _IOR (IOC_MAGIC, 75, uint32_t)
251 /**************************************************************************/
252 /* PCI-104 boards are identified with a jumpered value, which define their
253  * location in the PCI-104 stack. This function returns a value from 0 to 3.
254  * NOTE: this function doesn't have any meaning but for the PCI-104 boards */
255 
256 /**************************************************************************/
257 #define IOC_GET_IOPIN_STATUS _IOR (IOC_MAGIC, 80, uint32_t)
258 /**************************************************************************/
259 /* Get the status of the can nodes IOPIN. On Fault Tolerant (FT) boards, this
260  * is the BusError signal (low active -> '1' means no error). This values is
261  * also saved to every received CAN telegram (see iopin in struct can_msg) */
262 
263 #ifndef __QNX__
264 /**************************************************************************/
265 #define IOC_GET_ERR_STAT _IOR (IOC_MAGIC, 81, struct err_stat)
266 /**************************************************************************/
267 struct err_stat{
268  uint32_t values[0x3f];
269 };
270 /**************************************************************************/
271 #define IOC_CLEAR_ERR_STAT _IO (IOC_MAGIC, 82)
272 /**************************************************************************/
273 #endif
274 
275 
276 /**************************************************************************/
277 #define IOC_PRODUCTION_OK _IO (IOC_MAGIC, 101)
278 /**************************************************************************/
279 /* This command sets the board in "blink leds" mode. It is used in production
280  * and in the example programs to signal that everythings ok. This ioctl call
281  * has no use in normal CAN usage, and the board needs to be reset after
282  * putting it into the "blink leds" mode */
283 /**************************************************************************/
284 #define IOC_GET_LPCBC_REV _IOR (IOC_MAGIC, 102, uint32_t)
285 /**************************************************************************/
286 /* This returns the onboard processors bootloader FW revsision number.*/
287 
288 
289 #if 0
290 /**************************************************************************/
291 #define IOC_SET_MODE _IOW (IOC_MAGIC, 65, uint32_t)
292 /**************************************************************************/
293 #endif
294 
295 
296 /**************************************************************************/
297 /* structure of a CAN messages */
298 /**************************************************************************/
299 /* This structure is used for sending and receiving messages. Not all fields
300  * have a meaning when sending (e.g. timestamp) */
301 
302 #define MSG_DLC(msg) (((msg)->fi&0xf)>>0)
303 #define MSG_RTR(msg) (((msg)->fi&(1<<4))>>4)
304 #define MSG_FF(msg) (((msg)->fi&(1<<5))>>5)
305 #define MSG_DOS(msg) (((msg)->fi&(1<<6))>>6)
306 #define MSG_IOPIN(msg)(((msg)->fi&(1<<7))>>7)
307 #define MSG_NODE(msg) (((msg)->fi&(3<<8))>>8)
308 
309 struct can_msg {
310  union{
311  uint16_t fi;
312 #ifdef HICO_LE
313  struct {
314  /* Data length 0 to 8 */
315  uint16_t dlc:4;
316 
317  /* remote transmission request flag */
318  uint16_t rtr:1;
319 
320  /* Frame format flag 0=normal, 1=extended */
321  uint16_t ff:1;
322 
323  /* Data overrun status flag */
324  uint16_t dos:1;
325 
326  /* io pin status or can error signal on fault tolerant can */
327  uint16_t iopin:1;
328 
329  /* CAN node number which received the message */
330  uint16_t node:2;
331 
332  uint16_t reserved:6;
333  }PACKED;
334 #elif defined(HICO_BE)
335  struct {
336  uint16_t reserved:6;
337  uint16_t node:2;
338  uint16_t iopin:1;
339  uint16_t dos:1;
340  uint16_t ff:1;
341  uint16_t rtr:1;
342  uint16_t dlc:4;
343  }PACKED;
344 #endif
345  }PACKED;
346 
347  /* Timestamp in microseconds */
348  uint32_t ts;
349 
350  /* CAN identifier */
351  uint32_t id;
352 
353  /* CAN message data */
354  uint8_t data[8];
355 }PACKED;
356 
357 #define FF_NORMAL 0
358 #define FF_EXTENDED 1
359 
360 struct can_filter{
361  int type;
362  union{
363  uint32_t mask;
364  uint32_t upper;
365  };
366  union{
367  uint32_t code;
368  uint32_t lower;
369  };
370 };
371 #define FTYPE_AMASK 1
372 #define FTYPE_RANGE 2
373 
374 
375 #endif
Definition: hico_api.h:360
Definition: hico_api.h:309
Definition: hico_api.h:267