]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/canmsg.h
The LinCAN driver license unified according to DCE FEE CTU head and superiors request.
[lincan.git] / lincan / include / canmsg.h
1 /**************************************************************************/
2 /* File: canmsg.h - common kernel-space and user-space CAN message struct */
3 /*                                                                        */
4 /* LinCAN - (Not only) Linux CAN bus driver                               */
5 /* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
6 /* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
7 /* Funded by OCERA and FRESCOR IST projects                               */
8 /*                                                                        */
9 /* LinCAN is free software; you can redistribute it and/or modify it      */
10 /* under terms of the GNU General Public License as published by the      */
11 /* Free Software Foundation; either version 2, or (at your option) any    */
12 /* later version.  LinCAN is distributed in the hope that it will be      */
13 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
14 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
15 /* General Public License for more details. You should have received a    */
16 /* copy of the GNU General Public License along with LinCAN; see file     */
17 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
18 /* Cambridge, MA 02139, USA.                                              */
19 /*                                                                        */
20 /* To allow use of LinCAN in the compact embedded systems firmware        */
21 /* and RT-executives (RTEMS for example), main authors agree with next    */
22 /* special exception:                                                     */
23 /*                                                                        */
24 /* Including LinCAN header files in a file, instantiating LinCAN generics */
25 /* or templates, or linking other files with LinCAN objects to produce    */
26 /* an application image/executable, does not by itself cause the          */
27 /* resulting application image/executable to be covered by                */
28 /* the GNU General Public License.                                        */
29 /* This exception does not however invalidate any other reasons           */
30 /* why the executable file might be covered by the GNU Public License.    */
31 /* Publication of enhanced or derived LinCAN files is required although.  */
32 /**************************************************************************/
33
34 #ifndef _CANMSG_T_H
35 #define _CANMSG_T_H
36
37 #ifdef __KERNEL__
38
39 #include <linux/time.h>
40 #include <linux/types.h>
41
42 #else /* __KERNEL__ */
43
44 #include <inttypes.h>
45 #include <sys/time.h>
46 #include <sys/types.h>
47
48 #endif /* __KERNEL__ */
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /* 
55  * CAN_MSG_VERSION_2 enables new canmsg_t layout compatible with
56  * can4linux project from http://www.port.de/
57  * 
58  */
59 #define CAN_MSG_VERSION_2
60
61 /* Number of data bytes in one CAN message */
62 #define CAN_MSG_LENGTH 8
63
64 #ifdef CAN_MSG_VERSION_2
65
66 typedef struct timeval canmsg_tstamp_t ;
67
68 typedef unsigned long canmsg_id_t;
69
70 /**
71  * struct canmsg_t - structure representing CAN message
72  * @flags:  message flags
73  *      %MSG_RTR .. message is Remote Transmission Request,
74  *      %MSG_EXT .. message with extended ID, 
75  *      %MSG_OVR .. indication of queue overflow condition,
76  *      %MSG_LOCAL .. message originates from this node.
77  * @cob:    communication object number (not used)
78  * @id:     ID of CAN message
79  * @timestamp: not used
80  * @length: length of used data
81  * @data:   data bytes buffer
82  *
83  * Header: canmsg.h
84  */
85 struct canmsg_t {
86         int             flags;
87         int             cob;
88         canmsg_id_t     id;
89         canmsg_tstamp_t timestamp;
90         unsigned short  length;
91         unsigned char   data[CAN_MSG_LENGTH];
92 };
93
94 #else /*CAN_MSG_VERSION_2*/
95 #ifndef PACKED
96 #define PACKED __attribute__((packed))
97 #endif
98 /* Old, deprecated version of canmsg_t structure */
99 struct canmsg_t {
100         short           flags;
101         int             cob;
102         canmsg_id_t     id;
103         unsigned long   timestamp;
104         unsigned int    length;
105         unsigned char   data[CAN_MSG_LENGTH];
106 } PACKED;
107 #endif /*CAN_MSG_VERSION_2*/
108
109 typedef struct canmsg_t canmsg_t;
110
111 /**
112  * struct canfilt_t - structure for acceptance filter setup
113  * @flags:  message flags
114  *      %MSG_RTR .. message is Remote Transmission Request,
115  *      %MSG_EXT .. message with extended ID, 
116  *      %MSG_OVR .. indication of queue overflow condition,
117  *      %MSG_LOCAL .. message originates from this node.
118  *      there are corresponding mask bits
119  *      %MSG_RTR_MASK, %MSG_EXT_MASK, %MSG_LOCAL_MASK.
120  *      %MSG_PROCESSLOCAL enables local messages processing in the
121  *      combination with global setting
122  * @queid:  CAN queue identification in the case of the multiple
123  *          queues per one user (open instance)
124  * @cob:    communication object number (not used)
125  * @id:     selected required value of cared ID id bits
126  * @mask:   select bits significand for the comparation;
127  *          1 .. take care about corresponding ID bit, 0 .. don't care
128  *
129  * Header: canmsg.h
130  */
131 struct canfilt_t {
132         int             flags;
133         int             queid;
134         int             cob;
135         canmsg_id_t     id;
136         canmsg_id_t     mask;
137 };
138
139 typedef struct canfilt_t canfilt_t;
140
141 /* Definitions to use for canmsg_t and canfilt_t flags */
142 #define MSG_RTR   (1<<0)
143 #define MSG_OVR   (1<<1)
144 #define MSG_EXT   (1<<2)
145 #define MSG_LOCAL (1<<3)
146 /* If you change above lines, check canque_filtid2internal function */
147
148 /* Additional definitions used for canfilt_t only */
149 #define MSG_FILT_MASK_SHIFT   8
150 #define MSG_RTR_MASK   (MSG_RTR<<MSG_FILT_MASK_SHIFT)
151 #define MSG_EXT_MASK   (MSG_EXT<<MSG_FILT_MASK_SHIFT)
152 #define MSG_LOCAL_MASK (MSG_LOCAL<<MSG_FILT_MASK_SHIFT)
153 #define MSG_PROCESSLOCAL (MSG_OVR<<MSG_FILT_MASK_SHIFT)
154
155 /* Can message ID mask */
156 #define MSG_ID_MASK ((1l<<29)-1)
157
158 #ifdef __cplusplus
159 } /* extern "C"*/
160 #endif
161
162 #endif /*_CANMSG_T_H*/