ntcan.h
Go to the documentation of this file.
1 /* ntcan.h
2 **
3 ** Copyright (c) 2001-2006 by electronic system design gmbh
4 **
5 ** This software is copyrighted by and is the sole property of
6 ** esd gmbh. All rights, title, ownership, or other interests
7 ** in the software remain the property of esd gmbh. This
8 ** software may only be used in accordance with the corresponding
9 ** license agreement. Any unauthorized use, duplication, transmission,
10 ** distribution, or disclosure of this software is expressly forbidden.
11 **
12 ** This Copyright notice may not be removed or modified without prior
13 ** written consent of esd gmbh.
14 **
15 ** esd gmbh, reserves the right to modify this software without notice.
16 **
17 ** electronic system design gmbh Tel. +49-511-37298-0
18 ** Vahrenwalder Str 207 Fax. +49-511-37298-68
19 ** 30165 Hannover http://www.esd-electronics.com
20 ** Germany sales@esd-electronics.com
21 **
22 **
23 */
24 
25 #ifndef _ntcan_h_
26 #define _ntcan_h_
27 
28 #if ((__GNUC__ > 2) || (__GNUC__ > 2) && (__GNUC_MINOR__ >= 1))
29 # define NTCAN_GCCATTR_DEPRECATED __attribute__((deprecated))
30 #else
31 # define NTCAN_GCCATTR_DEPRECATED
32 #endif
33 
34 #include <stdint.h>
35 
36 #ifndef EXPORT
37 #define EXPORT
38 #endif
39 
40 #ifndef CALLTYPE
41 #define CALLTYPE
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif /* __cplusplus */
47 
48 /*------------------ Defines ------------------------------------------------*/
49 #define NTCAN_EV_BASE 0x40000000
50 #define NTCAN_EV_USER 0x40000080
51 #define NTCAN_EV_LAST 0x400000FF
52 
53 #define NTCAN_20B_BASE 0x20000000
54 
55 #define NTCAN_RTR 0x10
56 #define NTCAN_NO_DATA 0x20 /* only senseful in obj-mode */
57 #define NTCAN_INTERACTION 0x20 /* only senseful in non obj-mode */
58 
59 #define NTCAN_EV_CAN_ERROR NTCAN_EV_BASE
60 #define NTCAN_EV_BAUD_CHANGE (NTCAN_EV_BASE + 0x1)
61 #define NTCAN_EV_CAN_ERROR_EXT (NTCAN_EV_BASE + 0x2)
62 
63 /* Mode-flags for canOpen() */
64 #define NTCAN_MODE_OVERLAPPED 0x20000000
65 #define NTCAN_MODE_OBJECT 0x10000000 /* Open for Rx object mode */
66 
67 /* Queue-Size in canOpen() */
68 #define NTCAN_MAX_TX_QUEUESIZE 2047
69 #define NTCAN_MAX_RX_QUEUESIZE 2047
70 #define NTCAN_NO_QUEUE -1
71 
72 /* No baudrate configured (returned from canGetBaudrate() )*/
73 #define NTCAN_NO_BAUDRATE 0x7FFFFFFF
74 #define NTCAN_AUTOBAUD 0x7FFFFFFE
75 /* Defines to easily use CiA-recommended baudrates
76  * predefined by esd with canSetBaudrate() */
77 #define NTCAN_BAUD_1000 0x0
78 #define NTCAN_BAUD_800 0xE
79 #define NTCAN_BAUD_500 0x2
80 #define NTCAN_BAUD_250 0x4
81 #define NTCAN_BAUD_125 0x6
82 #define NTCAN_BAUD_100 0x7
83 #define NTCAN_BAUD_50 0x9
84 #define NTCAN_BAUD_20 0xB
85 #define NTCAN_BAUD_10 0xD
86 /* Defines to use with canSetBaudrate() */
87 #define NTCAN_USER_BAUD 0x80000000 /* DEPRECATED, please use the define below, as described in CAN-API manual */
88 #define NTCAN_USER_BAUDRATE 0x80000000
89 #define NTCAN_LISTEN_ONLY_MODE 0x40000000
90 #define NTCAN_USER_BAUDRATE_NUM 0x20000000
91 
92 /*------------------- error-code-base----------------------------------------*/
93 #define NTCAN_ERRNO_BASE 0x00000100
94 /*------------------- error-codes--------------------------------------------*/
95 #define NTCAN_SUCCESS 0
96 
97 #define NTCAN_RX_TIMEOUT (NTCAN_ERRNO_BASE +1)
98 #define NTCAN_TX_TIMEOUT (NTCAN_ERRNO_BASE +2)
99 /* #define NTCAN_RESERVED (NTCAN_ERRNO_BASE +3) */
100 #define NTCAN_TX_ERROR (NTCAN_ERRNO_BASE +4)
101 #define NTCAN_CONTR_OFF_BUS (NTCAN_ERRNO_BASE +5)
102 #define NTCAN_CONTR_BUSY (NTCAN_ERRNO_BASE +6)
103 #define NTCAN_CONTR_WARN (NTCAN_ERRNO_BASE +7)
104 #define NTCAN_NO_ID_ENABLED (NTCAN_ERRNO_BASE +9)
105 #define NTCAN_ID_ALREADY_ENABLED (NTCAN_ERRNO_BASE +10)
106 #define NTCAN_ID_NOT_ENABLED (NTCAN_ERRNO_BASE +11)
107 /* #define NTCAN_RESERVED (NTCAN_ERRNO_BASE +12) */
108 #define NTCAN_INVALID_FIRMWARE (NTCAN_ERRNO_BASE +13)
109 #define NTCAN_MESSAGE_LOST (NTCAN_ERRNO_BASE +14)
110 #define NTCAN_INVALID_HARDWARE (NTCAN_ERRNO_BASE +15)
111 
112 #define NTCAN_PENDING_WRITE (NTCAN_ERRNO_BASE +16)
113 #define NTCAN_PENDING_READ (NTCAN_ERRNO_BASE +17)
114 #define NTCAN_INVALID_DRIVER (NTCAN_ERRNO_BASE +18)
115 
116 #define NTCAN_SOCK_CONN_TIMEOUT (NTCAN_ERRNO_BASE + 0x80)
117 #define NTCAN_SOCK_CMD_TIMEOUT (NTCAN_ERRNO_BASE + 0x81)
118 #define NTCAN_SOCK_HOST_NOT_FOUND (NTCAN_ERRNO_BASE + 0x82) /* gethostbyname() failed */
119 
120 #define NTCAN_INVALID_PARAMETER EINVAL
121 #define NTCAN_INVALID_HANDLE EBADFD
122 /* #define NTCAN_IO_INCOMPLETE not reasonable under Linux */
123 /* #define NTCAN_IO_PENDING not reasonable under Linux */
124 #define NTCAN_NET_NOT_FOUND ENODEV
125 #define NTCAN_INSUFFICIENT_RESOURCES ENOMEM
126 
127 #define NTCAN_OPERATION_ABORTED EINTR
128 #define NTCAN_WRONG_DEVICE_STATE (NTCAN_ERRNO_BASE +19)
129 #define NTCAN_HANDLE_FORCED_CLOSE (NTCAN_ERRNO_BASE +20)
130 #define NTCAN_NOT_IMPLEMENTED ENOSYS
131 #define NTCAN_NOT_SUPPORTED (NTCAN_ERRNO_BASE +21)
132 #define NTCAN_CONTR_ERR_PASSIVE (NTCAN_ERRNO_BASE +22)
133 
134 /*
135  * Dear ntcan-user,
136  * we regret, that we were forced to change the name of our handle type.
137  * This had to be done to keep "inter-system" compatibility of your
138  * application sources, after a change in VxWorks 6.0. Please replace all
139  * occurrences of HANDLE with NTCAN_HANDLE in your application's source
140  * code.
141  */
142 typedef int32_t OVERLAPPED;
143 #ifndef NTCAN_CLEAN_NAMESPACE
144 typedef int32_t HANDLE NTCAN_GCCATTR_DEPRECATED;
145 #endif
146 typedef int32_t NTCAN_RESULT;
147 typedef int32_t NTCAN_HANDLE;
148 
149 #pragma pack(1)
150 
151 typedef struct {
152  int32_t id; /* can-id */
153  uint8_t len; /* length of message: 0-8 */
154  uint8_t msg_lost; /* count of lost rx-messages */
155  uint8_t reserved[2]; /* reserved */
156  uint8_t data[8]; /* 8 data-bytes */
157 } CMSG;
158 
159 typedef struct {
160  int32_t evid; /* event-id: possible range:EV_BASE...EV_LAST */
161  uint8_t len; /* length of message: 0-8 */
162  uint8_t reserved[3]; /* reserved */
163  union {
164  uint8_t c[8];
165  uint16_t s[4];
166  uint32_t l[2];
167  } evdata;
168 } EVMSG;
169 
170 typedef struct {
171  int32_t id; /* can-id */
172  uint8_t len; /* length of message: 0-8 */
173  uint8_t msg_lost; /* count of lost rx-messages */
174  uint8_t reserved[2]; /* reserved */
175  uint8_t data[8]; /* 8 data-bytes */
176  uint64_t timestamp; /* time stamp of this message */
177 } CMSG_T;
178 
179 typedef struct {
180  uint16_t hardware;
181  uint16_t firmware;
182  uint16_t driver;
183  uint16_t dll;
184  uint32_t boardstatus;
185  uint8_t boardid[14];
186  uint16_t features;
187 } CAN_IF_STATUS;
188 
189 
190 typedef struct
191 {
192  int32_t id;
193  int32_t flags;
194  uint64_t time_start;
195  uint64_t time_interval;
196  uint8_t reserved[8];
197 } CSCHED;
198 
199 #pragma pack()
200 
201 
202 /* Feature-flags returned by canStatus() */
203 #define NTCAN_FEATURE_FULL_CAN (1<<0)
204 #define NTCAN_FEATURE_BASIC_20B (1<<1)
205 #define NTCAN_FEATURE_DEVICE_NET (1<<2)
206 #define NTCAN_FEATURE_CYCLIC_TX (1<<3) /* Cyclic Tx support */
207 #define NTCAN_FEATURE_RX_OBJECT_MODE (1<<4) /* Receive object mode support */
208 #define NTCAN_FEATURE_TIMESTAMP (1<<5) /* Timestamp support */
209 #define NTCAN_FEATURE_LISTEN_ONLY_MODE (1<<6) /* Listen-only-mode support */
210 #define NTCAN_FEATURE_SMART_DISCONNECT (1<<7) /* Leave-bus-after-last-close */
211 
212 /* Bus states delivered by status-event */
213 #define NTCAN_BUSSTATE_OK 0x00
214 #define NTCAN_BUSSTATE_WARN 0x40
215 #define NTCAN_BUSSTATE_ERRPASSIVE 0x80
216 #define NTCAN_BUSSTATE_BUSOFF 0xC0
217 
218 /*
219  * IOCTL codes for canIoctl()
220  */
221 #define NTCAN_IOCTL_FLUSH_RX_FIFO 0x0001 /* Flush Rx FIFO */
222 #define NTCAN_IOCTL_GET_RX_MSG_COUNT 0x0002 /* Ret # CMSG in Rx FIFO */
223 #define NTCAN_IOCTL_GET_RX_TIMEOUT 0x0003 /* Ret configured Rx tout */
224 #define NTCAN_IOCTL_GET_TX_TIMEOUT 0x0004 /* Ret configured Tx tout */
225 
226 /*
227  * AB: The following IOCTLs aren't implemented in candev-driver, yet.
228  * And probably never will, since candev driver is deprecated.
229  */
230 #define NTCAN_IOCTL_SET_20B_HND_FILTER 0x0005 /* Configure 20B filter */
231 #define NTCAN_IOCTL_GET_SERIAL 0x0006 /* Get HW serial number */
232 #define NTCAN_IOCTL_GET_TIMESTAMP_FREQ 0x0007 /* Get timestamp frequency in Hz */
233 #define NTCAN_IOCTL_GET_TIMESTAMP 0x0008 /* Get timestamp counter */
234 #define NTCAN_IOCTL_ABORT_RX 0x0009 /* Abort a pending read */
235 #define NTCAN_IOCTL_ABORT_TX 0x000A /* Abort pending write */
236 #define NTCAN_IOCTL_SET_RX_TIMEOUT 0x000B /* Change rx-timeout parameter */
237 #define NTCAN_IOCTL_SET_TX_TIMEOUT 0x000C /* Change tx-timeout parameter */
238 #define NTCAN_IOCTL_TX_OBJ_CREATE 0x000D /* Create obj, arg->CMSG */
239 #define NTCAN_IOCTL_TX_OBJ_AUTOANSWER_ON 0x000E /* Switch autoanswer on,arg->CMSG */
240 #define NTCAN_IOCTL_TX_OBJ_AUTOANSWER_OFF 0x000F /* Switch autoanswer off,arg->CMSG*/
241 #define NTCAN_IOCTL_TX_OBJ_UPDATE 0x0010 /* update obj, arg->CMSG */
242 #define NTCAN_IOCTL_TX_OBJ_DESTROY 0x0011 /* Destroy obj, arg->id */
243 
244 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE_START 0x0013 /* Start scheduling for handle */
245 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE_STOP 0x0014 /* Stop scheduling for handle */
246 #define NTCAN_IOCTL_TX_OBJ_SCHEDULE 0x0015 /* Set sched. for obj,arg->CSCHED */
247 
248 
249 /*...prototypes................................................................*/
250 EXPORT NTCAN_RESULT CALLTYPE canSetBaudrate(
251  NTCAN_HANDLE handle, /* nt-handle */
252  uint32_t baud ); /* baudrate-constant */
253 /*.............................................................................*/
254 EXPORT NTCAN_RESULT CALLTYPE canGetBaudrate(
255  NTCAN_HANDLE handle, /* nt-handle */
256  uint32_t *baud ); /* Out: baudrate */
257 /*.............................................................................*/
258 EXPORT NTCAN_RESULT CALLTYPE canOpen(
259  int32_t net, /* net number */
260  uint32_t flags, /* */
261  int32_t txqueuesize, /* nr of entries in message queue */
262  int32_t rxqueuesize, /* nr of entries in message queue */
263  int32_t txtimeout, /* tx-timeout in miliseconds */
264  int32_t rxtimeout, /* rx-timeout in miliseconds */
265  NTCAN_HANDLE *handle ); /* out: nt-handle */
266 /*.............................................................................*/
267 EXPORT NTCAN_RESULT CALLTYPE canClose( /* ret NTCAN_OK, if success */
268  NTCAN_HANDLE handle ); /* handle */
269 /*.............................................................................*/
270 EXPORT NTCAN_RESULT CALLTYPE canIdAdd( /* ret NTCAN_OK, if success */
271  NTCAN_HANDLE handle, /* read handle */
272  int32_t id ); /* can identifier */
273 /*.............................................................................*/
274 EXPORT NTCAN_RESULT CALLTYPE canIdDelete( /* ret 0, if success */
275  NTCAN_HANDLE handle, /* read handle */
276  int32_t id ); /* can identifier */
277 /*.............................................................................*/
279  NTCAN_HANDLE handle, /* handle */
280  OVERLAPPED *ovrlppd, /* overlapped-structure */
281  int32_t *len, /* out: cnt of available CMSG-Buffer*/
282  int32_t bWait ); /* FALSE =>do not wait, else wait */
283 /*.............................................................................*/
284 EXPORT NTCAN_RESULT CALLTYPE canTake( /* ret 0, if success */
285  NTCAN_HANDLE handle, /* handle */
286  CMSG *cmsg, /* ptr to data-buffer */
287  int32_t *len ); /* out: size of CMSG-Buffer */
288  /* in: count of read messages */
289 /*.............................................................................*/
290 EXPORT NTCAN_RESULT CALLTYPE canRead( /* ret 0, if success */
291  NTCAN_HANDLE handle, /* handle */
292  CMSG *cmsg, /* ptr to data-buffer */
293  int32_t *len, /* out: size of CMSG-Buffer */
294  /* in: count of read messages */
295  OVERLAPPED *ovrlppd); /* NULL or overlapped-structure */
296 /*.............................................................................*/
297 EXPORT NTCAN_RESULT CALLTYPE canSend( /* ret 0, if success */
298  NTCAN_HANDLE handle, /* handle */
299  CMSG *cmsg, /* ptr to data-buffer */
300  int32_t *len ); /* size of CMSG-Buffer */
301 /*.............................................................................*/
302 EXPORT NTCAN_RESULT CALLTYPE canWrite( /* ret 0, if success */
303  NTCAN_HANDLE handle, /* handle */
304  CMSG *cmsg, /* ptr to data-buffer */
305  int32_t *len, /* size of CMSG-Buffer */
306  OVERLAPPED *ovrlppd); /* NULL or overlapped-structure */
307 /*.............................................................................*/
308 EXPORT NTCAN_RESULT CALLTYPE canSendT( /* ret 0, if success */
309  NTCAN_HANDLE handle, /* handle */
310  CMSG_T *cmsg, /* ptr to data-buffer */
311  int32_t *len ); /* size of CMSG-Buffer */
312 /*.............................................................................*/
313 EXPORT NTCAN_RESULT CALLTYPE canWriteT( /* ret 0, if success */
314  NTCAN_HANDLE handle, /* handle */
315  CMSG_T *cmsg, /* ptr to data-buffer */
316  int32_t *len, /* size of CMSG-Buffer */
317  OVERLAPPED *ovrlppd); /* NULL or overlapped-structure */
318 /*.............................................................................*/
319 EXPORT NTCAN_RESULT CALLTYPE canReadEvent(
320  NTCAN_HANDLE handle, /* handle */
321  EVMSG *evmsg, /* ptr to event-msg-buffer */
322  OVERLAPPED *ovrlppd); /* NULL or overlapped-structure */
323 /*.............................................................................*/
324 EXPORT NTCAN_RESULT CALLTYPE canSendEvent(
325  NTCAN_HANDLE handle, /* handle */
326  EVMSG *evmsg ); /* ptr to event-msg-buffer */
327 /*.............................................................................*/
328 EXPORT NTCAN_RESULT CALLTYPE canStatus(
329  NTCAN_HANDLE handle, /* handle */
330  CAN_IF_STATUS *cstat ); /* ptr to can-status-buffer */
331 /*.............................................................................*/
332 EXPORT NTCAN_RESULT CALLTYPE canIoctl(
333  NTCAN_HANDLE handle, /* handle */
334  uint32_t ulCmd, /* Command */
335  void *pArg ); /* Ptr to command specific argument */
336 /*.............................................................................*/
337 EXPORT NTCAN_RESULT CALLTYPE canTakeT(
338  NTCAN_HANDLE handle, /* In: handle */
339  CMSG_T *cmsg_t, /* In: ptr to receive buffer */
340  int32_t *len ); /* out: size of CMSG_T-Buffer */
341  /* In: count of read messages */
342 /*.............................................................................*/
343 EXPORT NTCAN_RESULT CALLTYPE canReadT(
344  NTCAN_HANDLE handle, /* In: handle */
345  CMSG_T *cmsg_t, /* Int ptr to receive buffer */
346  int32_t *len, /* out: size of CMSG_T-Buffer */
347  /* In: count of read messages */
348  OVERLAPPED *ovrlppd); /* In: always NULL */
349 
350 #ifdef __cplusplus
351 }
352 #endif /* __cplusplus */
353 #endif /* _ntcan_h_ */
EXPORT NTCAN_RESULT CALLTYPE canReadT(NTCAN_HANDLE handle, CMSG_T *cmsg_t, int32_t *len, OVERLAPPED *ovrlppd)
uint16_t dll
Definition: ntcan.h:183
uint64_t timestamp
Definition: ntcan.h:176
uint8_t len
Definition: ntcan.h:153
EXPORT NTCAN_RESULT CALLTYPE canGetOverlappedResult(NTCAN_HANDLE handle, OVERLAPPED *ovrlppd, int32_t *len, int32_t bWait)
int32_t id
Definition: ntcan.h:152
uint32_t boardstatus
Definition: ntcan.h:184
EXPORT NTCAN_RESULT CALLTYPE canWrite(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len, OVERLAPPED *ovrlppd)
EXPORT NTCAN_RESULT CALLTYPE canIoctl(NTCAN_HANDLE handle, uint32_t ulCmd, void *pArg)
uint8_t msg_lost
Definition: ntcan.h:173
EXPORT NTCAN_RESULT CALLTYPE canGetBaudrate(NTCAN_HANDLE handle, uint32_t *baud)
EXPORT NTCAN_RESULT CALLTYPE canTake(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len)
EXPORT NTCAN_RESULT CALLTYPE canIdDelete(NTCAN_HANDLE handle, int32_t id)
EXPORT NTCAN_RESULT CALLTYPE canSendT(NTCAN_HANDLE handle, CMSG_T *cmsg, int32_t *len)
uint64_t time_start
Definition: ntcan.h:194
EXPORT NTCAN_RESULT CALLTYPE canReadEvent(NTCAN_HANDLE handle, EVMSG *evmsg, OVERLAPPED *ovrlppd)
uint16_t hardware
Definition: ntcan.h:180
uint8_t len
Definition: ntcan.h:161
Definition: ntcan.h:151
int32_t id
Definition: ntcan.h:171
Definition: ntcan.h:190
uint16_t features
Definition: ntcan.h:186
int32_t flags
Definition: ntcan.h:193
uint16_t driver
Definition: ntcan.h:182
int32_t evid
Definition: ntcan.h:160
int32_t id
Definition: ntcan.h:192
Definition: ntcan.h:170
int32_t NTCAN_HANDLE
Definition: ntcan.h:147
EXPORT NTCAN_RESULT CALLTYPE canWriteT(NTCAN_HANDLE handle, CMSG_T *cmsg, int32_t *len, OVERLAPPED *ovrlppd)
uint16_t firmware
Definition: ntcan.h:181
EXPORT NTCAN_RESULT CALLTYPE canOpen(int32_t net, uint32_t flags, int32_t txqueuesize, int32_t rxqueuesize, int32_t txtimeout, int32_t rxtimeout, NTCAN_HANDLE *handle)
uint64_t time_interval
Definition: ntcan.h:195
EXPORT NTCAN_RESULT CALLTYPE canStatus(NTCAN_HANDLE handle, CAN_IF_STATUS *cstat)
EXPORT NTCAN_RESULT CALLTYPE canClose(NTCAN_HANDLE handle)
int32_t NTCAN_RESULT
Definition: ntcan.h:146
int32_t OVERLAPPED
Definition: ntcan.h:142
#define EXPORT
Definition: ntcan.h:37
#define CALLTYPE
Definition: ntcan.h:41
uint8_t msg_lost
Definition: ntcan.h:154
EXPORT NTCAN_RESULT CALLTYPE canRead(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len, OVERLAPPED *ovrlppd)
EXPORT NTCAN_RESULT CALLTYPE canSend(NTCAN_HANDLE handle, CMSG *cmsg, int32_t *len)
#define NTCAN_GCCATTR_DEPRECATED
Definition: ntcan.h:31
EXPORT NTCAN_RESULT CALLTYPE canIdAdd(NTCAN_HANDLE handle, int32_t id)
EXPORT NTCAN_RESULT CALLTYPE canSetBaudrate(NTCAN_HANDLE handle, uint32_t baud)
EXPORT NTCAN_RESULT CALLTYPE canSendEvent(NTCAN_HANDLE handle, EVMSG *evmsg)
uint8_t len
Definition: ntcan.h:172
Definition: ntcan.h:159
EXPORT NTCAN_RESULT CALLTYPE canTakeT(NTCAN_HANDLE handle, CMSG_T *cmsg_t, int32_t *len)


libntcan
Author(s): Florian Weisshardt
autogenerated on Tue Jun 2 2020 03:34:30