Xenomai  3.0-rc7
can.h
Go to the documentation of this file.
1 
33 #ifndef _RTDM_UAPI_CAN_H
34 #define _RTDM_UAPI_CAN_H
35 
41 #define RTCAN_PROFILE_VER 2
42 
43 #ifndef AF_CAN
44 
46 #define AF_CAN 29
47 
49 #define PF_CAN AF_CAN
50 
51 #endif
52 
57 #define SOL_CAN_RAW 103
58 
60 typedef uint32_t can_id_t;
61 typedef uint32_t canid_t;
62 
65 
72 #define CAN_EFF_MASK 0x1FFFFFFF
73 
75 #define CAN_SFF_MASK 0x000007FF
76 
84 #define CAN_EFF_FLAG 0x80000000
85 
86 #define CAN_RTR_FLAG 0x40000000
87 
88 #define CAN_ERR_FLAG 0x20000000
89 
90 #define CAN_INV_FILTER CAN_ERR_FLAG
91 
101 #define CAN_RAW 1
102 
104 #define CAN_BAUDRATE_UNKNOWN ((uint32_t)-1)
105 #define CAN_BAUDRATE_UNCONFIGURED 0
106 
110 typedef uint32_t can_baudrate_t;
111 
120 };
121 
126 
131  uint32_t brp;
132  uint8_t prop_seg;
133  uint8_t phase_seg1;
134  uint8_t phase_seg2;
135  uint8_t sjw:7;
136  uint8_t sam:1;
137 };
138 
143 
144  uint8_t btr0;
145  uint8_t btr1;
146 };
147 
151 struct can_bittime {
154 
155  union {
160  };
161 };
162 
167 enum CAN_MODE {
170 
175 
183 };
187 typedef enum CAN_MODE can_mode_t;
188 
204 #define CAN_CTRLMODE_LISTENONLY 0x1
205 
211 #define CAN_CTRLMODE_LOOPBACK 0x2
212 
216 #define CAN_CTRLMODE_3_SAMPLES 0x4
217 
221 typedef int can_ctrlmode_t;
222 
227 enum CAN_STATE {
232 
237 
242 
245 
248 
251 
254 };
258 typedef enum CAN_STATE can_state_t;
259 
260 #define CAN_STATE_OPERATING(state) ((state) < CAN_STATE_BUS_OFF)
261 
287 typedef struct can_filter {
290  uint32_t can_id;
291 
294  uint32_t can_mask;
295 } can_filter_t;
296 
300 struct sockaddr_can {
302  sa_family_t can_family;
303 
306 };
307 
313 typedef struct can_frame {
319 
321  uint8_t can_dlc;
322 
324  uint8_t data[8] __attribute__ ((aligned(8)));
325 } can_frame_t;
326 
331 #define RTCAN_TAKE_NO_TIMESTAMPS 0
332 #define RTCAN_TAKE_TIMESTAMPS 1
335 #define RTIOC_TYPE_CAN RTDM_CLASS_CAN
336 
375 #define CAN_RAW_FILTER 0x1
376 
405 #define CAN_RAW_ERR_FILTER 0x2
406 
433 #define CAN_RAW_LOOPBACK 0x3
434 
441 #define CAN_RAW_RECV_OWN_MSGS 0x4
442 
466 #ifdef DOXYGEN_CPP /* For Doxygen only, already defined by kernel headers */
467 #define SIOCGIFINDEX defined_by_kernel_header_file
468 #endif
469 
496 #define SIOCSCANBAUDRATE _IOW(RTIOC_TYPE_CAN, 0x01, struct ifreq)
497 
515 #define SIOCGCANBAUDRATE _IOWR(RTIOC_TYPE_CAN, 0x02, struct ifreq)
516 
541 #define SIOCSCANCUSTOMBITTIME _IOW(RTIOC_TYPE_CAN, 0x03, struct ifreq)
542 
560 #define SIOCGCANCUSTOMBITTIME _IOWR(RTIOC_TYPE_CAN, 0x04, struct ifreq)
561 
595 #define SIOCSCANMODE _IOW(RTIOC_TYPE_CAN, 0x05, struct ifreq)
596 
621 #define SIOCGCANSTATE _IOWR(RTIOC_TYPE_CAN, 0x06, struct ifreq)
622 
647 #define SIOCSCANCTRLMODE _IOW(RTIOC_TYPE_CAN, 0x07, struct ifreq)
648 
667 #define SIOCGCANCTRLMODE _IOWR(RTIOC_TYPE_CAN, 0x08, struct ifreq)
668 
686 #define RTCAN_RTIOC_TAKE_TIMESTAMP _IOW(RTIOC_TYPE_CAN, 0x09, int)
687 
711 #define RTCAN_RTIOC_RCV_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0A, nanosecs_rel_t)
712 
736 #define RTCAN_RTIOC_SND_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0B, nanosecs_rel_t)
737 
739 #define CAN_ERR_DLC 8 /* dlc for error frames */
740 
761 #define CAN_ERR_TX_TIMEOUT 0x00000001U
762 
764 #define CAN_ERR_LOSTARB 0x00000002U
765 
767 #define CAN_ERR_CRTL 0x00000004U
768 
771 #define CAN_ERR_PROT 0x00000008U
772 
774 #define CAN_ERR_TRX 0x00000010U
775 
777 #define CAN_ERR_ACK 0x00000020U
778 
780 #define CAN_ERR_BUSOFF 0x00000040U
781 
783 #define CAN_ERR_BUSERROR 0x00000080U
784 
786 #define CAN_ERR_RESTARTED 0x00000100U
787 
789 #define CAN_ERR_MASK 0x1FFFFFFFU
790 
797 /* arbitration lost in bit ... / data[0] */
798 #define CAN_ERR_LOSTARB_UNSPEC 0x00
806 /* error status of CAN-controller / data[1] */
807 #define CAN_ERR_CRTL_UNSPEC 0x00
808 #define CAN_ERR_CRTL_RX_OVERFLOW 0x01
809 #define CAN_ERR_CRTL_TX_OVERFLOW 0x02
810 #define CAN_ERR_CRTL_RX_WARNING 0x04
811 #define CAN_ERR_CRTL_TX_WARNING 0x08
812 #define CAN_ERR_CRTL_RX_PASSIVE 0x10
813 #define CAN_ERR_CRTL_TX_PASSIVE 0x20
820 /* error in CAN protocol (type) / data[2] */
821 #define CAN_ERR_PROT_UNSPEC 0x00
822 #define CAN_ERR_PROT_BIT 0x01
823 #define CAN_ERR_PROT_FORM 0x02
824 #define CAN_ERR_PROT_STUFF 0x04
825 #define CAN_ERR_PROT_BIT0 0x08
826 #define CAN_ERR_PROT_BIT1 0x10
827 #define CAN_ERR_PROT_OVERLOAD 0x20
828 #define CAN_ERR_PROT_ACTIVE 0x40
829 #define CAN_ERR_PROT_TX 0x80
836 /* error in CAN protocol (location) / data[3] */
837 #define CAN_ERR_PROT_LOC_UNSPEC 0x00
838 #define CAN_ERR_PROT_LOC_SOF 0x03
839 #define CAN_ERR_PROT_LOC_ID28_21 0x02
840 #define CAN_ERR_PROT_LOC_ID20_18 0x06
841 #define CAN_ERR_PROT_LOC_SRTR 0x04
842 #define CAN_ERR_PROT_LOC_IDE 0x05
843 #define CAN_ERR_PROT_LOC_ID17_13 0x07
844 #define CAN_ERR_PROT_LOC_ID12_05 0x0F
845 #define CAN_ERR_PROT_LOC_ID04_00 0x0E
846 #define CAN_ERR_PROT_LOC_RTR 0x0C
847 #define CAN_ERR_PROT_LOC_RES1 0x0D
848 #define CAN_ERR_PROT_LOC_RES0 0x09
849 #define CAN_ERR_PROT_LOC_DLC 0x0B
850 #define CAN_ERR_PROT_LOC_DATA 0x0A
851 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08
852 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18
853 #define CAN_ERR_PROT_LOC_ACK 0x19
854 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B
855 #define CAN_ERR_PROT_LOC_EOF 0x1A
856 #define CAN_ERR_PROT_LOC_INTERM 0x12
863 /* error status of CAN-transceiver / data[4] */
864 /* CANH CANL */
865 #define CAN_ERR_TRX_UNSPEC 0x00
866 #define CAN_ERR_TRX_CANH_NO_WIRE 0x04
867 #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05
868 #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06
869 #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07
870 #define CAN_ERR_TRX_CANL_NO_WIRE 0x40
871 #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50
872 #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60
873 #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70
874 #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80
879 #endif /* !_RTDM_UAPI_CAN_H */
uint32_t can_id
CAN ID which must match with incoming IDs after passing the mask.
Definition: can.h:290
Definition: can.h:182
Custom CAN bit-time definition.
Definition: can.h:151
CAN_MODE
Definition: can.h:167
Standard bit-time definition according to Bosch.
Definition: can.h:117
Definition: can.h:174
sa_family_t can_family
CAN address family, must be AF_CAN.
Definition: can.h:302
can_bittime_type_t type
Type of bit-time definition.
Definition: can.h:153
uint8_t sjw
from 1 to 4
Definition: can.h:135
struct can_bittime_std std
Standard bit-time.
Definition: can.h:157
CAN_BITTIME_TYPE
Supported CAN bit-time types.
Definition: can.h:115
CAN controller is error passive.
Definition: can.h:241
CAN controller is error passive.
Definition: can.h:239
Socket address structure for the CAN address family.
Definition: can.h:300
uint8_t data[8] __attribute__((aligned(8)))
Payload data bytes.
CAN_STATE
Definition: can.h:227
Definition: can.h:169
CAN controller is error active, warning level is reached.
Definition: can.h:234
uint32_t can_mask
Mask which is applied to incoming IDs.
Definition: can.h:294
CAN controller went into Bus Off.
Definition: can.h:244
uint32_t can_baudrate_t
Baudrate definition in bits per second.
Definition: can.h:110
uint8_t prop_seg
from 1 to 8
Definition: can.h:132
can_id_t can_id
CAN ID of the frame.
Definition: can.h:318
uint8_t sam
1 - enable triple sampling
Definition: can.h:136
CAN controller is active.
Definition: can.h:231
Raw CAN frame.
Definition: can.h:313
CAN controller is in Sleep mode.
Definition: can.h:253
int can_ifindex
Interface index of CAN controller.
Definition: can.h:305
uint8_t phase_seg2
from 1 to 8
Definition: can.h:134
enum CAN_BITTIME_TYPE can_bittime_type_t
See CAN_BITTIME_TYPE.
Definition: can.h:125
CAN controller is in stopped mode.
Definition: can.h:250
int can_ctrlmode_t
See CAN_CTRLMODE.
Definition: can.h:221
Standard bit-time parameters according to Bosch.
Definition: can.h:130
CAN controller is error active.
Definition: can.h:229
uint8_t btr0
Bus timing register 0.
Definition: can.h:144
can_id_t can_err_mask_t
Type of CAN error mask.
Definition: can.h:64
Filter for reception of CAN messages.
Definition: can.h:287
struct can_frame can_frame_t
Raw CAN frame.
uint8_t phase_seg1
from 1 to 8
Definition: can.h:133
Hardware-specific BTR bit-time definition.
Definition: can.h:119
struct can_filter can_filter_t
Filter for reception of CAN messages.
uint8_t can_dlc
Size of the payload in bytes.
Definition: can.h:321
CAN controller is scanning to get the baudrate.
Definition: can.h:247
enum CAN_STATE can_state_t
See CAN_STATE.
Definition: can.h:258
CAN controller is error active, warning level is reached.
Definition: can.h:236
uint8_t btr1
Bus timing register 1.
Definition: can.h:145
uint32_t can_id_t
Type of CAN id (see CAN_xxx_MASK and CAN_xxx_FLAG)
Definition: can.h:60
struct can_bittime_btr btr
Hardware-spcific BTR bit-time.
Definition: can.h:159
uint32_t brp
Baud rate prescaler.
Definition: can.h:131
Hardware-specific BTR bit-times.
Definition: can.h:142
enum CAN_MODE can_mode_t
See CAN_MODE.
Definition: can.h:187