1 Examples of using different system calls for sending/receiving CAN frames under Linux
2 =====================================================================================
4 There are two types of programs: candump-* and cansend-*. Candump
5 receives the messages from a CAN interface and prints their content to
6 stdout. Cansend sends one or more CAN frames to the specified CAN
7 interface. Variants of each program differ in which Linux system calls
8 they use to accomplish their task.
10 The syntax of candump commands is:
12 candump-xxx <CAN interface>
18 The syntax of cansend commands is:
20 cansend-xxx <CAN interface> <CAN frame>...
24 cansend-write can0 123#4567 321#987654
26 The individual programs are described below/
28 - candump-read.c - The simplest possible candump implementation using
31 - candump-recvmmsg.c - Implementation based on recvmmsg() system call.
32 Here, one system call can receive "multiple messages". Therefore, in
33 case of highbandwidth CAN traffic and slow CPU, this can
34 significantly improve system throughput.
36 - candump-mmap.c - Implementation based on PF_PACKET protocol family
37 and memory mapped ring buffers. The performance is slightly better
38 than of recvmmsg. If needed, reception can be happen completely
39 without any system call, because the kernel automatically stores
40 received CAN frames in memory mapped to the user space.
42 Bug: When this is used with a virtual CAN interface (vcan), each
43 message is received two times.
45 - cansend-write.c - The simplest way to send CAN frames.
47 - cansend-sendmmsg.c - Sends multiple CAN frames with one system call
48 and thus reducing the overhead. Note that the sendmmsg() system call
49 is only available in Linux 3.0 and later.
51 - cansend-mmap.c - Implementation based on PF_PACKET protocol family
52 and memory mapped ring buffers. In terms of performance it is
53 similar to sendmmsg().
55 Bug: This method does not work with virtual CAN (vcan) interfaces.
57 More information about these system calls and their performance in the
58 context of CAN bus can be found in
59 https://rtime.felk.cvut.cz/can/can-syscalls.pdf.