Can4linux

from Wikipedia, the free encyclopedia

can4linux is an open-source - CAN device drivers for the Linux kernel . Development began in the mid-1990s for the Philips 82C200 CAN controller module on an ISA AT-CAN-MINI board. The first version was created around 1995 as part of the Linux Lab project at the Free University of Berlin to use the CAN bus in the laboratory automation under Linux.

Due to the increasing spread of CAN in automation technology, especially in the embedded area, in which Linux has been increasingly used since the turn of the millennium, device drivers are used as the basis for higher CAN-based protocols such as CANopen , J1939 and DeviceNet . increased importance.

In addition to the NXP SJA1000 as the successor to the CAN controller Philips 82C200 and the Intel 82527, more and more adaptations for so-called integrated CAN controllers in powerful microcontrollers , for which Linux ports exist, were created from 2005 onwards . The Freescale ColdFire processors or ARM derivatives from ATMEL and Freescale as well as the Stand-Alone CAN Controller MCP2515, connected via the SPI bus, serve as examples .

A list can be found on the can4linux project page.

The latest version supports a virtual CAN operating mode in which applications without special CAN hardware can only exchange messages via the CAN driver. In this operating mode, the frame format for CAN FD is already implemented, which allows data lengths of up to 64 bytes.

use

The application software opens a CAN device descriptor and receives a file descriptor. This is used to exchange the CAN frames via the standard operating system functions read()and write()with other participants on the CAN bus.

The following code is an example that sends a frame and then waits for a frame from another bus participant. Further examples can be found on the project page.

/* simple CAN application example
 *
 * used for the Wikipedia article on can4linux
 */
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#include <can4linux.h>

int main(int argc,char **argv)
{
    int fd;
    canmsg_t frame;

    fd = open("/dev/can0", O_RDWR);

    frame.id      = 100;
    frame.length  = 2;
    frame.data[0] = 5;
    frame.data[1] = 0;
    write(fd, &frame, 1); /* ! count enthält Anzahl Frames, nicht Byte */

    read(fd, &frame, 1); /* ! count enthält Anzahl Frames, nicht Byte */
    printf("received CAN Frame Id %ld, DLC=%d\n", frame.id, frame.length);
    return 0;
}

can4linux can be translated so that different processes can read and write to the same CAN controller. In this way, for. B. In addition to the actual application, an independent diagnostic process can monitor the bus.

See also

Web links

Individual evidence

  1. ATMEL SAM9263
  2. Freescale i.MX35 family
  3. Stand Alone CAN MCP2515
  4. can4linux project page
  5. CAN FD specification (PDF; 624 kB)
  6. Online can4linux-examples