1 PCAN Driver Linux UserMan Eng
1 PCAN Driver Linux UserMan Eng
User Manual
Relevant products
Product Name Version Part number
PCAN Driver for Linux 8.x.x not applicable
All product names mentioned in this document may be the trademarks or registered trademarks of their respective companies.
They are not explicitly marked by “™” or “®”.
www.peak-system.com
info@peak-system.com
2
PCAN Driver for Linux v8 – User Manual
Contents
1 Disclaimer 4
2 Introduction 5
2.1 Features 5
2.2 System Requirements 6
2.3 Scope of Supply 6
3 Installation 7
3.1 Build Binaries 7
3.2 Install Package 9
3.3 Configure Software 9
3.4 Configure Non-PnP-Hardware 10
5 Developer Guide 35
5.1 chardev Mode 35
5.1.1 CAN 2.0 API 36
5.1.2 CAN FD API 40
5.2 netdev Mode 48
3
PCAN Driver for Linux v8 – User Manual
1 Disclaimer
The provided files are part of the PCAN Driver for Linux package.
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 3 of the License, or (at your option)
any later version.
The software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the software package. If
not, see http://www.gnu.org/licenses/.
Important note: It is strictly prohibited to use the intellectual property from the provided source code
for developing or producing a compatible hardware. All rights are reserved by PEAK-System Technik
GmbH.
4
PCAN Driver for Linux v8 – User Manual
2 Introduction
With the PCAN Driver for Linux, you can use CAN 2.0 and, since v8, CAN FD hardware products from
PEAK-System under Linux-based systems. Even if the use of Linux 2.4 kernels is declining, the canonical
age of the driver ensures compatibility with some versions of this kernel line and with older PEAK-
System hardware products.
The driver is also compatible with the latest versions of well-known real-time (RT) extensions like
Xenomai 1 and RTAI 2 , by interfacing to the common “Real Time Driver Mode” model.
Historically, the PCAN Driver for Linux provides an application programming interface called chardev by
implementing the character mode device drivers system calls (open, read, write, close, poll, ioctl). Since
version 20070306_n, the driver also provides a netdev interface which, by integrating the Kernel
SocketCAN network sub-layer, provides applications with access to the PEAK-System CAN channels via
the socket interface of the Linux kernel. The choice of the selected interface is exclusively done when
building the driver; the driver cannot run offering both interfaces at the same time.
Note: Since the Linux kernel v3.6, PEAK-System has worked to include the support of their most-
used PC CAN interfaces in the mainline Kernel. Thus, if you plan to get access to the CAN bus with a
PC CAN interface made by PEAK-System from a socket-based application, there is no need of
installing this PCAN Driver for Linux package anymore. The so-called netdev interface is however
kept for backward compatibility.
Version 8 of the PCAN Driver for Linux is a major evolution since it mainly includes the support of the
new CAN FD specification. Because of the new features CAN FD proposes, the historical chardev API has
had to evolve, too. Time has come for PCAN to propose a more modern and scalable new chardev
interface, while the “old” good one is obviously always supported.
The package is always evolving, because of the constant support of some new hardware products made
by PEAK-System, some new versions of tools and Kernels, or because of some bug fixing. The latest
version can be downloaded from the PEAK-System website:
http://www.peak-system.com/fileadmin/media/linux/index.htm
2.1 Features
Support of all CAN 2.0 a/b and CAN FD hardware products made by PEAK-System
Support of all 2.6.x, 3.x, and 4.x Linux Kernels in 32 and 64-bit environments
DESTDIR and cross-compilation supported
Udev system support
Enhanced sysfs integration
Optimized character mode device driver interface (chardev) supporting CAN 2.0 as well as CAN
FD standard and multiple messages transfers between applications and the driver
SocketCAN device driver interface (netdev) supporting CAN 2.0 as well as CAN FD new features,
with enhanced NETLINK integration (ip link support)
1
Website Xenomai: http://xenomai.org/
2
Website RTAI: https://www.rtai.org/
5
PCAN Driver for Linux v8 – User Manual
Real-time Linux extensions like Xenomai 2.6 and RTAI supported by the driver, as well as by the
user space library and the test and examples applications (chardev interface only)
Full binary compatibility with existing CAN 2.0 chardev applications that run over older versions
of the driver (7.x and older)
Note: The g++ compiler as well as the libpopt-dev package are only required for building some user
space applications from the test directory.
6
PCAN Driver for Linux v8 – User Manual
3 Installation
The PCAN Driver for Linux is an out-of-tree driver module, and because of the GPL, it is provided in a
(compressed) tarball package including the source files of the driver as well as the user libraries and
some test utilities and tools (see 2.3 Scope of Supply on page 6).
This chapter covers the setup of the whole driver package under non-RT and RT Linux systems (root
privileges are required for the installation part). Also cross-compilation options are explained.
$ make clean
$ make
Note: This behavior is new from v8.x of the driver! In former versions, the global make command did
build enabling the netdev interface rather than the chardev one. The main reason of that change is
that a great number of PEAK-System CAN hardware products are now natively supported by the
mainline kernel as SocketCAN interfaces 3. Thus, driver users are supposed to prefer using the
chardev interface instead. But of course, the netdev interface can always be selected by rebuilding
the driver (only) with:
$ make RT=XENOMAI
$ make RT=RTAI
3
Kernel code: http://lxr.free-electrons.com/source/drivers/net/can/usb/peak_usb/pcan_usb_core.c?v=3.4
7
PCAN Driver for Linux v8 – User Manual
Note: Selecting one of the above real-time compilations also removes the support of some of the
non-RT PC CAN interfaces (like the USB adapters, for example).
To cross-compile binaries:
$ make KERNEL_LOCATION=/where/are/the/kernel/headers
Making something from the package’s root directory recursively makes this thing into:
$ make –C driver
$ make –C lib
$ make –C test
The default configuration of the PCAN Driver for Linux in non-RT configuration is to handle the support of
all PC CAN interfaces. However, in order to save memory or to fix some cross-compilation and/or loading
issues, it is possible to remove the support of some of these interfaces. The driver's Makefile handles the
following set of switches from the make command line:
For example, to build the driver without including the support of neither the PCAN-Dongle nor the
PCAN-PC Card CAN interfaces:
8
PCAN Driver for Linux v8 – User Manual
$ cd peak-linux-driver-X.Y.Z
$ su -c "make install"
The above setup will build and install the driver, the user libraries, and the test programs on the running
system.
9
PCAN Driver for Linux v8 – User Manual
Note: The bitrate= parameter has changed since v8.x of the driver. In previous versions, this para-
meter allowed to change the default nominal bitrate, but with following the coding format of the
BTR0BTR1 SJA1000 register only.
In order to ensure the best backward compatibility with the existing configurations, the bitrate=
parameter is now parsed as follows:
If the two first characters of the given value is 0x or 0X and if the hexadecimal value is smaller
than 65536, then the value is always interpreted as a BTR0BTR1 bitrate specification (as the driver
did in previous versions).
Otherwise, and if the value is obviously a numeric value, then it is used as a bit-per-second (bit/s)
bitrate specification.
These parameters and their values can be given on the insmod command line or can be written in the
/etc/modprobe.d/pcan.conf file. The system administrator has to edit this file, then to uncomment
the options pcan line, and to write his own settings.
Note: This paragraph only concerns the users of some non-plug-and-play PC CAN interfaces (like the
PCAN-ISA and PC/104 PC CAN interfaces family). The configuration of the driver for the PCI/PCIe and
USB PC CAN interfaces families is entirely handled by the system.
When using some non-plug-and-play PC CAN interfaces, the driver has to be informed of the IRQs and
I/O ports configured for these boards (see the provided hardware reference and the corresponding jum-
pers' usage). The installation procedure of the PCAN Driver for Linux has already created a configuretion
text file which enables to define some optional arguments that are passed to the driver (see 3.3 Configure
Software on page 9), when it is loaded.
For example, if the Linux host is equipped with a two channels ISA PC CAN interface board, and if IRQ 5
(resp. IRQ 10) and I/O port 0x300 (resp. 0x320) is the configuration selected by the dedicated jumpers on
the board, then the /etc/modprobe.d/pcan.conf file has to be changed like this:
$ sudo vi /etc/modprobe.d/pcan.conf
# PCAN - automatic made entry, begin --------
# if required add options and remove comment
options pcan type=isa,isa irq=10,5 io=0x300,0x320
install pcan /sbin/modprobe --ignore-install pcan
# PCAN - automatic made entry, end ----------
The standard assignments for ISA and PC/104 PC CAN interfaces are (io/irq): 0x300/10, 0x320/5. The
standard assignments for the PCAN-Dongle in SP/EPP mode are (io/irq): 0x378/7, 0x278/5.
10
PCAN Driver for Linux v8 – User Manual
Once installed, and if the Udev system is running on the target system, the driver is automatically loaded
by the system at the next boot for internal PC CAN interfaces, like the PCI/PCIe boards, or when the
external PC CAN interface (like the USB adapters) is plugged into the system.
Note: The modprobe system command manages to load all the other modules the driver depends
on. When using insmod instead, you must load all of these modules manually:
The driver is reasonably verbose for the kernel: it logs one or several messages in the kernel logs buffer
for each PC CAN interface it enumerates. Next, it will save messages only when something wrong has
been detected.
11
PCAN Driver for Linux v8 – User Manual
Here are the messages it logs when it just has been loaded, for example:
The driver enumerates each PC CAN interface according to its type. By default, each type has the
following range of device minor numbers:
Note: No device nodes files are created when running the real-time version of the driver module
because it creates real-time (only) devices which are not connected in any way to the Udev system.
The installation of the driver package also adds some default rules to Udev, for helping the system to
create the device nodes that implement the CAN channels handled by the driver (see peak-linux-
12
PCAN Driver for Linux v8 – User Manual
For example:
The Udev rules that the driver installs enable to create some symbolic links that give much more
information about the CAN channel:
2. Udev rules group CAN channels according to their PC CAN interface into the same subdirectory
whose name is made of the PC CAN interface product name
3. Udev default rules also create some other symbolic links if the CAN channel exports a devid
property (different from -1) under /sys (as USB devices are able to).
13
PCAN Driver for Linux v8 – User Manual
The example below demonstrates the complete list of /dev/pcan* nodes, symbolic links, and
subdirectories the Udev rules provided with the driver might create.
$ ls -l /dev/pcan*
lrwxrwxrwx 1 root root 10 févr. 3 14:59 /dev/pcan0 -> pcanpcifd0
lrwxrwxrwx 1 root root 10 févr. 3 14:59 /dev/pcan1 -> pcanpcifd1
lrwxrwxrwx 1 root root 10 févr. 3 14:59 /dev/pcan2 -> pcanpcifd2
lrwxrwxrwx 1 root root 10 févr. 3 14:59 /dev/pcan3 -> pcanpcifd3
lrwxrwxrwx 1 root root 11 févr. 3 14:59 /dev/pcan32 -> pcanusbfd32
lrwxrwxrwx 1 root root 11 févr. 3 14:59 /dev/pcan33 -> pcanusbfd33
lrwxrwxrwx 1 root root 11 févr. 3 14:59 /dev/pcan34 -> pcanusbfd34
lrwxrwxrwx 1 root root 9 févr. 3 15:24 /dev/pcan35 -> pcanusb35
lrwxrwxrwx 1 root root 9 févr. 3 15:24 /dev/pcan36 -> pcanusb36
lrwxrwxrwx 1 root root 8 févr. 3 14:59 /dev/pcan4 -> pcanpci4
lrwxrwxrwx 1 root root 8 févr. 3 14:59 /dev/pcan5 -> pcanpci5
lrwxrwxrwx 1 root root 8 févr. 3 14:59 /dev/pcan8 -> pcanisa8
lrwxrwxrwx 1 root root 8 févr. 3 14:59 /dev/pcan9 -> pcanisa9
crw-rw-rw- 1 root root 246, 8 févr. 3 14:59 /dev/pcanisa8
crw-rw-rw- 1 root root 246, 9 févr. 3 14:59 /dev/pcanisa9
crw-rw-rw- 1 root root 246, 4 févr. 3 14:59 /dev/pcanpci4
crw-rw-rw- 1 root root 246, 5 févr. 3 14:59 /dev/pcanpci5
crw-rw-rw- 1 root root 246, 0 févr. 3 14:59 /dev/pcanpcifd0
crw-rw-rw- 1 root root 246, 1 févr. 3 14:59 /dev/pcanpcifd1
crw-rw-rw- 1 root root 246, 2 févr. 3 14:59 /dev/pcanpcifd2
crw-rw-rw- 1 root root 246, 3 févr. 3 14:59 /dev/pcanpcifd3
crw-rw-rw- 1 root root 246, 35 févr. 3 15:24 /dev/pcanusb35
crw-rw-rw- 1 root root 246, 36 févr. 3 15:24 /dev/pcanusb36
crw-rw-rw- 1 root root 246, 32 févr. 3 14:59 /dev/pcanusbfd32
crw-rw-rw- 1 root root 246, 33 févr. 3 14:59 /dev/pcanusbfd33
crw-rw-rw- 1 root root 246, 34 févr. 3 14:59 /dev/pcanusbfd34
lrwxrwxrwx 1 root root 11 févr. 3 14:59 /dev/pcanusbpfd32 -> pcanusbfd32
lrwxrwxrwx 1 root root 11 févr. 3 14:59 /dev/pcanusbpfd33 -> pcanusbfd33
/dev/pcan-pci:
total 0
drwxr-xr-x 2 root root 80 févr. 3 14:59 0
/dev/pcan-pcie_fd:
total 0
drwxr-xr-x 2 root root 80 févr. 3 14:59 0
drwxr-xr-x 2 root root 80 févr. 3 14:59 1
/dev/pcan-usb:
total 0
drwxr-xr-x 2 root root 60 févr. 3 15:24 0
drwxr-xr-x 2 root root 60 févr. 3 15:24 1
lrwxrwxrwx 1 root root 12 févr. 3 15:24 devid=161 -> ../pcanusb35
/dev/pcan-usb_fd:
total 0
drwxr-xr-x 2 root root 60 févr. 3 14:59 0
lrwxrwxrwx 1 root root 14 févr. 3 14:59 devid=12345678 -> ../pcanusbfd34
/dev/pcan-usb_pro_fd:
total 0
drwxr-xr-x 2 root root 80 févr. 3 14:59 0
lrwxrwxrwx 1 root root 14 févr. 3 14:59 devid=2 -> ../pcanusbfd32
lrwxrwxrwx 1 root root 14 févr. 3 14:59 devid=31 -> ../pcanusbfd33
14
PCAN Driver for Linux v8 – User Manual
Here is the content of the subdirectories created by these Udev rules, one per PC CAN interface. The tree
representation provides a better way of showing which CAN channel is connected to which PC CAN
interface:
$ tree /dev/pcan-pci
/dev/pcan-pci
└── 0
├── can0 -> ../../pcanpci4
└── can1 -> ../../pcanpci5
1 directory, 2 files
$ tree /dev/pcan-pcie_fd
/dev/pcan-pcie_fd
├── 0
│ ├── can0 -> ../../pcanpcifd0
│ └── can1 -> ../../pcanpcifd1
└── 1
├── can0 -> ../../pcanpcifd2
└── can1 -> ../../pcanpcifd3
2 directories, 4 files
$ tree /dev/pcan-usb
/dev/pcan-usb
├── 0
│ └── can0 -> ../../pcanusb35
├── 1
│ └── can0 -> ../../pcanusb36
└── devid=161 -> ../pcanusb35
2 directories, 3 files
$ tree /dev/pcan-usb_fd
/dev/pcan-usb_fd
├── 0
│ └── can0 -> ../../pcanusbfd34
└── devid=12345678 -> ../pcanusbfd34
1 directory, 2 files
$ tree /dev/pcan-usb_pro_fd
/dev/pcan-usb_pro_fd
├── 0
│ ├── can0 -> ../../pcanusbfd32
│ └── can1 -> ../../pcanusbfd33
├── devid=2 -> ../pcanusbfd32
└── devid=31 -> ../pcanusbfd33
1 directory, 4 files
15
PCAN Driver for Linux v8 – User Manual
In the above configuration, a user application that wants to access to the CAN bus through the 2nd CAN
port of the PCAN-USB Pro FD plugged to the host will be able to open indifferently:
/dev/pcanusbfd33
/dev/pcan33
/dev/pcan-usb_pro_fd/devid=31
/dev/pcan-usb_pro_fd/0/can1
Note: With a properly configured and running Udev system, all of these devices files and directories
are generated on the fly. If the target non-RT system does not have a running Udev system, you
must create the device files manually each time after driver installation. The driver package provides
the shell script driver/pcan_make_devices for this. For example, to create a maximum of 2
devices of each type:
$ cd driver
$ sudo ./pcan_make_devices 2
Example:
$ cat /proc/pcan
16
PCAN Driver for Linux v8 – User Manual
The columns of the PC CAN interfaces table are properties that are common to each interface:
For historical reasons, v8.x of the driver always handles the /proc/pcan file, but it should be considered
as deprecated and for CAN 2.0 usage only. Since v8.x, the driver also exports all of the /proc/pcan
properties (and some more) to the /sysfs interface.
$ cat /sys/class/pcan/version
8.0.0
b) The /sys/class/pcan directory exports the list of all the CAN interfaces it handles:
17
PCAN Driver for Linux v8 – User Manual
$ tree -a /sys/class/pcan
/sys/class/pcan
├── pcanisa8 -> ../../devices/virtual/pcan/pcanisa8
├── pcanisa9 -> ../../devices/virtual/pcan/pcanisa9
├── pcanpci4 -> ../../devices/virtual/pcan/pcanpci4
├── pcanpci5 -> ../../devices/virtual/pcan/pcanpci5
├── pcanpcifd0 -> ../../devices/virtual/pcan/pcanpcifd0
├── pcanpcifd1 -> ../../devices/virtual/pcan/pcanpcifd1
├── pcanpcifd2 -> ../../devices/virtual/pcan/pcanpcifd2
├── pcanpcifd3 -> ../../devices/virtual/pcan/pcanpcifd3
├── pcanusb35 -> ../../devices/virtual/pcan/pcanusb35
├── pcanusb36 -> ../../devices/virtual/pcan/pcanusb36
├── pcanusbfd32 -> ../../devices/virtual/pcan/pcanusbfd32
├── pcanusbfd33 -> ../../devices/virtual/pcan/pcanusbfd33
├── pcanusbfd34 -> ../../devices/virtual/pcan/pcanusbfd34
└── version
These entries have been extended to export some PCAN devices private properties, as shown (bold) in
the example below (bold-green lines properties are the same as the columns of /proc/pcan):
$ ls -l /sys/class/pcan/pcanpci4/
total 0
-r--r--r-- 1 root root 4096 nov. 6 12:34 adapter_name
-r--r--r-- 1 root root 4096 nov. 6 12:34 adapter_number
-r--r--r-- 1 root root 4096 nov. 6 12:34 adapter_version
-r--r--r-- 1 root root 4096 nov. 6 12:34 base
-r--r--r-- 1 root root 4096 nov. 6 12:34 btr0btr1
-r--r--r-- 1 root root 4096 nov. 6 12:34 bus_state
-r--r--r-- 1 root root 4096 nov. 6 12:34 clock
-r--r--r-- 1 root root 4096 nov. 6 12:34 ctrlr_number
-r--r--r-- 1 root root 4096 nov. 6 12:34 dev
-r--r--r-- 1 root root 4096 nov. 6 12:34 devid
-r--r--r-- 1 root root 4096 nov. 6 12:34 errors
-r--r--r-- 1 root root 4096 nov. 6 12:34 hwtype
-r--r--r-- 1 root root 4096 nov. 6 12:34 irq
-r--r--r-- 1 root root 4096 nov. 6 12:34 irqs
-r--r--r-- 1 root root 4096 nov. 6 12:34 minor
-r--r--r-- 1 root root 4096 nov. 6 12:34 nom_bitrate
-r--r--r-- 1 root root 4096 nov. 6 12:34 nom_brp
-r--r--r-- 1 root root 4096 nov. 6 12:34 nom_sjw
-r--r--r-- 1 root root 4096 nov. 6 12:34 nom_tseg1
-r--r--r-- 1 root root 4096 nov. 6 12:34 nom_tseg2
drwxr-xr-x 2 root root 0 nov. 6 12:34 power
-r--r--r-- 1 root root 4096 nov. 6 12:34 read
-r--r--r-- 1 root root 4096 nov. 6 12:34 rx_fifo_ratio
-r--r--r-- 1 root root 4096 nov. 6 12:34 status
lrwxrwxrwx 1 root root 0 nov. 6 12:34 subsystem -> ../../../../class/pcan
-r--r--r-- 1 root root 4096 nov. 6 12:34 tx_fifo_ratio
-r--r--r-- 1 root root 4096 nov. 6 12:34 type
-rw-r--r-- 1 root root 4096 nov. 6 12:33 uevent
-r--r--r-- 1 root root 4096 nov. 6 12:34 write
18
PCAN Driver for Linux v8 – User Manual
Reading the content of all of the above files will display something like that:
Note: Depending on the CAN hardware, the device node might export some more properties. For
example, a CAN FD PCIe device will export the following properties (new properties are bold):
19
PCAN Driver for Linux v8 – User Manual
minor = 0
nom_bitrate = 500000
nom_brp = 1
nom_sjw = 1
nom_tseg1 = 13
nom_tseg2 = 2
read = 0
rx_error_counter = 0
rx_fifo_ratio = 0.00
status = 0x0000
tx_error_counter = 0
tx_fifo_ratio = 0.00
type = pcifd
uevent = MAJOR=249
MINOR=1
DEVNAME=pcanpcifd1
write = 0
The lspcan tool is a shell script based on the /sysfs interface that can be used to get an overview of the
PC CAN interfaces and CAN channels of the host.
$ ./lspcan --help
lspcan: list PEAK-System CAN/CANFD devices found by driver
Option:
-a | --all equivalent to: -i -s
-f | --forever forever loop on devices (^C to stop)
-h | --help display this help
-i | --info information about PCAN devices
-s | --stats statistics about PCAN devices
-t | --title display a title line over columns
-T | --tree tree version
--version display driver version
20
PCAN Driver for Linux v8 – User Manual
$ ./lspcan -T -t -i
dev name port irq clock btrs bus
[PCAN-ISA 0]
|_ pcanisa8 CAN1 10 8MHz 500k CLOSED
|_ pcanisa9 CAN2 5 8MHz 500k CLOSED
[PCAN-PCI 0]
|_ pcanpci4 CAN1 19 8MHz 500k CLOSED
|_ pcanpci5 CAN2 19 8MHz 500k CLOSED
[PCAN-PCIe FD 0]
|_ pcanpcifd0 CAN1 32 80MHz 500k+2M CLOSED
|_ pcanpcifd1 CAN2 32 80MHz 500k+2M CLOSED
[PCAN-PCIe FD 1]
|_ pcanpcifd2 CAN1 33 80MHz 500k+2M CLOSED
|_ pcanpcifd3 CAN2 33 80MHz 500k+2M CLOSED
[PCAN-USB 0]
|_ pcanusb32 CAN1 - 8MHz 500k CLOSED
[PCAN-USB 1]
|_ pcanusb33 CAN1 - 8MHz 500k CLOSED
[PCAN-USB Pro FD 0]
|_ pcanusbfd34 CAN1 - 80MHz 500k+2M CLOSED
|_ pcanusbfd35 CAN2 - 80MHz 500k+2M CLOSED
On the other hand, running lspcan with –T –t –s –f refreshes the screen every second with a detailed
view of statistics collected from all the PC CAN interfaces present on the Linux host:
Note: The content of the above screen copy may change, depending on the version of the driver.
21
PCAN Driver for Linux v8 – User Manual
This (very) simple interface makes it possible to quickly check if the driver correctly works. This interface
uses a syntax made of:
1. a letter that indicates the command
Example:
$ echo "i nom_bitrate=1M" > /dev/pcanusb0
22
PCAN Driver for Linux v8 – User Manual
Example:
$ echo "m s 0x123 3 01 02 03" > /dev/pcanusb0
The above command writes CAN message ID 0x123 with 3 the data bytes
“01 02 03” on the CAN bus connected to the 1st CAN port of the USB CAN
interface.
e id len [xx [xx …]] Write CAN extended message id (numeric value <= 0x3fffffff) with len
data bytes valued by xx [xx ].
Example:
$ echo "m e 0x123 3 01 02 03" > /dev/pcanusb0
The above command writes CAN message ID 0x00000123 with 3 the data
bytes “01 02 03” on the CAN bus connected to the 1st CAN port of the USB
CAN interface.
r s id Write the CAN RTR (Remote Transmission Request) of standard id
(numeric value <= 0x7ff).
e id Write the CAN RTR (Remote Transmission Request) of extended id
(numeric value <= 0x7ff).
M Same as m but asking the driver to activate the self-receive feature (if the CAN controller of the given channel has
the ability to copy an outgoing CAN frame to its own rx queue).
R Same as r but asking the driver to activate the self-receive feature (if the CAN controller of the given channel has
the ability to copy an outgoing CAN frame to its own rx queue).
b Same as m but asking the driver to activate the BRS feature (if the given channel is equipped with a CAN FD
controller).
B Same as b but asking the driver to activate the self-receive feature (if the CAN FD controller of the given channel
has the ability to copy an outgoing CAN FD frame to its own rx queue).
If reading from this interface, the user is able to receive any of the above messages, plus status (x)
messages:
23
PCAN Driver for Linux v8 – User Manual
The test directory applications should be built after the libraries under lib directory have been built and
installed. Like the driver, these libraries and applications accept non-RT and RT compilation.
The global package installation described in 3.1 Build Binaries on page 7 has built and installed those
binaries in the system. To (re-)build them (without using any RT system calls):
$ cd peak-linux-driver-x.y.z
$ make –C test
A user who wants to rebuild the RT version of these binaries will have to:
$ cd peak-linux-driver-x.y.z
$ make –C test RT=XENOMAI
$ cd peak-linux-driver-x.y.z
$ make –C test RT=RTAI
Note: Users (as well as developers) of CAN-FD-specific applications can directly have a look at the
new pcanfdtst application described in 4.7.5 on page 28.
4.7.1 receivetest
This application writes all frames it receives from a given CAN 2.0 channel (only!) to stdout. This
application also demonstrates the usage of the old lipcan CAN 2.0 API.
Usage:
24
PCAN Driver for Linux v8 – User Manual
$ receivetest --help
receivetest - a small test program which receives and prints CAN messages.
usage: receivetest [-b=BTR0BTR1] [-e] [-?]
{[-f=devicenode] | {[-t=type] [-p=port [-i=irq]]}}
options:
-f=devicenode path to PCAN device node (default=/dev/pcan0)
-t=type type of interface (pci, sp, epp, isa, pccard, usb (default=pci)
-p=port port number if applicable (default=1st port of type)
-i=irq irq number if applicable (default=irq of 1st port)
-b=BTR0BTR1 bitrate code in hex (default=see /proc/pcan)
-e accept extended frames (default=standard frames only)
-d=no donot display received messages (default=yes)
-n=mloop number of loops to run before exit (default=infinite)
-? or --help displays this help
Example:
Display up to 100 (extended and standard) messages received from the 1st CAN port of a USB interface
connected to a CAN bus at 1 Mbit/s:
Note: The bitrate set by this program to this CAN interface is exported by the driver:
4.7.2 transmitest
This application writes all the frames it finds in a given text file to a given CAN 2.0 channel (only!). This
application also demonstrates the use of the old lipcan CAN 2.0 API.
25
PCAN Driver for Linux v8 – User Manual
Usage:
$ transmitest --help
The file transmit.txt is given as an example in the test directory. The syntax of this file is quite
simple and follows the syntax of the write interface of the driver. The test loops the transmission of the
frames found in the input text file. The number of loops is infinite unless the -n option is specified on
command line.
Example:
Transmit 100 times all the CAN 2.0 frames described in transmit.txt to the 1st CAN port of a USB
interface connected to a CAN bus at 1 Mbit/s:
Note: The bitrate set by this program to this CAN interface is exported by the driver:
4.7.3 pcan-settings
This application enables to read/write some specific values from/to the non-volatile memory of some PC
CAN interfaces. This feature is useful to the user who wants his hot-pluggable CAN interfaces to always
have the same device node name, whatever socket it is plugged on (operating systems devices
26
PCAN Driver for Linux v8 – User Manual
enumeration rules don't give the same number to the same device, if this device is not plugged to the
same socket/bus/port…).
Usage:
$ pcan-settings --help
Usage: pcan-settings [OPTION...]
-f, --deviceNode='device file path' set path to PCAN device
(default: "/dev/pcan32")
-s, --SerialNo get serial No
-d, --DeviceNo[='non-volatile device number'] get or set device No
-v, --verbose make it verbose
Help options:
-?, --help Show this help message
--usage Display brief usage message
Example:
$ pcan-settings -f=/dev/pcanusb32 –s
0x00000003
• Set device numbers 30 and 31 for CAN1 and CAN2 of a USB 2xCAN channels interface:
$ pcan-settings -f=/dev/pcanusb32 –d 30
$ pcan-settings -f=/dev/pcanusb33 –d 31
• Read the device numbers of CAN1 and CAN2 of a USB 2xCAN channels interface:
$ pcan-settings -f=/dev/pcanusb32 –d
30
$ pcan-settings -f=/dev/pcanusb33 –d
31
When the driver is reloaded, it reads these numbers and exports them to /sys:
$ cat /sys/class/pcan/pcanusb32/devid
30
$ cat /sys/class/pcan/pcanusb33/devid
31
Thus, Udev is notified and reads the driver’s rules. These default rules say that, if devid is not -1, then it
should be used to create a symbolic link to the true device node under a directory which name is the
adapter name. In this example, if the USB CAN interface is a PCAN-USB Pro, then two symbolic links are
created under /dev/pcan-usb_pro:
27
PCAN Driver for Linux v8 – User Manual
$ ls -l /dev/pcan-usb_pro
total 0
drwxr-xr-x 2 root root 11 nov. 8 11:00 0
lrwxrwxrwx 1 root root 11 nov. 8 11:00 devid=30 -> ../pcanusb32
lrwxrwxrwx 1 root root 11 nov. 8 11:00 devid=31 -> ../pcanusb33
4.7.4 bitratetest
Note: This application is kept for historical reasons only but, since bitrate values and clock selection
are now proposed by the new API to the user space, it is considered as deprecated.
This application displays the BTR0BTR1 values for some well-known bitrate values. The BTR0BTR1
16-bits codification is 8 MHz SJA1000-controller-specific.
Usage:
$ bitratetest --help
4.7.5 pcanfdtst
This application enables to test the driver, since it is able to receive/transmit CAN 2.0/CAN FD messages
from/to all of the device nodes handled by the driver. It works in two modes:
when running in RX mode, the application only writes everything received from all the opened
CAN FD device nodes on the screen
when running in TX mode, the application transmits CAN FD frames on all the opened devices
and also displays any event received from them
Moreover, this application demonstrates the usage of the new CAN FD API of the driver. Among all the
novelties, the application allows to:
specify nominal and data bitrates for CAN FD usage
select the device clock
select ISO and non-ISO CAN FD modes
demonstrate the usage of the new entry points of the new API that enable multi-messages
transmit/receive
demonstrate the new event-based API
28
PCAN Driver for Linux v8 – User Manual
Usage:
$ pcanfdtst --help
Setup CAN[FD] tests between CAN channels over the PCAN Driver (>= v8.x)
WARNING
This application comes with ABSOLUTELY NO WARRANTY. This is free
software and you are welcome to redistribute it under certain
conditions. For details, see attached COPYING file.
USAGE
$ pcanfdtst MODE [OPTIONS] CAN [CAN...]
MODE
tx generate CAN traffic on the specified CAN interfaces
rx check CAN traffic received on the specified CAN interfaces
CAN
/dev/pcanx indicate which CAN interface is used in the test.
Several CAN interfaces can be specified. In that case,
each one is opened in non-blocking mode.
OPTIONS
-a | --accept f-t add message filter [f...t]
-b | --bitrate v set [nominal] bitrate to "v" bps
--btr0btr1 bitrates with BTR0BTR1 format
-B | --brs data bitrate used for transmitting CANFD msgs
-c | --clock v select clock frequency "v" Hz
-D | --debug (maybe too) lot of display
-d | --dbitrate v set data bitrate to "v" bps
-f | --fd select CAN FD ISO mode
-F | --fd-non-iso select CAN FD non-ISO mode
-h | --help display this help
-i | --id v|r set fixed CAN ID "v" or randomly
-is v|r set fixed standard CAN ID "v" or randomly
-ie v|r set fixed extented CAN ID "v" or randomly
-I | --incr v "v"=nb of data bytes to use for increment counter
-l | --len v set fixed CAN dlc "v" for tests
-m | --mul v tx/rx "v" msgs at once
-n v do "v" test loops and stop
-o | --listen-only set PCAN device in listen-only mode
-p | --pause-us v set "v" us. pause between tests
-q | --quiet nothing is displayed
-r | --rtr set the RTR flag to msgs sent
--no-rtr clear the RTR flag from msgs sent
-s | --stdmsg-only don't handle extended msgs
-t | --timeout-ms v wait "v" ms. for events
-u | --bus-load get bus load notifications from the driver
-v | --verbose things are (very much) explained
-w | --with-ts logs are prefixed with time of day (s.us)
Bitrates and clock values can be expressed with ending k or M as shortcuts for factor 1,000 or
factor 1,000,000. Note that if the option --btr0btr1 is used, then bitrate and dbitrate
options value is read as a BTR0BTR1 format coded value.
The unit of the pause delay between each write or read system call is the microsecond. Here,
using an m appended to a value (e.g. 5m) changes to milliseconds and an appended s to full
seconds (e.g. 7s).
29
PCAN Driver for Linux v8 – User Manual
The unit of the timeout-ms parameter is millisecond. Appending an s to the value switches to
seconds (e.g. 7s).
If only one PC CAN interface is given on the command line, the application runs in “blocking”
mode, that is, the application task blocks into the driver while the receive queue of the driver is
empty, or while the transmission queue of the driver is full.
If more than one PC CAN interface is given on the command line, the application does the
following:
• It runs in non-blocking mode and uses the select() system call in non-RT environment,
to be able to wait for several events at once.
• It creates as many real-time tasks as given device nodes, to be able to wait for several
events at the same time.
The application’s default behavior is to read/write messages from/to the driver one by one. When
the --mul x option is used (with x > 1), then the application reads/writes x messages at once.
Examples:
1. Write 10 CAN 2.0 frames (with random ID and data length) each second on a bus with a bitrate of
250 kbit/s using the 2nd USB CAN interface:
2. Write CAN FD (non-ISO) frames with extended ID 0x123 and 24 data bytes at a nominal bitrate of
1 Mbit/s and data bitrate of 2 Mbit/s, using the 60 MHz clock of the 2nd USB interface and the
1st PCI interface of the host:
3. Read the same bus, but from the 1st USB interface:
30
PCAN Driver for Linux v8 – User Manual
4. Transmit frames, but use the new entry point of the multi-messages write API. Here, the
application transmits 3 copies of the same frame:
When reading on the same bus, you can see that the driver has written each frame 3 times:
31
PCAN Driver for Linux v8 – User Manual
Note: Since kernel version 3.6, the netdev interface with all of the PEAK-System PC CAN interfaces is
natively included in the mainline kernel. So, there is no need to install the PCAN driver for Linux
when planning to use the SocketCAN interface in applications.
In this mode, the driver registers a “CAN network interface” for each PC CAN interface it enumerates.
Each network interface is given a name made of the prefix can, followed by a number starting from 0.
assign=peak
When loading the driver with the parameter assign=peak, the CAN network CAN interface number is
fixed to the PCAN device minor number. In this mode, canX interface defines the same PC CAN interface
as /dev/pcanX.
assign=pcanX:canY[,pcanX:canY]
Loading the driver with the parameter assign=pcanX:canY[,pcanX=canY] defines the name canY to
the device which name is pcanX.
assign=pcanX:canY
Loading the driver with the parameter assign=pcanX:canY sets the name canY to the device which
name is pcanX. When selecting this mode, the assign parameter value can be a list of several
assignments, each separated by a “,” (comma).
assign=devid[,peak]
When loading the driver with the parameter assign=devid, then the name of the network CAN interface
is made by using the devid value of the corresponding PC CAN interface. If the PC CAN interface does
not define any devid, then the usual (ascending) order enumeration scheme is used (as if assign= was
not used) unless assign=devid,peak is used. In that case, the CAN network number will be the same as
the PCAN device number (as if assign=peak was used).
Note: The value of the devid property can be changed using test/pcan-settings utility (see 4.7.3
pcan-settings on page 26).
4
Background information: https://en.wikipedia.org/wiki/SocketCAN
32
PCAN Driver for Linux v8 – User Manual
4.8.2 ifconfig/iproute2
Both of these utilities configure a canX interface. While ifconfig is somewhere too old to support all of
the CAN/CAN-FD-specific features, the last versions of the iproute2 package (especially the ip tool)
include options to setup a canX interface. Since v8, the canX interfaces exported by the driver can be
configured using the ip link command.
The ip tool has been modified to handle protocol-specific features of CAN and CAN FD. This simplifies
the bitrate setup of a CAN interface. The help of the tool describes its usage:
[ loopback { on | off } ]
[ listen-only { on | off } ]
[ triple-sampling { on | off } ]
[ one-shot { on | off } ]
[ berr-reporting { on | off } ]
[ restart-ms TIME-MS ]
[ restart ]
Thus, setting the bitrate to a CAN interface is now possible using one of the following options:
bitrate bit-timing parameters set (aka sample-point, tq, prop-seg, phase-seg1, phase-seg2,
sjw)
bitrate option followed by numeric value (if the kernel configuration option
CONFIG_CAN_CALC_BITTIMING was set)
The restart-ms option defines a timer in milliseconds. After this period the CAN interface is
automatically restarted on BUS-OFF condition. If the given numeric value is 0, then the automatic restart
mechanism is disabled, thus user will have to manually do:
The last and complete version of how to use the ip link tool with CAN networks is available online at:
https://www.kernel.org/doc/Documentation/networking/can.txt
Examples:
33
PCAN Driver for Linux v8 – User Manual
Set up a PCAN netdev CAN FD interface with 1 Mbit/s te and 2 Mbit/s of data bitrate (if supported):
Set up a PCAN netdev CAN FD interface with 1 Mbit/s nominal bitrate and 2 Mbit/s data bitrate,
running in non-ISO mode (if supported by the device and the kernel):
$ ip link set canX up type can bitrate 1000000 dbitrate 2000000 fd-non-iso on
You might use ifconfig for setting the interface UP or DOWN only:
4.8.3 can-utils
The can-utils package 5 contains some tools and utilities that allow transmitting and receiving CAN as
well as CAN FD messages over the PCAN netdev interfaces.
Note: Transmitting and receiving to/from the CAN bus through the SocketCAN network interfaces
needs these interfaces to be configured (see 4.8.2 ifconfig/iproute2 on page 33).
Examples:
Dump CAN/CAN FD messages received from the canX interface, display timestamps:
$ candump –t a canX
Transmit a CAN message with ID 0x123 on canX with 4 data bytes 00 11 22 33:
Transmit the same message with CAN FD (##) on canX, select the data bitrate for the data bytes
(BRS flags = 1):
5
Website can-utils: https://github.com/linux-can/can-utils/
34
PCAN Driver for Linux v8 – User Manual
5 Developer Guide
As explained in 3.1 Build Binaries on page 7, the PCAN Driver for Linux can be configured to run in two
exclusive modes:
1. If built for chardev mode, the driver exports a classic open/read/write/ioctl/close character device
interface to the user space applications, while
Note: The netdev mode is not available when building the driver for real-time environment.
Building and installing the driver as described in 3.1 Build Binaries on page 7 and in 3.2 Install Package
on page 9 also builds and installs some user API libraries that encapsulate the system calls to the driver:
• lipcan is the good and old API which is always offering access to CAN 2.0 channels (see 5.1.1
CAN 2.0 API on page 36)
• libpcanfd is the new API included in the package since version 8 of the driver. This new API
offers access to CAN 2.0 and CAN FD channels, as well as multi-messages services and status
events messaging. Since this library also includes all the entry points of libpcan described in
5.1.1 CAN 2.0 API on page 36, this library can also be linked with CAN 2.0 API applications instead
of using libpcan.
Both of these libraries can be built for being used by real-time applications. Two RT environments can be
selected when building these libraries:
Each device node can be opened, closed, read, and written (see 4.6 read/write Interface on page 22). The
main functions are implemented through the ioctl() entry point. The architecture of the several
software components of the driver package since v8 is summarized in Figure 1 below.
35
PCAN Driver for Linux v8 – User Manual
main() main()
{ {
h = CAN_Open(); fd = pcanfd_open();
CAN_Init(h); err = pcanfd_set_init(fd);
CAN_Write(h); err = pcanfd_send_msg(fd);
CAN_Read(h); err = pcanfd_recv_msg(fd);
} pcanfd_close(fd);
libpcan.h #include <PCAN.h> }
#include <libpcan.h> libpcanfd.h
DWORD CAN_Init(); int pcanfd_set_init()
DWORD CAN_Init();
pcanfd.h
#include <PCAN.h>
PCAN.h
#define PCAN_INIT
#define PCANFD_SET_INIT
libpcanfd.so
#include <libpcan.h> #include <libpcanfd.h>
libpcan.so
DWORD CAN_Init() int pcanfd_set_init()
{ {
ioctl(PCAN_INIT);
}
}
PCAN.ko
#include <pcanfd.h>
ioctl() {
case PCAN_INIT:
case PCANFD_SET_INIT:
Note: This API is kept for backward compatibility reasons, thus these entry points are also proposed
by the new libpcanfd library. But, this API is considered as deprecated. Use the new CAN FD API
instead.
The (old) CAN 2.0 API ioctl codes are defined by pcan.h:
36
PCAN Driver for Linux v8 – User Manual
This API enables to read and write CAN 2.0 messages (only) from/through any PC CAN interface of PEAK-
System. This API is encapsulated by the libpcan library (C/C++ programs like transmitest,
receivetest, bitratetest, and pcan-settings stored in the test directory use this API). Since this
API is always supported for CAN 2.0 access, to use this API, the application must link with -lpcan or
-lpcanfd.
The principle of this API is to implement a CAN 2.0 channel with something like an object HANDLE used
during the whole life of the connection to the CAN bus. This API is greatly inspired of the PCAN-Light
version for Windows©.
For example:
#include <libpcan.h>
/* open the 2nd CAN 2.0 PCI channel in the system (first is 0) */
HANDLE h = CAN_Open(HW_PCI, 1);
See the list of CAN_BAUD_xxx and CAN_INIT_TYPE_XX symbols defined in libpcan.h to get the list of
supported values for wBTR0BTR1 values and nCANMsgType.
For example:
#include <libpcan.h>
…
/* initialize the CAN 2.0 channel with 500 kbps BTR0BTR1, accepting extended ID. */
status = CAN_Init(h, CAN_BAUD_500K, CAN_INIT_TYPE_EX);
37
PCAN Driver for Linux v8 – User Manual
For example:
#include <libpcan.h>
…
msg.ID = 0x123
msg.MSGTYPE = MSGTYPE_STANDARD;
msg.LEN = 3;
msg.DATA[0] = 0x01;
msg.DATA[1] = 0x02;
msg.DATA[2] = 0x03;
/* write standard msg ID = 0x123. with 3 data bytes 0x01 0x02 0x03
* (the function may block)
*/
status = CAN_Write(h, &msg);
For example:
#include <libpcan.h>
…
/* wait for a CAN 2.0 msg receievd from the CAN channel
* (the function may block)
*/
status = CAN_Read(h, &msg);
Note: Reading the status of a channel with this function clears it!
38
PCAN Driver for Linux v8 – User Manual
For example:
#include <libpcan.h>
…
/* get the status of a CAN 2.0 channel */
status = CAN_Status(h);
For example:
#include <libpcan.h>
…
/* wait for a CAN 2.0 msg receievd from the CAN channel
* (the function may block)
*/
CAN_Close(h);
To get profit from the multi-tasking environment of Linux, the library has been extended with the
following LINUX_XXX() functions:
39
PCAN Driver for Linux v8 – User Manual
These new ioctl codes are also encapsulated by some new entry points of the new libpcanfd library.
These new entry points are defined in libpcanfd.h.
Note: The test application pcanfdtst uses these new entry points.
40
PCAN Driver for Linux v8 – User Manual
This new library does not anymore encapsulate CAN channels into any HANDLE objects, but directly
deals with file descriptors returned by the open() system call, made on the corresponding device node.
Note: The old and new APIs are not compatible! Once a CAN channel is opened through one API, it
cannot be used with the other one. In other words, opening a CAN channel selects the API that is
used for the connection.
The new API offers several levels of usage. While Level 1 encapsulates the above ioctl codes, Level 2 API
offers a more friendly way of opening and closing a device node.
Finally, all of the entry points of this new API return an integer value. If it is negative, it must be
interpreted as an error code that equals to –errno.
struct pcanfd_init {
__u32 flags;
__u32 clock_Hz;
struct pcan_bittiming nominal;
struct pcan_bittiming data;
};
41
PCAN Driver for Linux v8 – User Manual
struct pcanfd_state {
__u16 ver_major, ver_minor, ver_subminor;
struct pcanfd_msg_filter {
__u32 id_from; /* msgs ID in range [id_from..id_to] */
__u32 id_to; /* and flags == msg_flags */
__u32 msg_flags; /* will be passed to applications */
};
42
PCAN Driver for Linux v8 – User Manual
struct pcanfd_msg_filters {
__u32 count
struct pcanfd_msg_filter list[0];
};
Note: The count field should contain the number of message filters saved in the list[] array field.
struct pcanfd_msg {
__u16 type; /* PCANFD_TYPE_xxx */
__u16 data_len; /* true length (not the DLC) */
__u32 id;
__u32 flags; /* PCANFD_xxx definitions */
struct timeval timestamp;
__u8 ctrlr_data[PCANFD_CTRLR_MAXDATALEN];
__u8 data[PCANFD_MAXDATALEN] __attribute__((aligned(8)));
};
This C structure object is able to carry a CAN 2.0 as well as a CAN FD message. It also can contain some
out-of-band message types (like status messages) that can be pushed by the driver to the application.
Note: Writing a message to the CAN bus might block the calling task, unless the device node has
been opened in non-blocking mode. In that case, -EWOULDBLOCK is returned by this function if the
task had not enough room to store the outgoing message.
43
PCAN Driver for Linux v8 – User Manual
struct pcanfd_msgs {
__u32 count;
struct pcanfd_msg list[0];
};
This C structure object is able to carry several CAN 2.0 and CAN FD messages. The number of messages
to write is given by the count field. This field is also used to indicate how many messages have really
been written in the transmit queue of the device.
Note: Writing several messages to the CAN bus might block the calling task, unless the device node
has been opened in non-blocking mode. In that case, -EWOULDBLOCK is returned by this function if
the task had not enough room to store the outgoing messages.
If at least one message has been successfully written in the transmit queue, then the function returns 0.
Otherwise, it returns a negative error code.
Using this function saves memory copies and constant round trips between kernel and user spaces.
44
PCAN Driver for Linux v8 – User Manual
Example:
#include <malloc.h>
#include <libpcanfd.h>
/* put all of the messages at once in the transmit queue of the device… */
err = pcanfd_send_msgs(fd, pml);
if (err)
printf("Only %u/5 msgs have been sent because of errno=%d\n",
pml->count, err)
free(pml);
…
Note: Reading a message from the driver might block the calling task, unless the device node has
been opened in non-blocking mode. In that case, -EWOULDBLOCK is returned by this function if the
task didn't find any message to read.
45
PCAN Driver for Linux v8 – User Manual
struct pcanfd_msgs {
__u32 count;
struct pcanfd_msg list[0];
};
This C structure object is able to carry several CAN 2.0 and CAN FD messages. The maximum number of
messages the list is able to contain must be set in the count field. When returning from this function, the
count field is set by the driver to the real number of copied messages.
Note: Reading several messages from the driver might block the calling task, unless the device node
has been opened in non-blocking mode. In that case, -EWOULDBLOCK is returned by this function if
the task didn't find any message to read.
If at least one message has been successfully read, then the function returns 0. Otherwise, it returns a
negative error code.
Using this function saves memory copies and constant round trips between kernel and user spaces.
46
PCAN Driver for Linux v8 – User Manual
Example:
#include <malloc.h>
#include <libpcanfd.h>
#include <errno.h>
return -EINVAL
}
free(pml);
…
If the return value is positive, then it indicates the real count of messages read from the device input
queue. Otherwise, it's an error code.
47
PCAN Driver for Linux v8 – User Manual
Table 10 describes the order and how each bit of the flags argument is interpreted:
Bit Description
OFD_BITRATE The specification of the nominal bitrate starts with the third parameter:
If OFD_BTR0BTR1 is set too, then the third parameter is interpreted as a 16-bit value
respecting the BTR0BTR1 SJA1000 format.
If OFD_BRPTSEGSJW is specified, then the 3rd, 4th, 5th, and 6th parameters are
interpreted as BRP, TSEG1, TSEG2, and SJW values.
If none of the above bits is set, then the third argument is interpreted as a bits-per-
second value.
OFD_DBITRATE The data bitrate is given in the next arguments:
If OFD_BTR0BTR1 is set too, then the next parameter is interpreted as a 16-bit value
respecting the BTR0BTR1 SJA1000 format.
If OFD_BRPTSEGSJW is specified, then the 4 next parameters are interpreted as BRP,
TSEG1, TSEG2 and SJW values.
If none of the above bits is set, then the next argument is interpreted as a bits-per-
second value.
OFD_CLOCKHZ The clock frequency (in Hz) to select in the CAN controller is given in the next
argument.
OFD_NONBLOCKING The device node is opened in non-blocking mode.
PCANFD_INIT_xxx All of these flags are used to initialize the CAN device, as if it was initialized using
“int pcanfd_set_init(int fd, struct pcanfd_init *pfdi);”.
Example:
#include <libpcanfd.h>
int fd;
/* open the 1st CANFD channel of the PCAN-USB Pro FD and set 1Mbps+2Mbps bitrate */
fd = pcanfd_open("/dev/pcanusbprofd0",
OFD_BITRATE|OFD_DBITRATE,
1000000,
2000000);
…
In this case the user application can neither use the libpcan nor the libpcanfd library, but has to be
built over the socket API instead. The programmer can access the online documentation, starting, for
example, at these links:
https://en.wikipedia.org/wiki/SocketCAN
https://www.kernel.org/doc/Documentation/networking/can.txt
48