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