Xenomai  3.1
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 
332 struct can_ifreq {
333  union {
334  char ifrn_name[IFNAMSIZ];
335  } ifr_ifrn;
336 
337  union {
338  struct can_bittime bittime;
339  can_baudrate_t baudrate;
340  can_ctrlmode_t ctrlmode;
341  can_mode_t mode;
342  can_state_t state;
343  int ifru_ivalue;
344  } ifr_ifru;
345 };
346 
351 #define RTCAN_TAKE_NO_TIMESTAMPS 0
352 #define RTCAN_TAKE_TIMESTAMPS 1
355 #define RTIOC_TYPE_CAN RTDM_CLASS_CAN
356 
395 #define CAN_RAW_FILTER 0x1
425 #define CAN_RAW_ERR_FILTER 0x2
426 
453 #define CAN_RAW_LOOPBACK 0x3
454 
461 #define CAN_RAW_RECV_OWN_MSGS 0x4
462 
492 #ifdef DOXYGEN_CPP /* For Doxygen only, already defined by kernel headers */
493 #define SIOCGIFINDEX defined_by_kernel_header_file
494 #endif
495 
522 #define SIOCSCANBAUDRATE _IOW(RTIOC_TYPE_CAN, 0x01, struct can_ifreq)
523 
541 #define SIOCGCANBAUDRATE _IOWR(RTIOC_TYPE_CAN, 0x02, struct can_ifreq)
542 
567 #define SIOCSCANCUSTOMBITTIME _IOW(RTIOC_TYPE_CAN, 0x03, struct can_ifreq)
568 
586 #define SIOCGCANCUSTOMBITTIME _IOWR(RTIOC_TYPE_CAN, 0x04, struct can_ifreq)
587 
621 #define SIOCSCANMODE _IOW(RTIOC_TYPE_CAN, 0x05, struct can_ifreq)
622 
647 #define SIOCGCANSTATE _IOWR(RTIOC_TYPE_CAN, 0x06, struct can_ifreq)
648 
673 #define SIOCSCANCTRLMODE _IOW(RTIOC_TYPE_CAN, 0x07, struct can_ifreq)
674 
693 #define SIOCGCANCTRLMODE _IOWR(RTIOC_TYPE_CAN, 0x08, struct can_ifreq)
694 
712 #define RTCAN_RTIOC_TAKE_TIMESTAMP _IOW(RTIOC_TYPE_CAN, 0x09, int)
713 
737 #define RTCAN_RTIOC_RCV_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0A, nanosecs_rel_t)
738 
762 #define RTCAN_RTIOC_SND_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0B, nanosecs_rel_t)
763 
765 #define CAN_ERR_DLC 8 /* dlc for error frames */
766 
787 #define CAN_ERR_TX_TIMEOUT 0x00000001U
788 
790 #define CAN_ERR_LOSTARB 0x00000002U
791 
793 #define CAN_ERR_CRTL 0x00000004U
794 
797 #define CAN_ERR_PROT 0x00000008U
798 
800 #define CAN_ERR_TRX 0x00000010U
801 
803 #define CAN_ERR_ACK 0x00000020U
804 
806 #define CAN_ERR_BUSOFF 0x00000040U
807 
809 #define CAN_ERR_BUSERROR 0x00000080U
810 
812 #define CAN_ERR_RESTARTED 0x00000100U
813 
815 #define CAN_ERR_MASK 0x1FFFFFFFU
816 
823 /* arbitration lost in bit ... / data[0] */
824 #define CAN_ERR_LOSTARB_UNSPEC 0x00
832 /* error status of CAN-controller / data[1] */
833 #define CAN_ERR_CRTL_UNSPEC 0x00
834 #define CAN_ERR_CRTL_RX_OVERFLOW 0x01
835 #define CAN_ERR_CRTL_TX_OVERFLOW 0x02
836 #define CAN_ERR_CRTL_RX_WARNING 0x04
837 #define CAN_ERR_CRTL_TX_WARNING 0x08
838 #define CAN_ERR_CRTL_RX_PASSIVE 0x10
839 #define CAN_ERR_CRTL_TX_PASSIVE 0x20
846 /* error in CAN protocol (type) / data[2] */
847 #define CAN_ERR_PROT_UNSPEC 0x00
848 #define CAN_ERR_PROT_BIT 0x01
849 #define CAN_ERR_PROT_FORM 0x02
850 #define CAN_ERR_PROT_STUFF 0x04
851 #define CAN_ERR_PROT_BIT0 0x08
852 #define CAN_ERR_PROT_BIT1 0x10
853 #define CAN_ERR_PROT_OVERLOAD 0x20
854 #define CAN_ERR_PROT_ACTIVE 0x40
855 #define CAN_ERR_PROT_TX 0x80
862 /* error in CAN protocol (location) / data[3] */
863 #define CAN_ERR_PROT_LOC_UNSPEC 0x00
864 #define CAN_ERR_PROT_LOC_SOF 0x03
865 #define CAN_ERR_PROT_LOC_ID28_21 0x02
866 #define CAN_ERR_PROT_LOC_ID20_18 0x06
867 #define CAN_ERR_PROT_LOC_SRTR 0x04
868 #define CAN_ERR_PROT_LOC_IDE 0x05
869 #define CAN_ERR_PROT_LOC_ID17_13 0x07
870 #define CAN_ERR_PROT_LOC_ID12_05 0x0F
871 #define CAN_ERR_PROT_LOC_ID04_00 0x0E
872 #define CAN_ERR_PROT_LOC_RTR 0x0C
873 #define CAN_ERR_PROT_LOC_RES1 0x0D
874 #define CAN_ERR_PROT_LOC_RES0 0x09
875 #define CAN_ERR_PROT_LOC_DLC 0x0B
876 #define CAN_ERR_PROT_LOC_DATA 0x0A
877 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08
878 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18
879 #define CAN_ERR_PROT_LOC_ACK 0x19
880 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B
881 #define CAN_ERR_PROT_LOC_EOF 0x1A
882 #define CAN_ERR_PROT_LOC_INTERM 0x12
889 /* error status of CAN-transceiver / data[4] */
890 /* CANH CANL */
891 #define CAN_ERR_TRX_UNSPEC 0x00
892 #define CAN_ERR_TRX_CANH_NO_WIRE 0x04
893 #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05
894 #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06
895 #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07
896 #define CAN_ERR_TRX_CANL_NO_WIRE 0x40
897 #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50
898 #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60
899 #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70
900 #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80
905 #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
CAN interface request descriptor.
Definition: can.h:332
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