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