Xenomai API
2.5.6.1
|
00001 00236 #ifndef _RTCAN_H 00237 #define _RTCAN_H 00238 00239 #ifdef __KERNEL__ 00240 00241 #include <linux/net.h> 00242 #include <linux/socket.h> 00243 #include <linux/if.h> 00244 00245 #else /* !__KERNEL__ */ 00246 00247 #include <net/if.h> 00248 00249 #endif /* !__KERNEL__ */ 00250 00251 #include <rtdm/rtdm.h> 00252 00253 #define RTCAN_PROFILE_VER 2 00254 00255 #ifndef AF_CAN 00256 00258 #define AF_CAN 29 00259 00261 #define PF_CAN AF_CAN 00262 00263 #endif 00264 00269 #define SOL_CAN_RAW 103 00270 00272 typedef uint32_t can_id_t; 00273 typedef uint32_t canid_t; 00274 00276 typedef can_id_t can_err_mask_t; 00277 00284 #define CAN_EFF_MASK 0x1FFFFFFF 00285 00287 #define CAN_SFF_MASK 0x000007FF 00288 00296 #define CAN_EFF_FLAG 0x80000000 00297 00298 #define CAN_RTR_FLAG 0x40000000 00299 00300 #define CAN_ERR_FLAG 0x20000000 00301 00302 #define CAN_INV_FILTER CAN_ERR_FLAG 00303 00313 #define CAN_RAW 1 00314 00316 #define CAN_BAUDRATE_UNKNOWN ((uint32_t)-1) 00317 #define CAN_BAUDRATE_UNCONFIGURED 0 00318 00322 typedef uint32_t can_baudrate_t; 00323 00327 enum CAN_BITTIME_TYPE { 00329 CAN_BITTIME_STD, 00331 CAN_BITTIME_BTR 00332 }; 00333 00337 typedef enum CAN_BITTIME_TYPE can_bittime_type_t; 00338 00342 struct can_bittime_std { 00343 uint32_t brp; 00344 uint8_t prop_seg; 00345 uint8_t phase_seg1; 00346 uint8_t phase_seg2; 00347 uint8_t sjw:7; 00348 uint8_t sam:1; 00349 }; 00350 00354 struct can_bittime_btr { 00355 00356 uint8_t btr0; 00357 uint8_t btr1; 00358 }; 00359 00363 struct can_bittime { 00365 can_bittime_type_t type; 00366 00367 union { 00369 struct can_bittime_std std; 00371 struct can_bittime_btr btr; 00372 }; 00373 }; 00374 00379 enum CAN_MODE { 00381 CAN_MODE_STOP = 0, 00382 00386 CAN_MODE_START, 00387 00394 CAN_MODE_SLEEP 00395 }; 00399 typedef enum CAN_MODE can_mode_t; 00400 00416 #define CAN_CTRLMODE_LISTENONLY 0x1 00417 00423 #define CAN_CTRLMODE_LOOPBACK 0x2 00424 00428 typedef int can_ctrlmode_t; 00429 00434 enum CAN_STATE { 00436 CAN_STATE_ACTIVE = 0, 00437 00439 CAN_STATE_BUS_WARNING, 00440 00442 CAN_STATE_BUS_PASSIVE, 00443 00445 CAN_STATE_BUS_OFF, 00446 00448 CAN_STATE_SCANNING_BAUDRATE, 00449 00451 CAN_STATE_STOPPED, 00452 00454 CAN_STATE_SLEEPING, 00455 }; 00459 typedef enum CAN_STATE can_state_t; 00460 00461 #define CAN_STATE_OPERATING(state) ((state) < CAN_STATE_BUS_OFF) 00462 00488 typedef struct can_filter { 00491 uint32_t can_id; 00492 00495 uint32_t can_mask; 00496 } can_filter_t; 00497 00501 struct sockaddr_can { 00503 sa_family_t can_family; 00504 00506 int can_ifindex; 00507 }; 00508 00514 typedef struct can_frame { 00519 can_id_t can_id; 00520 00522 uint8_t can_dlc; 00523 00525 uint8_t data[8] __attribute__ ((aligned(8))); 00526 } can_frame_t; 00527 00532 #define RTCAN_TAKE_NO_TIMESTAMPS 0 00533 #define RTCAN_TAKE_TIMESTAMPS 1 00536 #define RTIOC_TYPE_CAN RTDM_CLASS_CAN 00537 00576 #define CAN_RAW_FILTER 0x1 00577 00606 #define CAN_RAW_ERR_FILTER 0x2 00607 00634 #define CAN_RAW_LOOPBACK 0x3 00635 00642 #define CAN_RAW_RECV_OWN_MSGS 0x4 00643 00676 #ifdef DOXYGEN_CPP /* For Doxygen only, already defined by kernel headers */ 00677 #define SIOCGIFINDEX defined_by_kernel_header_file 00678 #endif 00679 00714 #define SIOCSCANBAUDRATE _IOW(RTIOC_TYPE_CAN, 0x01, struct ifreq) 00715 00741 #define SIOCGCANBAUDRATE _IOWR(RTIOC_TYPE_CAN, 0x02, struct ifreq) 00742 00775 #define SIOCSCANCUSTOMBITTIME _IOW(RTIOC_TYPE_CAN, 0x03, struct ifreq) 00776 00802 #define SIOCGCANCUSTOMBITTIME _IOWR(RTIOC_TYPE_CAN, 0x04, struct ifreq) 00803 00845 #define SIOCSCANMODE _IOW(RTIOC_TYPE_CAN, 0x05, struct ifreq) 00846 00879 #define SIOCGCANSTATE _IOWR(RTIOC_TYPE_CAN, 0x06, struct ifreq) 00880 00913 #define SIOCSCANCTRLMODE _IOW(RTIOC_TYPE_CAN, 0x07, struct ifreq) 00914 00941 #define SIOCGCANCTRLMODE _IOWR(RTIOC_TYPE_CAN, 0x08, struct ifreq) 00942 00968 #define RTCAN_RTIOC_TAKE_TIMESTAMP _IOW(RTIOC_TYPE_CAN, 0x09, int) 00969 01001 #define RTCAN_RTIOC_RCV_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0A, nanosecs_rel_t) 01002 01034 #define RTCAN_RTIOC_SND_TIMEOUT _IOW(RTIOC_TYPE_CAN, 0x0B, nanosecs_rel_t) 01035 01037 #define CAN_ERR_DLC 8 /* dlc for error frames */ 01038 01059 #define CAN_ERR_TX_TIMEOUT 0x00000001U 01060 01062 #define CAN_ERR_LOSTARB 0x00000002U 01063 01065 #define CAN_ERR_CRTL 0x00000004U 01066 01069 #define CAN_ERR_PROT 0x00000008U 01070 01072 #define CAN_ERR_TRX 0x00000010U 01073 01075 #define CAN_ERR_ACK 0x00000020U 01076 01078 #define CAN_ERR_BUSOFF 0x00000040U 01079 01081 #define CAN_ERR_BUSERROR 0x00000080U 01082 01084 #define CAN_ERR_RESTARTED 0x00000100U 01085 01087 #define CAN_ERR_MASK 0x1FFFFFFFU 01088 01095 /* arbitration lost in bit ... / data[0] */ 01096 #define CAN_ERR_LOSTARB_UNSPEC 0x00 01104 /* error status of CAN-controller / data[1] */ 01105 #define CAN_ERR_CRTL_UNSPEC 0x00 01106 #define CAN_ERR_CRTL_RX_OVERFLOW 0x01 01107 #define CAN_ERR_CRTL_TX_OVERFLOW 0x02 01108 #define CAN_ERR_CRTL_RX_WARNING 0x04 01109 #define CAN_ERR_CRTL_TX_WARNING 0x08 01110 #define CAN_ERR_CRTL_RX_PASSIVE 0x10 01111 #define CAN_ERR_CRTL_TX_PASSIVE 0x20 01118 /* error in CAN protocol (type) / data[2] */ 01119 #define CAN_ERR_PROT_UNSPEC 0x00 01120 #define CAN_ERR_PROT_BIT 0x01 01121 #define CAN_ERR_PROT_FORM 0x02 01122 #define CAN_ERR_PROT_STUFF 0x04 01123 #define CAN_ERR_PROT_BIT0 0x08 01124 #define CAN_ERR_PROT_BIT1 0x10 01125 #define CAN_ERR_PROT_OVERLOAD 0x20 01126 #define CAN_ERR_PROT_ACTIVE 0x40 01127 #define CAN_ERR_PROT_TX 0x80 01134 /* error in CAN protocol (location) / data[3] */ 01135 #define CAN_ERR_PROT_LOC_UNSPEC 0x00 01136 #define CAN_ERR_PROT_LOC_SOF 0x03 01137 #define CAN_ERR_PROT_LOC_ID28_21 0x02 01138 #define CAN_ERR_PROT_LOC_ID20_18 0x06 01139 #define CAN_ERR_PROT_LOC_SRTR 0x04 01140 #define CAN_ERR_PROT_LOC_IDE 0x05 01141 #define CAN_ERR_PROT_LOC_ID17_13 0x07 01142 #define CAN_ERR_PROT_LOC_ID12_05 0x0F 01143 #define CAN_ERR_PROT_LOC_ID04_00 0x0E 01144 #define CAN_ERR_PROT_LOC_RTR 0x0C 01145 #define CAN_ERR_PROT_LOC_RES1 0x0D 01146 #define CAN_ERR_PROT_LOC_RES0 0x09 01147 #define CAN_ERR_PROT_LOC_DLC 0x0B 01148 #define CAN_ERR_PROT_LOC_DATA 0x0A 01149 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 01150 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 01151 #define CAN_ERR_PROT_LOC_ACK 0x19 01152 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B 01153 #define CAN_ERR_PROT_LOC_EOF 0x1A 01154 #define CAN_ERR_PROT_LOC_INTERM 0x12 01161 /* error status of CAN-transceiver / data[4] */ 01162 /* CANH CANL */ 01163 #define CAN_ERR_TRX_UNSPEC 0x00 01164 #define CAN_ERR_TRX_CANH_NO_WIRE 0x04 01165 #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 01166 #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 01167 #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 01168 #define CAN_ERR_TRX_CANL_NO_WIRE 0x40 01169 #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 01170 #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 01171 #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 01172 #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 01175 /* controller specific additional information / data[5..7] */ 01176 01190 #endif /* _RTCAN_H */