Xenomai API  2.6.5
rtcan.h
Go to the documentation of this file.
1 
236 #ifndef _RTCAN_H
237 #define _RTCAN_H
238 
239 #ifdef __KERNEL__
240 
241 #include <linux/net.h>
242 #include <linux/socket.h>
243 #include <linux/if.h>
244 
245 #else /* !__KERNEL__ */
246 
247 #include <net/if.h>
248 
249 #endif /* !__KERNEL__ */
250 
251 #include <rtdm/rtdm.h>
252 
253 #define RTCAN_PROFILE_VER 2
254 
255 #ifndef AF_CAN
256 
258 #define AF_CAN 29
259 
261 #define PF_CAN AF_CAN
262 
263 #endif
264 
269 #define SOL_CAN_RAW 103
270 
272 typedef uint32_t can_id_t;
273 typedef uint32_t canid_t;
274 
277 
284 #define CAN_EFF_MASK 0x1FFFFFFF
285 
287 #define CAN_SFF_MASK 0x000007FF
288 
296 #define CAN_EFF_FLAG 0x80000000
297 
298 #define CAN_RTR_FLAG 0x40000000
299 
300 #define CAN_ERR_FLAG 0x20000000
301 
302 #define CAN_INV_FILTER CAN_ERR_FLAG
303 
313 #define CAN_RAW 1
314 
316 #define CAN_BAUDRATE_UNKNOWN ((uint32_t)-1)
317 #define CAN_BAUDRATE_UNCONFIGURED 0
318 
322 typedef uint32_t can_baudrate_t;
323 
332 };
333 
338 
343  uint32_t brp;
344  uint8_t prop_seg;
345  uint8_t phase_seg1;
346  uint8_t phase_seg2;
347  uint8_t sjw:7;
348  uint8_t sam:1;
349 };
350 
355 
356  uint8_t btr0;
357  uint8_t btr1;
358 };
359 
363 struct can_bittime {
366 
367  union {
372  };
373 };
374 
379 enum CAN_MODE {
382 
387 
395 };
399 typedef enum CAN_MODE can_mode_t;
400 
416 #define CAN_CTRLMODE_LISTENONLY 0x1
417 
423 #define CAN_CTRLMODE_LOOPBACK 0x2
424 
428 #define CAN_CTRLMODE_3_SAMPLES 0x4
429 
433 typedef int can_ctrlmode_t;
434 
439 enum CAN_STATE {
442  CAN_STATE_ACTIVE = 0,
443 
446  CAN_STATE_BUS_WARNING = 1,
447 
450  CAN_STATE_BUS_PASSIVE = 2,
451 
454 
457 
460 
463 };
467 typedef enum CAN_STATE can_state_t;
468 
469 #define CAN_STATE_OPERATING(state) ((state) < CAN_STATE_BUS_OFF)
470 
496 typedef struct can_filter {
499  uint32_t can_id;
500 
503  uint32_t can_mask;
504 } can_filter_t;
505 
509 struct sockaddr_can {
511  sa_family_t can_family;
512 
515 };
516 
522 typedef struct can_frame {
528 
530  uint8_t can_dlc;
531 
533  uint8_t data[8] __attribute__ ((aligned(8)));
534 } can_frame_t;
535 
540 #define RTCAN_TAKE_NO_TIMESTAMPS 0
541 #define RTCAN_TAKE_TIMESTAMPS 1
544 #define RTIOC_TYPE_CAN RTDM_CLASS_CAN
545 
584 #define CAN_RAW_FILTER 0x1
585 
614 #define CAN_RAW_ERR_FILTER 0x2
615 
642 #define CAN_RAW_LOOPBACK 0x3
643 
650 #define CAN_RAW_RECV_OWN_MSGS 0x4
651 
684 #ifdef DOXYGEN_CPP /* For Doxygen only, already defined by kernel headers */
685 #define SIOCGIFINDEX defined_by_kernel_header_file
686 #endif
687 
722 #define SIOCSCANBAUDRATE _IOW(RTIOC_TYPE_CAN, 0x01, struct ifreq)
723 
749 #define SIOCGCANBAUDRATE _IOWR(RTIOC_TYPE_CAN, 0x02, struct ifreq)
750 
783 #define SIOCSCANCUSTOMBITTIME _IOW(RTIOC_TYPE_CAN, 0x03, struct ifreq)
784 
810 #define SIOCGCANCUSTOMBITTIME _IOWR(RTIOC_TYPE_CAN, 0x04, struct ifreq)
811 
853 #define SIOCSCANMODE _IOW(RTIOC_TYPE_CAN, 0x05, struct ifreq)
854 
887 #define SIOCGCANSTATE _IOWR(RTIOC_TYPE_CAN, 0x06, struct ifreq)
888 
921 #define SIOCSCANCTRLMODE _IOW(RTIOC_TYPE_CAN, 0x07, struct ifreq)
922 
949 #define SIOCGCANCTRLMODE _IOWR(RTIOC_TYPE_CAN, 0x08, struct ifreq)
950 
976 #define RTCAN_RTIOC_TAKE_TIMESTAMP _IOW(RTIOC_TYPE_CAN, 0x09, int)
977 
1009 #define RTCAN_RTIOC_RCV_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0A, nanosecs_rel_t)
1010 
1042 #define RTCAN_RTIOC_SND_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0B, nanosecs_rel_t)
1043 
1045 #define CAN_ERR_DLC 8 /* dlc for error frames */
1046 
1067 #define CAN_ERR_TX_TIMEOUT 0x00000001U
1068 
1070 #define CAN_ERR_LOSTARB 0x00000002U
1071 
1073 #define CAN_ERR_CRTL 0x00000004U
1074 
1077 #define CAN_ERR_PROT 0x00000008U
1078 
1080 #define CAN_ERR_TRX 0x00000010U
1081 
1083 #define CAN_ERR_ACK 0x00000020U
1084 
1086 #define CAN_ERR_BUSOFF 0x00000040U
1087 
1089 #define CAN_ERR_BUSERROR 0x00000080U
1090 
1092 #define CAN_ERR_RESTARTED 0x00000100U
1093 
1095 #define CAN_ERR_MASK 0x1FFFFFFFU
1096 
1103 /* arbitration lost in bit ... / data[0] */
1104 #define CAN_ERR_LOSTARB_UNSPEC 0x00
1112 /* error status of CAN-controller / data[1] */
1113 #define CAN_ERR_CRTL_UNSPEC 0x00
1114 #define CAN_ERR_CRTL_RX_OVERFLOW 0x01
1115 #define CAN_ERR_CRTL_TX_OVERFLOW 0x02
1116 #define CAN_ERR_CRTL_RX_WARNING 0x04
1117 #define CAN_ERR_CRTL_TX_WARNING 0x08
1118 #define CAN_ERR_CRTL_RX_PASSIVE 0x10
1119 #define CAN_ERR_CRTL_TX_PASSIVE 0x20
1126 /* error in CAN protocol (type) / data[2] */
1127 #define CAN_ERR_PROT_UNSPEC 0x00
1128 #define CAN_ERR_PROT_BIT 0x01
1129 #define CAN_ERR_PROT_FORM 0x02
1130 #define CAN_ERR_PROT_STUFF 0x04
1131 #define CAN_ERR_PROT_BIT0 0x08
1132 #define CAN_ERR_PROT_BIT1 0x10
1133 #define CAN_ERR_PROT_OVERLOAD 0x20
1134 #define CAN_ERR_PROT_ACTIVE 0x40
1135 #define CAN_ERR_PROT_TX 0x80
1142 /* error in CAN protocol (location) / data[3] */
1143 #define CAN_ERR_PROT_LOC_UNSPEC 0x00
1144 #define CAN_ERR_PROT_LOC_SOF 0x03
1145 #define CAN_ERR_PROT_LOC_ID28_21 0x02
1146 #define CAN_ERR_PROT_LOC_ID20_18 0x06
1147 #define CAN_ERR_PROT_LOC_SRTR 0x04
1148 #define CAN_ERR_PROT_LOC_IDE 0x05
1149 #define CAN_ERR_PROT_LOC_ID17_13 0x07
1150 #define CAN_ERR_PROT_LOC_ID12_05 0x0F
1151 #define CAN_ERR_PROT_LOC_ID04_00 0x0E
1152 #define CAN_ERR_PROT_LOC_RTR 0x0C
1153 #define CAN_ERR_PROT_LOC_RES1 0x0D
1154 #define CAN_ERR_PROT_LOC_RES0 0x09
1155 #define CAN_ERR_PROT_LOC_DLC 0x0B
1156 #define CAN_ERR_PROT_LOC_DATA 0x0A
1157 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08
1158 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18
1159 #define CAN_ERR_PROT_LOC_ACK 0x19
1160 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B
1161 #define CAN_ERR_PROT_LOC_EOF 0x1A
1162 #define CAN_ERR_PROT_LOC_INTERM 0x12
1169 /* error status of CAN-transceiver / data[4] */
1170 /* CANH CANL */
1171 #define CAN_ERR_TRX_UNSPEC 0x00
1172 #define CAN_ERR_TRX_CANH_NO_WIRE 0x04
1173 #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05
1174 #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06
1175 #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07
1176 #define CAN_ERR_TRX_CANL_NO_WIRE 0x40
1177 #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50
1178 #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60
1179 #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70
1180 #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80
1183 /* controller specific additional information / data[5..7] */
1184 
1198 #endif /* _RTCAN_H */
uint32_t can_id
CAN ID which must match with incoming IDs after passing the mask.
Definition: rtcan.h:499
uint32_t can_id_t
Type of CAN id (see CAN_xxx_MASK and CAN_xxx_FLAG)
Definition: rtcan.h:272
CAN_STATE
Definition: rtcan.h:439
Hardware-specific BTR bit-time definition.
Definition: rtcan.h:331
CAN controller is error active, warning level is reached.
Definition: rtcan.h:445
Custom CAN bit-time definition.
Definition: rtcan.h:363
enum CAN_MODE can_mode_t
See CAN_MODE.
Definition: rtcan.h:399
enum CAN_STATE can_state_t
See CAN_STATE.
Definition: rtcan.h:467
struct can_filter can_filter_t
Filter for reception of CAN messages.
sa_family_t can_family
CAN address family, must be AF_CAN.
Definition: rtcan.h:511
can_bittime_type_t type
Type of bit-time definition.
Definition: rtcan.h:365
uint8_t sjw
from 1 to 4
Definition: rtcan.h:347
struct can_bittime_std std
Standard bit-time.
Definition: rtcan.h:369
uint32_t can_baudrate_t
Baudrate definition in bits per second.
Definition: rtcan.h:322
CAN_BITTIME_TYPE
Supported CAN bit-time types.
Definition: rtcan.h:327
CAN controller is scanning to get the baudrate.
Definition: rtcan.h:456
Socket address structure for the CAN address family.
Definition: rtcan.h:509
CAN controller is in stopped mode.
Definition: rtcan.h:459
uint8_t data[8] __attribute__((aligned(8)))
Payload data bytes.
uint32_t can_mask
Mask which is applied to incoming IDs.
Definition: rtcan.h:503
uint8_t prop_seg
from 1 to 8
Definition: rtcan.h:344
can_id_t can_id
CAN ID of the frame.
Definition: rtcan.h:527
uint8_t sam
1 - enable triple sampling
Definition: rtcan.h:348
CAN controller is error active.
Definition: rtcan.h:441
struct can_frame can_frame_t
Raw CAN frame.
Definition: rtcan.h:394
int can_ctrlmode_t
See CAN_CTRLMODE.
Definition: rtcan.h:433
Raw CAN frame.
Definition: rtcan.h:522
Definition: rtcan.h:386
Definition: rtcan.h:381
int can_ifindex
Interface index of CAN controller.
Definition: rtcan.h:514
CAN controller went into Bus Off.
Definition: rtcan.h:453
CAN controller is in Sleep mode.
Definition: rtcan.h:462
uint8_t phase_seg2
from 1 to 8
Definition: rtcan.h:346
Standard bit-time parameters according to Bosch.
Definition: rtcan.h:342
CAN_MODE
Definition: rtcan.h:379
CAN controller is error passive.
Definition: rtcan.h:449
uint8_t btr0
Bus timing register 0.
Definition: rtcan.h:356
Filter for reception of CAN messages.
Definition: rtcan.h:496
can_id_t can_err_mask_t
Type of CAN error mask.
Definition: rtcan.h:276
uint8_t phase_seg1
from 1 to 8
Definition: rtcan.h:345
uint8_t can_dlc
Size of the payload in bytes.
Definition: rtcan.h:530
enum CAN_BITTIME_TYPE can_bittime_type_t
See CAN_BITTIME_TYPE.
Definition: rtcan.h:337
Standard bit-time definition according to Bosch.
Definition: rtcan.h:329
uint8_t btr1
Bus timing register 1.
Definition: rtcan.h:357
struct can_bittime_btr btr
Hardware-spcific BTR bit-time.
Definition: rtcan.h:371
uint32_t brp
Baud rate prescaler.
Definition: rtcan.h:343
Hardware-specific BTR bit-times.
Definition: rtcan.h:354
Real-Time Driver Model for Xenomai, user API header.