]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/canmsg.h
LinCAN version updated to 0.3
[lincan.git] / lincan / include / canmsg.h
1 /* canmsg.h - common kernel-space and user-space CAN message structure
2  * Linux CAN-bus device driver.
3  * Written by Pavel Pisa - OCERA team member
4  * email:pisa@cmp.felk.cvut.cz
5  * This software is released under the GPL-License.
6  * Version lincan-0.3  17 Jun 2004
7  */
8
9 #ifndef _CANMSG_T_H
10 #define _CANMSG_T_H
11
12 #ifdef __KERNEL__
13
14 #include <linux/time.h>
15 #include <linux/types.h>
16
17 #else /* __KERNEL__ */
18
19 #include <sys/time.h>
20 #include <sys/types.h>
21
22 #endif /* __KERNEL__ */
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* 
29  * CAN_MSG_VERSION_2 enables new canmsg_t layout compatible with
30  * can4linux project from http://www.port.de/
31  * 
32  */
33 #define CAN_MSG_VERSION_2
34
35 /* Number of data bytes in one CAN message */
36 #define CAN_MSG_LENGTH 8
37
38 #ifdef CAN_MSG_VERSION_2
39
40 typedef struct timeval canmsg_tstamp_t ;
41
42 /**
43  * struct canmsg_t - structure representing CAN message
44  * @flags:  message flags
45  *      %MSG_RTR .. message is Remote Transmission Request,
46  *      %MSG_EXT .. message with extended ID, 
47  *      %MSG_OVR .. indication of queue overflow condition,
48  *      %MSG_LOCAL .. message originates from this node.
49  * @cob:    communication object number (not used)
50  * @id:     ID of CAN message
51  * @timestamp: not used
52  * @length: length of used data
53  * @data:   data bytes buffer
54  *
55  * Header: canmsg.h
56  */
57 struct canmsg_t {
58         int             flags;
59         int             cob;
60         unsigned long   id;
61         canmsg_tstamp_t timestamp;
62         unsigned short  length;
63         unsigned char   data[CAN_MSG_LENGTH];
64 };
65
66 #else /*CAN_MSG_VERSION_2*/
67 #ifndef PACKED
68 #define PACKED __attribute__((packed))
69 #endif
70 /* Old, deprecated version of canmsg_t structure */
71 struct canmsg_t {
72         short           flags;
73         int             cob;
74         unsigned long   id;
75         unsigned long   timestamp;
76         unsigned int    length;
77         unsigned char   data[CAN_MSG_LENGTH];
78 } PACKED;
79 #endif /*CAN_MSG_VERSION_2*/
80
81 typedef struct canmsg_t canmsg_t;
82
83 /**
84  * struct canfilt_t - structure for acceptance filter setup
85  * @flags:  message flags
86  *      %MSG_RTR .. message is Remote Transmission Request,
87  *      %MSG_EXT .. message with extended ID, 
88  *      %MSG_OVR .. indication of queue overflow condition,
89  *      %MSG_LOCAL .. message originates from this node.
90  *      there are corresponding mask bits
91  *      %MSG_RTR_MASK, %MSG_EXT_MASK, %MSG_LOCAL_MASK.
92  *      %MSG_PROCESSLOCAL enables local messages processing in the
93  *      combination with global setting
94  * @queid:  CAN queue identification in the case of the multiple
95  *          queues per one user (open instance)
96  * @cob:    communication object number (not used)
97  * @id:     selected required value of cared ID id bits
98  * @mask:   select bits significand for the comparation;
99  *          1 .. take care about corresponding ID bit, 0 .. don't care
100  *
101  * Header: canmsg.h
102  */
103 struct canfilt_t {
104         int             flags;
105         int             queid;
106         int             cob;
107         unsigned long   id;
108         unsigned long   mask;
109 };
110
111 typedef struct canfilt_t canfilt_t;
112
113 /* Definitions to use for canmsg_t and canfilt_t flags */
114 #define MSG_RTR   (1<<0)
115 #define MSG_OVR   (1<<1)
116 #define MSG_EXT   (1<<2)
117 #define MSG_LOCAL (1<<3)
118 /* If you change above lines, check canque_filtid2internal function */
119
120 /* Additional definitions used for canfilt_t only */
121 #define MSG_FILT_MASK_SHIFT   8
122 #define MSG_RTR_MASK   (MSG_RTR<<MSG_FILT_MASK_SHIFT)
123 #define MSG_EXT_MASK   (MSG_EXT<<MSG_FILT_MASK_SHIFT)
124 #define MSG_LOCAL_MASK (MSG_LOCAL<<MSG_FILT_MASK_SHIFT)
125 #define MSG_PROCESSLOCAL (MSG_OVR<<MSG_FILT_MASK_SHIFT)
126
127 /* Can message ID mask */
128 #define MSG_ID_MASK ((1l<<29)-1)
129
130 #ifdef __cplusplus
131 } /* extern "C"*/
132 #endif
133
134 #endif /*_CANMSG_T_H*/