PCAN-Driver for Linux
Total Page:16
File Type:pdf, Size:1020Kb
PCAN-driver for Linux Copyright (C) 2002 -2005 Peak System-Technik GmbH www.peak-system.com [email protected] and Klaus Hitschler [email protected] PCAN-driver for Linux page 1 of 20 History of the document first draft Hi 13.01.2002 rescue after loss of data Hi 10.02.2002 format revision, read/write tables Hi 20.02.2002 delete typographic mistakes Hi 21.02.2002 PCAN-USB integrated Hi 09.02.2003 obfuscation of „pcan_usb_kernel.c“ is described Hi 23.02.2003 devfs, kernel-2.5 support, LGPL Hi 04.08.2003 1st revision for kernel 2.6.x Hi 02.05.2004 enlarge FAQ, corrections Hi 13.05.2004 simple correction for RPM make procedure Hi 14.08.2004 additional compiler switches Hi 19.07.2005 PCAN-driver for Linux page 2 of 20 table of documents Disclaimer..........................................................................................................................4 Characteristics of the 'pcan.o' or 'pcan.ko' driver..............................................................4 Characteristics of the 'libpcan.so' library...........................................................................5 Preliminary notes...............................................................................................................5 Installation with RPM.........................................................................................................6 Installation of source RPM........................................................................................6 Customization of 'modules.conf' or 'modprobe.conf'.................................................7 Installation of the driver ............................................................................................7 Manual installation.............................................................................................................7 Manual file unpacking ..............................................................................................7 Specifics with the driver installation for PCAN-USB ................................................8 Manual installation of the driver ...............................................................................9 Manual installation of the shared library.................................................................10 Manual installation of the header-files....................................................................10 Semi-automatic installation with translation.....................................................................11 Installation test, use of test programs..............................................................................11 Most important header files ............................................................................................13 Compilation of the driver..................................................................................................13 Use cases ...............................................................................................................13 Prerequisites for compilation of the sources...........................................................14 Support for Cross-Compilation................................................................................15 FAQs................................................................................................................................15 Appendix..........................................................................................................................19 PCAN-driver for Linux page 3 of 20 Disclaimer Part of this program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License or LGPL Lesser General Public License as published by the Free Software Foundation version 2 of the License. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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. Characteristics of the 'pcan.o' or 'pcan.ko' driver The „pcan.o“ or „pcan.ko“ driver is supporting PCAN-PCI, PCAN-ISA, PCAN-PC/104, PCAN-Dongle as well as PCAN-USB hardware. Depending on the type of hardware (PCI, ISA, Dongle, USB) 8 channels for each type can be supported. For PCAN-ISA, PCAN-PC/104 and PCAN-Dongle the base address and the used interrupt are adjustable. If no parameters are provided then the driver uses factory defaults. A user program can communicate with the driver in two different ways: 1. ASCII formatted data can be provided or accepted over a „read()“ or „write()“ interface. This data contains information from received or transmitted telegrams or about channel initializing parameters. 2. With a „ioctl()“ interface. Through this interface user programs are able to receive and to transmit CAN-telegrams as well. However it is possible to get information about the diagnosis of the channel status and to initialize the CAN-channel. The driver can be used from more than one user program at the same time and the simultaneous use of lots of interfaces and/or CAN channels is supported. If more than one user program communicates with the same CAN-channel the input or output is shared. (e.g.: Many user programs are accidentally sharing the received telegrams.) Up from Release_20030622_x the device file system is being supported optionally. Using the devfs it's not necessary to create device files manually any more. This is taken over by the kernel in cooperation with the driver and the daemon devfsd. The device file system has to be enabled within the kernel. (From kernel version 2.6.x on the kernel developers depreciate the use of devfs so for the time being the driver is not supporting this.) The reading or writing of telegrams can block if the receive buffer doesn't contain data any more or if the write buffer is full. This behaviour can be disabled by opening the path as non-blocking. PCAN-driver for Linux page 4 of 20 The „select“-method is supported. The interface to the driver (constants and structures) is defined in the header file „pcan.h“. Characteristics of the 'libpcan.so' library The „libpcan.so“ library is providing an easier interface for using the properties of the PCAN-drivers. The library interface is similar to the ones from MS-Windows and make the porting of applications easier. There are also some calls which adapt better to the specifics of Linux. They are marked with a 'LINUX_..' as prefix. (Example: HANDLE LINUX_CAN_Open(char *szDeviceName, int nFlags);) Application Shared library Driver Picture 1. calling hierarchy The interface of the library is described within the C/C++-header file „libpcan.h“. Please note that „libpcan.h“ includes the „pcan.h“ file. The source code is under LGPL so it is for utilizing within proprietary software without any exceptions. Preliminary notes Note: Before installing the software the hardware has to be installed in or at the computer (Exception: PCAN-Dongle or PCAN-USB, see at (6*)). This manual is describing the installation process on a x86-Linux-computer with installed kernel 2.4.x. and a SuSE 8.0 system. Exceptions for kernel 2.2.x. 2.6.x and x86-RedHat systems are particularly mentioned. During the installation sometimes a console and perhaps an editor as well will be used in the „root“- mode. If you want to login as „root“ user within a console or xterm-session you can use the 'su' command or the built in menu „file/root console“. PCAN-driver for Linux page 5 of 20 To start an editor in the „root“ – mode, just invoke from the menu „system/terminals/terminal (system manager mode)“ in KDE. From the console command line you can invoke the editor „kwrite“, „kate“ or „emacs“. For some distributions the standard path doesn't include the „/sbin“ folder. Then installation commands have to typed in with „/sbin/“ ahead. Examples: /sbin/modprobe ... instead of modprobe ... /sbin/insmod ... instead of insmod ... /sbin/rmmod ... instead of rmmod ... /sbin/modinfo ... instead of modinfo ... Installation with RPM The installation comprise three files: Installation-en.pdf description in PDF format. peak-linux-driver-20040501-3.3.src.rpm the RPM-source-file. peak-linux-driver.3.3.tar.gz the packed tar-sources. (Note: The term for release or the version for file names can change.) The installation with RPM creates an installable RPM – package with standard settings for the local target system. If the standard settings don't fit you can do a manual installation. Installation of source RPM Please type in the command line (as „root“ user): rpm --rebuild peak-linux-driver-20040501-3.3.src.rpm or rpmbuild –rebuild peak-linux-driver-20040501-3.3.src.rpm if the file „peak-linux-driver-20040501-3.3.src.rpm“ is in your current directory. This invocation expects the previous installation of the gcc-compiler, the kernel-headers and the make tools. The translation with and for systems with kernel 2.6.x needs an additionally configured kernel and all of the kernel sources. At the successful end of this rebuild RPM is filing at: „/usr/src/packages/“ or „/usr/src/redhat“ a system specific binary-installation for SuSE or RedHat in this folder. e.g. /usr/src/redhat/RPMS/i386/peak-linux-driver-20040501-3.3.i386.rpm