Xenomai  3.3
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
86 #define CAN_RTR_FLAG 0x40000000
88 #define CAN_ERR_FLAG 0x20000000
90 #define CAN_INV_FILTER CAN_ERR_FLAG
91 
101 #define CAN_RAW 1
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 {
157  struct can_bittime_std std;
159  struct can_bittime_btr btr;
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;
296 
300 struct sockaddr_can {
302  sa_family_t can_family;
303 
306 };
307 
313 typedef struct can_frame {
319 
321  union {
322  uint8_t can_dlc;
323  uint8_t len;
324  };
325 
327  uint8_t data[8] __attribute__ ((aligned(8)));
329 
335 struct can_ifreq {
336  union {
337  char ifrn_name[IFNAMSIZ];
338  } ifr_ifrn;
339 
340  union {
341  struct can_bittime bittime;
342  can_baudrate_t baudrate;
343  can_ctrlmode_t ctrlmode;
344  can_mode_t mode;
345  can_state_t state;
346  int ifru_ivalue;
347  } ifr_ifru;
348 };
349 
354 #define RTCAN_TAKE_NO_TIMESTAMPS 0
355 #define RTCAN_TAKE_TIMESTAMPS 1
358 #define RTIOC_TYPE_CAN RTDM_CLASS_CAN
359 
398 #define CAN_RAW_FILTER 0x1
399 
428 #define CAN_RAW_ERR_FILTER 0x2
429 
456 #define CAN_RAW_LOOPBACK 0x3
457 
464 #define CAN_RAW_RECV_OWN_MSGS 0x4
465 
495 #ifdef DOXYGEN_CPP /* For Doxygen only, already defined by kernel headers */
496 #define SIOCGIFINDEX defined_by_kernel_header_file
497 #endif
498 
525 #define SIOCSCANBAUDRATE _IOW(RTIOC_TYPE_CAN, 0x01, struct can_ifreq)
526 
544 #define SIOCGCANBAUDRATE _IOWR(RTIOC_TYPE_CAN, 0x02, struct can_ifreq)
545 
570 #define SIOCSCANCUSTOMBITTIME _IOW(RTIOC_TYPE_CAN, 0x03, struct can_ifreq)
571 
589 #define SIOCGCANCUSTOMBITTIME _IOWR(RTIOC_TYPE_CAN, 0x04, struct can_ifreq)
590 
624 #define SIOCSCANMODE _IOW(RTIOC_TYPE_CAN, 0x05, struct can_ifreq)
625 
650 #define SIOCGCANSTATE _IOWR(RTIOC_TYPE_CAN, 0x06, struct can_ifreq)
651 
676 #define SIOCSCANCTRLMODE _IOW(RTIOC_TYPE_CAN, 0x07, struct can_ifreq)
677 
696 #define SIOCGCANCTRLMODE _IOWR(RTIOC_TYPE_CAN, 0x08, struct can_ifreq)
697 
715 #define RTCAN_RTIOC_TAKE_TIMESTAMP _IOW(RTIOC_TYPE_CAN, 0x09, int)
716 
740 #define RTCAN_RTIOC_RCV_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0A, nanosecs_rel_t)
741 
765 #define RTCAN_RTIOC_SND_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0B, nanosecs_rel_t)
768 #define CAN_ERR_DLC 8 /* dlc for error frames */
769 
790 #define CAN_ERR_TX_TIMEOUT 0x00000001U
791 
793 #define CAN_ERR_LOSTARB 0x00000002U
794 
796 #define CAN_ERR_CRTL 0x00000004U
797 
800 #define CAN_ERR_PROT 0x00000008U
801 
803 #define CAN_ERR_TRX 0x00000010U
804 
806 #define CAN_ERR_ACK 0x00000020U
807 
809 #define CAN_ERR_BUSOFF 0x00000040U
810 
812 #define CAN_ERR_BUSERROR 0x00000080U
813 
815 #define CAN_ERR_RESTARTED 0x00000100U
816 
818 #define CAN_ERR_MASK 0x1FFFFFFFU
819 
826 /* arbitration lost in bit ... / data[0] */
827 #define CAN_ERR_LOSTARB_UNSPEC 0x00
835 /* error status of CAN-controller / data[1] */
836 #define CAN_ERR_CRTL_UNSPEC 0x00
837 #define CAN_ERR_CRTL_RX_OVERFLOW 0x01
838 #define CAN_ERR_CRTL_TX_OVERFLOW 0x02
839 #define CAN_ERR_CRTL_RX_WARNING 0x04
840 #define CAN_ERR_CRTL_TX_WARNING 0x08
841 #define CAN_ERR_CRTL_RX_PASSIVE 0x10
842 #define CAN_ERR_CRTL_TX_PASSIVE 0x20
843 #define CAN_ERR_CRTL_ACTIVE 0x40
850 /* error in CAN protocol (type) / data[2] */
851 #define CAN_ERR_PROT_UNSPEC 0x00
852 #define CAN_ERR_PROT_BIT 0x01
853 #define CAN_ERR_PROT_FORM 0x02
854 #define CAN_ERR_PROT_STUFF 0x04
855 #define CAN_ERR_PROT_BIT0 0x08
856 #define CAN_ERR_PROT_BIT1 0x10
857 #define CAN_ERR_PROT_OVERLOAD 0x20
858 #define CAN_ERR_PROT_ACTIVE 0x40
859 #define CAN_ERR_PROT_TX 0x80
866 /* error in CAN protocol (location) / data[3] */
867 #define CAN_ERR_PROT_LOC_UNSPEC 0x00
868 #define CAN_ERR_PROT_LOC_SOF 0x03
869 #define CAN_ERR_PROT_LOC_ID28_21 0x02
870 #define CAN_ERR_PROT_LOC_ID20_18 0x06
871 #define CAN_ERR_PROT_LOC_SRTR 0x04
872 #define CAN_ERR_PROT_LOC_IDE 0x05
873 #define CAN_ERR_PROT_LOC_ID17_13 0x07
874 #define CAN_ERR_PROT_LOC_ID12_05 0x0F
875 #define CAN_ERR_PROT_LOC_ID04_00 0x0E
876 #define CAN_ERR_PROT_LOC_RTR 0x0C
877 #define CAN_ERR_PROT_LOC_RES1 0x0D
878 #define CAN_ERR_PROT_LOC_RES0 0x09
879 #define CAN_ERR_PROT_LOC_DLC 0x0B
880 #define CAN_ERR_PROT_LOC_DATA 0x0A
881 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08
882 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18
883 #define CAN_ERR_PROT_LOC_ACK 0x19
884 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B
885 #define CAN_ERR_PROT_LOC_EOF 0x1A
886 #define CAN_ERR_PROT_LOC_INTERM 0x12
893 /* error status of CAN-transceiver / data[4] */
894 /* CANH CANL */
895 #define CAN_ERR_TRX_UNSPEC 0x00
896 #define CAN_ERR_TRX_CANH_NO_WIRE 0x04
897 #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05
898 #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06
899 #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07
900 #define CAN_ERR_TRX_CANL_NO_WIRE 0x40
901 #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50
902 #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60
903 #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70
904 #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80
909 #endif /* !_RTDM_UAPI_CAN_H */
enum CAN_STATE can_state_t
See CAN_STATE.
Definition: can.h:258
uint32_t can_baudrate_t
Baudrate definition in bits per second.
Definition: can.h:110
CAN_BITTIME_TYPE
Supported CAN bit-time types.
Definition: can.h:115
enum CAN_MODE can_mode_t
See CAN_MODE.
Definition: can.h:187
CAN_STATE
Definition: can.h:227
struct can_frame can_frame_t
Raw CAN frame.
enum CAN_BITTIME_TYPE can_bittime_type_t
See CAN_BITTIME_TYPE.
Definition: can.h:125
int can_ctrlmode_t
See CAN_CTRLMODE.
Definition: can.h:221
CAN_MODE
Definition: can.h:167
uint32_t can_id_t
Type of CAN id (see CAN_xxx_MASK and CAN_xxx_FLAG)
Definition: can.h:60
struct can_filter can_filter_t
Filter for reception of CAN messages.
can_id_t can_err_mask_t
Type of CAN error mask.
Definition: can.h:64
@ CAN_BITTIME_STD
Standard bit-time definition according to Bosch.
Definition: can.h:117
@ CAN_BITTIME_BTR
Hardware-specific BTR bit-time definition.
Definition: can.h:119
@ CAN_STATE_ERROR_ACTIVE
CAN controller is error active.
Definition: can.h:229
@ CAN_STATE_ERROR_WARNING
CAN controller is error active, warning level is reached.
Definition: can.h:234
@ CAN_STATE_BUS_PASSIVE
CAN controller is error passive.
Definition: can.h:241
@ CAN_STATE_SLEEPING
CAN controller is in Sleep mode.
Definition: can.h:253
@ CAN_STATE_STOPPED
CAN controller is in stopped mode.
Definition: can.h:250
@ CAN_STATE_BUS_OFF
CAN controller went into Bus Off.
Definition: can.h:244
@ CAN_STATE_ACTIVE
CAN controller is active.
Definition: can.h:231
@ CAN_STATE_BUS_WARNING
CAN controller is error active, warning level is reached.
Definition: can.h:236
@ CAN_STATE_ERROR_PASSIVE
CAN controller is error passive.
Definition: can.h:239
@ CAN_STATE_SCANNING_BAUDRATE
CAN controller is scanning to get the baudrate.
Definition: can.h:247
@ CAN_MODE_STOP
Definition: can.h:169
@ CAN_MODE_SLEEP
Definition: can.h:182
@ CAN_MODE_START
Definition: can.h:174
Hardware-specific BTR bit-times.
Definition: can.h:142
uint8_t btr0
Bus timing register 0.
Definition: can.h:144
uint8_t btr1
Bus timing register 1.
Definition: can.h:145
Standard bit-time parameters according to Bosch.
Definition: can.h:130
uint8_t prop_seg
from 1 to 8
Definition: can.h:132
uint32_t brp
Baud rate prescaler.
Definition: can.h:131
uint8_t sjw
from 1 to 4
Definition: can.h:135
uint8_t phase_seg1
from 1 to 8
Definition: can.h:133
uint8_t phase_seg2
from 1 to 8
Definition: can.h:134
uint8_t sam
1 - enable triple sampling
Definition: can.h:136
Custom CAN bit-time definition.
Definition: can.h:151
struct can_bittime_btr btr
Hardware-spcific BTR bit-time.
Definition: can.h:159
struct can_bittime_std std
Standard bit-time.
Definition: can.h:157
can_bittime_type_t type
Type of bit-time definition.
Definition: can.h:153
Filter for reception of CAN messages.
Definition: can.h:287
uint32_t can_id
CAN ID which must match with incoming IDs after passing the mask.
Definition: can.h:290
uint32_t can_mask
Mask which is applied to incoming IDs.
Definition: can.h:294
Raw CAN frame.
Definition: can.h:313
can_id_t can_id
CAN ID of the frame.
Definition: can.h:318
uint8_t data[8] __attribute__((aligned(8)))
Payload data bytes.
CAN interface request descriptor.
Definition: can.h:335
Socket address structure for the CAN address family.
Definition: can.h:300
sa_family_t can_family
CAN address family, must be AF_CAN.
Definition: can.h:302
int can_ifindex
Interface index of CAN controller.
Definition: can.h:305