CAN bus: Difference between revisions
No edit summary |
|||
| Line 104: | Line 104: | ||
* ACK failure -- transmitter did not see a dominant signal in the ACK slot | * ACK failure -- transmitter did not see a dominant signal in the ACK slot | ||
* CRC failure -- received CRC did not match computed CRC | * CRC failure -- received CRC did not match computed CRC | ||
==Linux== | |||
You really, really want a device with a SocketCAN driver. | |||
===SocketCAN=== | |||
SocketCAN drivers expose the CAN interface as a standard networking device, visible in <tt>/sys/class/net</tt>, and usable via the Berkeley Sockets Layer via the PF_CAN protocol family. SocketCAN is documented in <tt>Documentation/networking/can.txt</tt>. Protocol types include: | |||
* SOCK_RAW/CAN_RAW: Raw RX/TX | |||
** CAN_RAW_ERR_FILTER: control passing of Error Frames to the socket (default: disabled) | |||
** CAN_RAW_LOOPBACK: control whether transmitted frames are seen by other listeners on the host (default: enabled) | |||
** CAN_RAW_RECV_OWN_MSGS: if CAN_RAW_LOOPBACK is used, control whether transmitter sees their own frames (default: disabled) | |||
** CAN_RAW_FD_FRAMES: control RX/TX of CAN FD frames (and CANFD_MTU) | |||
*** Determine whether a device is capable of CAN FD by checking its advertised MTU | |||
* SOCK_DGRAM/CAN_BCM: Broadcast Manager mode, used for cyclic transmissions typical of sensor ECUs | |||
** Also simple timer-based interface for cyclic RX with failure notification | |||
===iproute=== | |||
SocketCAN devices, including virtual interfaces (<tt>vcanX</tt>), are configured with the standard <tt>iproute</tt> tool. | |||
* Get statistics: <tt>ip -details -statistics link show canX</tt> | |||
** Alternatively, look at <tt>/proc/net/can/stats</tt> | |||
Options for the device include: | |||
* <tt>restart-ms</tt>: automatic restart time in milliseconds in the event of bus-off state | |||
** <tt>restart</tt> can be used by itself for one-time bus recovery | |||
** A restart will send an error frame | |||
* <tt>one-shot</tt>: don't attempt to retransmit when we don't see an ACK | |||
** Note: when sniffing a <b>non-virtual</b> CAN interface, you must either (a) see an ACK -- requiring a connected device, or (b) be in one-shot mode, or you will not see your transmitted frames | |||
* <tt>bitrate</tt>: bits per second, i.e. "125000". | |||
** If CONFIG_CAN_CALC_BITTIMING is enabled in the kernel, this will set CiA timing parameters for the known bitrate. | |||
** Otherwise, they should be tediously provided via "tq", "prop_seg", "phase_seg1", "phase_seg2", and "sjw". | |||
** Additional controller-specific timing options can be discovered via <tt>ip -details</tt> | |||
* <tt>triple-sampling</tt>: whether to sample between each of the 4 bit quanta | |||
* <tt>berr-reporting</tt>: control delivery of error state events (default: disabled) | |||