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