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