TPMC810-SW-82. Linux Device Driver. User Manual. The Embedded I/O Company. Isolated 2x CAN Bus Version 1.2.x. Issue 1.2.

Similar documents
TDRV010-SW-95. QNX6 - Neutrino Device Driver. Isolated 2x CAN Bus. Version 1.0.x. User Manual. Issue September 2016

TPMC901-SW-95. QNX4 - Neutrino Device Driver. User Manual. The Embedded I/O Company. 6/4/2 Channel Extended CAN-Bus PMC

TIP675-SW-82. Linux Device Driver. 48 TTL I/O Lines with Interrupts Version 1.2.x. User Manual. Issue November 2013

The Embedded I/O Company TIP700-SW-82 Linux Device Driver User Manual TEWS TECHNOLOGIES GmbH TEWS TECHNOLOGIES LLC

TDRV011-SW-82. Linux Device Driver. Extended CAN Bus Version 1.0.x. User Manual. Issue April 2018

TPMC680-SW-82. Linux Device Driver. 64 Digital Input/Output Version 1.1.x. User Manual. Issue April 2010

TPMC860-SW-82. Linux Device Driver. 4 Channel Isolated Serial Interface RS232 Version 1.4.x. User Manual. Issue 1.4.

CARRIER-SW-82. Linux Device Driver. IPAC Carrier Version 2.2.x. User Manual. Issue November 2017

TCP866-SW-82. Linux Device Driver. User Manual. The Embedded I/O Company. 8 Channel Serial PMC Version 1.0.x. Issue 1.

TPMC917-SW-82. Linux Device Driver. User Manual. The Embedded I/O Company. 4 MB SRAM with Battery Backup and 4 Channel Serial Interface Version 1.0.

TDRV002-SW-82. Linux Device Driver. Multi-Channel Serial Interface Version 1.8.x. User Manual. Issue November 2017

TPMC500-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. 32 Channel 12 Bit ADC. Version 2.0.x. Issue 2.0.

TIP570-SW-95 QNX-Neutrino Device Driver TIP570 16/8 Channel 12 Bit ADC and 8 Channel 12 Bit DAC on SBS PCI40 Carrier

TIP114-SW-72. LynxOS Device Driver. User Manual. The Embedded I/O Company. 10 Channel Absolute Encoder Interface (SSI) Version 1.0.

TPMC815-SW-72. LynxOS Device Driver. User Manual. The Embedded I/O Company. ARCNET Controller. Version 1.0.x. Issue 1.0 May 2004

TIP610-SW-95 QNX-Neutrino Device Driver TIP610 16/20 Channel Digital I/O on SBS PCI40 Carrier

TPMC821-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. INTERBUS Master G4 PMC. Version 1.4. Issue 1.

TIP670-SW-95. QNX-Neutrino Device Driver. User Manual. The Embedded I/O Company. Digital I/O. Version 1.0.x. Issue August 2008.

TIP700-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. Digital Output 24V DC. Version 2.0.x. Issue June 2008.

TDRV006-SW-42. VxWorks Device Driver. 64 Digital Inputs/Outputs (Bit I/O) Version 4.0.x. User Manual. Issue December 2017

TIP120-SW-42. VxWorks Device Driver. Motion Controller with Incremental Encoder Interface. Version 2.1.x. User Manual. Issue 2.1.

TPMC868-SW-42. VxWorks Device Driver. 16 Channel Serial PMC. Version 2.1.x. User Manual. Issue December 2011

TPMC550-SW-12 OS-9 for PPC Device Driver 8 (4) Channels Isolated 12-bit D/A

Advcan QNX Driver User Manual V1.02

OPTO32A 24 Input Bit, 8 Output Bit Optical Isolator Board

TPMC810. Isolated 2x CAN Bus. Version 1.1. User Manual. Issue June 2009

TPMC815 ARCNET PMC. User Manual. The Embedded I/O Company. Version 2.0. Issue 1.2 November 2002 D

TPMC851-SW-42. VxWorks Device Driver. Multifunction I/O (16 bit ADC/DAC, TTL I/O, Counter) Version 2.0.x. User Manual. Issue 2.0.

TPMC Channel Motion Control. User Manual. The Embedded I/O Company. Version 1.0. Issue 1.3 March 2003 D

TIP866-SW-95. QNX-Neutrino Device Driver. 8 Channel Serial Interface IP. Version 2.1.x. User Manual. Issue October 2009

24DSI32 24DSI12 24-bit, 32 Channel Delta-Sigma A/D Boards

Section 3: File I/O, JSON, Generics. Meghan Cowan

TPMC816. Two Independent Channels Extended CAN Bus PMC Module. Version 2.2. User Manual. Issue August 2014

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

CSE 333 SECTION 3. POSIX I/O Functions

spwr_base & spwr_chan

Standards / Extensions C or C++ Dependencies POSIX.1 XPG4 XPG4.2 Single UNIX Specification, Version 3

TPMC Channel Isolated Serial Interface RS232. Version 1.0. User Manual. Issue August 2017

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

TPMC310. Conduction Cooled PMC Isolated 2 x CAN Bus. Version 1.1. User Manual. Issue June 2014

TPMC Channel Isolated Serial Interface RS422/RS485. Version 1.0. User Manual. Issue July 2009

MaRTE OS Misc utilities

TXMC885. Four Channel 10/100/1000 Mbit/s Ethernet Adapter. Version 1.0. User Manual. Issue October 2011

CSE 333 SECTION 3. POSIX I/O Functions

CARRIER-SW-42. VxWorks Device Driver. IPAC Carrier. Version 4.2.x. User Manual. Issue July 2018

DYNAMIC ENGINEERING 150 DuBois St. Suite C, Santa Cruz, CA Fax Est.

TIP SERCOS IP with 2 Encoder Interfaces. User Manual. The Embedded I/O Company. Version 1.0. Issue 1.3 September 2006 D

Files. Eric McCreath

TPMC /8 Digital Inputs (24V) 16/8 Digital Outputs (24V, 0.5A) Version 3.0. User Manual. Issue June 2014

ADADIO 12 Channel, 16-bit A/D-D/A I/O With 8-bit Discrete Digital I/O

SpiNNaker Application Programming Interface (API)

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

M O T O R O L A C O M P U T E R G R O U P VME DRIVER FOR LINUX USER GUIDE

SPE Runtime Management Library Version 2.2

Janus-MM Basic CAN Driver For Linux 2.6.xx and Windows XP. User Manual Revision A

TCP Channel Serial Interface RS232 / RS422 cpci Module. User Manual. The Embedded I/O Company. Version 1.0. Issue 1.

Gaisler LEON3 RTEMS driver documentation

AN Philips LPC2000 CAN driver. Document information

UNIX System Calls. Sys Calls versus Library Func

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes

CS240: Programming in C

in Berlin (Germany) Sponsored by Motorola Semiconductor NEC Electronics (Europe) Siemens Semiconductors Organized by

TIP120. Motion Controller with Incremental Encoder Interface. Version 1.0. User Manual. Issue August 2014

Lecture files in /home/hwang/cs375/lecture05 on csserver.

TIP815. ARCNET Controller. Version 1.0. User Manual. Issue September 2009

Operating Systems II Systems Programming in C

TPMC Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014

JetBox 8152 User Manual. WinCE 6.0 Canbus.

Amsterdam Compiler Kit-ANSI C compiler compliance statements

TPMC Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014

DYNAMIC ENGINEERING 150 DuBois, Suite C Santa Cruz, CA (831) Fax (831) Est

10. I/O System Library

Experiment 6 The Real World Interface

CSX600 Runtime Software. User Guide

TPMC500. Optically Isolated 32 Channel 12 Bit ADC. Version 1.1. User Manual. Issue January 2014

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Fall 2015 COMP Operating Systems. Lab #3

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

ICS-121. VxWORKS DEVICE DRIVER MANUAL

NAME attr extended attributes on XFS filesystem objects. SYNOPSIS attr [ LRq ] s attrname [ V attrvalue ] pathname

DirectFB Fusion kernel module: introduction and API

Naked C Lecture 6. File Operations and System Calls

TCP Channel Serial Interface RS232/RS422. Version 1.0. User Manual. Issue August 2014

TPMC x ADC, 16x/0x DAC and 8x Digital I/O. Version 1.0. User Manual. Issue May 2018

MicroBlaze TFTP Server User Guide

Operating systems. Lecture 7

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

Linux Device Drivers Interrupt Requests

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

TIP550. Optically Isolated 8/4 Channel 12-bit D/A. Version 1.2. User Manual. Issue October 2009

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

The Linux driver for the Rome PCI-AER board

TIP111. Motion Controller with Absolute Encoder Interface (SSI) User Manual. The Embedded I/O Company. Version 1.1. Issue 1.4 September 2005 D

Input / Output. Kevin Webb Swarthmore College April 12, 2018

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

TPCE260. PCI Express PMC Carrier. Version 1.0. User Manual. Issue August 2014

Outline. Operating Systems: Devices and I/O p. 1/18

libnetfilter_log Reference Manual

Transcription:

The Embedded I/O Company TPMC810-SW-82 Linux Device Driver Isolated 2x CAN Bus Version 1.2.x User Manual Issue 1.2.0 January 2006 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 25469 Halstenbek / Germany Phone: +49-(0)4101-4058-0 Fax: +49-(0)4101-4058-19 e-mail: info@tews.com www.tews.com TEWS TECHNOLOGIES LLC 1 E. Liberty Street, Sixth Floor Reno, Nevada 89504 / USA Phone: +1 (775) 686 6077 Fax: +1 (775) 686 6024 e-mail: usasales@tews.com www.tews.com

TPMC810-SW-82 Isolated 2x CAN Bus Linux Device Driver This document contains information, which is proprietary to TEWS TECHNOLOGIES GmbH. Any reproduction without written permission is forbidden. TEWS TECHNOLOGIES GmbH has made any effort to ensure that this manual is accurate and complete. However TEWS TECHNOLOGIES GmbH reserves the right to change the product described in this document at any time without notice. TEWS TECHNOLOGIES GmbH is not liable for any damage arising out of the application or use of the device described herein. 2005-2006 by TEWS TECHNOLOGIES GmbH Issue Description Date 1.0 First Issue April 14, 2004 1.1.0 Linux Kernel 2.6.x Revision March 22, 2005 1.1.1 depmod added to Installation section January 19, 2006 1.2.0 Modified file list January 24, 2006 TPMC810-SW-82 Linux Device Driver Page 2 of 35

Table of Content 1 INTRODUCTION 4 2 INSTALLATION. 5 2.1 Build and install the device driver.5 2.2 Uninstall the device driver.6 2.3 Install device driver into the running kernel..6 2.4 Remove device driver from the running kernel 6 2.5 Change Major Device Number.7 2.6 Receive Queue Configuration..7 3 DEVICE INPUT/OUTPUT FUNCTIONS 8 3.1 open()..8 3.2 close()10 3.3 read().11 3.4 write() 14 3.5 ioctl().17 3.5.1 TP810_IOCSBITTIMING.19 3.5.2 TP810_IOCSSETFILTER..21 3.5.3 TP810_IOCBUSON..23 3.5.4 TP810_IOCBUSOFF.24 3.5.5 TP810_IOCFLUSH 25 3.5.6 TP810_IOCGCANSTATUS..26 3.5.7 TP810_IOCENABLE_SELFTEST..28 3.5.8 TP810_IOCDISABLE_SELFTEST.29 3.5.9 TP810_IOCENABLE_LISTENONLY 30 3.5.10 TP810_IOCDISABLE_ LISTENONLY31 3.5.11 TP810_IOCSSETLIMIT.32 3.6 Step by Step Driver Initialization.33 4 DIAGNOSTIC 34 TPMC810-SW-82 Linux Device Driver Page 3 of 35

1 Introduction The TPMC810-SW-82 Linux device driver allows the operation of a TPMC810 Isolated 2x CAN PMC on Linux operating systems. Supported features: Transmission and receive of Standard and Extended Identifiers Standard bit rates from 5 kbit up to 1 Mbit and user defined bit rates Message acceptance filtering Single-Shot transmission Listen only mode Message self reception Programmable error warning limit The TPMC810-SW-82 device driver supports the modules listed below: TPMC810-10 Isolated 2x CAN Bus (PMC) To get more information about the features and use of TPMC810 device it is recommended to read the manuals listed below. TPMC810 User manual TPMC810 Engineering Manual SJA1000 CAN Controller Manual TPMC810-SW-82 Linux Device Driver Page 4 of 35

2 Installation Following files are located on the distribution media: Directory path.\tpmc810-sw-82\ : TPMC810-SW-82-1.2.0.pdf TPMC810-SW-82-SRC.tar.gz Release.txt This manual in PDF format GZIP compressed archive with driver source code Release information For installation the files have to be copied to the desired target directory. The GZIP compressed archive TPMC810-SW-82-SRC.tar.gz contains the following files and directories: Directory path./tpmc810/ : tpmc810.c tpmc810def.h tpmc810.h sja1000.h makenode Makefile example/tpmc810exa.c example/makefile include/tpmodule.h include/tpmodule.c include/tpxxxhwdep.h include/tpxxxhwdep.c Driver source code Driver include file Driver include file for application program Driver include file (CAN controller information) Script to create device nodes on the file system Device driver make file Example application Example application make file Driver and kernel independent library header file Driver and kernel independent library source file HAL library header file HAL library source file In order to perform an installation, extract all files of the archive TPMC810-SW-82-SRC.tar.gz to the desired target directory. After this do the following steps: Login as root and change to the target directory Copy tpmc810.h to /usr/include to make it accessible for user applications 2.1 Build and install the device driver Login as root Change to the target directory To create and install the driver in the module directory /lib/modules/<version>/misc enter: # make install To update the kernel's module dependencies, enter the following command: # depmod aq TPMC810-SW-82 Linux Device Driver Page 5 of 35

2.2 Uninstall the device driver Login as root Change to the target directory To remove the driver from the module directory /lib/modules/<version>/misc enter: # make uninstall 2.3 Install device driver into the running kernel To load the device driver into the running kernel, login as root and execute the following commands: # modprobe tpmc810drv After the first build or if you are using dynamic major device allocation it s necessary to create new device nodes on the file system. Please execute the script file makenode to do this. If your kernel has enabled the device file system (devfs) then you have to skip running the makenode script. Instead of creating device nodes from the script the driver itself takes creating and destroying of device nodes in its responsibility. # sh makenode On success the device driver will create a minor device for each TPMC810 channel found. The first channel of the first TPMC810 module can be accessed with device node /dev/tpmc810_0, the second channel with device node /dev/tpmc810_1, the first channel of a second TPMC810 module with device node /dev/tpmc810_2 and so on. The assignment of device nodes to physical TPMC810 modules depends on the search order of the PCI bus driver. 2.4 Remove device driver from the running kernel To remove the device driver from the running kernel login as root and execute the following command: # modprobe r tpmc810drv If your kernel has enabled devfs, all /dev/tpmc810_x nodes will be automatically removed from your file system after this. Be sure that the driver isn t opened by any application program. If opened you will get the response tpmc810drv: Device or resource busy and the driver will still remain in the system until you close all opened files and execute modprobe r again. TPMC810-SW-82 Linux Device Driver Page 6 of 35

2.5 Change Major Device Number This paragraph is only for Linux kernels without DEVFS installed. The TPCM810 driver use dynamic allocation of major device numbers per default. If this isn t suitable for the application it s possible to define a major number for the driver. To change the major number edit the file tpmc810def.h, change the following symbol to appropriate value and entermake install to create a new driver. TPMC810_MAJOR Valid numbers are in range between 0 and 255. A value of 0 means dynamic number allocation. Example: #define TPMC810_MAJOR 122 2.6 Receive Queue Configuration Received CAN messages will be stored in a FIFO buffer. The depth of the FIFO can be adapted by changing the following symbol in tpmc810def.h. TP810_RX_FIFO_SIZE Defines the depth of the message FIFO buffer (default = 100). Valid numbers are in range between 1 and MAXINT. TPMC810-SW-82 Linux Device Driver Page 7 of 35

3 Device Input/Output functions This chapter describes the interface to the device driver I/O system. 3.1 open() NAME open() - open a file descriptor SYNOPSIS #include <fcntl.h> int open (const char *filename, int flags) DESCRIPTION The open function creates and returns a new file descriptor for the file named by filename. The flags argument controls how the file is to be opened. This is a bit mask; you create the value by the bitwise OR of the appropriate parameters (using the operator in C). See also the GNU C Library documentation for more information about the open function and open flags. EXAMPLE int fd; fd = open( /dev/tpmc810_0, O_RDWR); RETURNS The normal return value from open is a non-negative integer file descriptor. In the case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. TPMC810-SW-82 Linux Device Driver Page 8 of 35

ERRORS E_NODEV The requested minor device does not exist. This is the only error code returned by the driver, other codes may be returned by the I/O system during open. For more information about open error codes, see the GNU C Library description Low- Level Input/Output. SEE ALSO GNU C Library description Low-Level Input/Output TPMC810-SW-82 Linux Device Driver Page 9 of 35

3.2 close() NAME close() close a file descriptor SYNOPSIS #include <unistd.h> int close (int filedes) DESCRIPTION The close function closes the file descriptor filedes. EXAMPLE int fd; if (close(fd)!= 0) /* handle close error conditions */ RETURNS The normal return value from close is 0. In the case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. ERRORS E_NODEV The requested minor device does not exist. This is the only error code returned by the driver, other codes may be returned by the I/O system during close. For more information about close error codes, see the GNU C Library description Low- Level Input/Output. SEE ALSO GNU C Library description Low-Level Input/Output TPMC810-SW-82 Linux Device Driver Page 10 of 35

3.3 read() NAME read() read from a device SYNOPSIS #include <unistd.h> ssize_t read(int filedes, void *buffer, size_t size) DESCRIPTION The read function reads a CAN message from the driver receive queue. A pointer to the callers message buffer (TP810_MSG_BUF) and the size of this structure are passed by the parameters buffer and size to the device. The TP810_MSG_BUF structure has the following layout: typedef struct unsigned long unsigned char unsigned char unsigned char long unsigned char Identifier; IOFlags; MsgLen; Data[8]; Timeout; Status; TP810_MSG_BUF, *PTP810_MSG_BUF; Identifier IOFlags Receives the message identifier of the read CAN message. Receives CAN message attributes as a set of bit flags. The following attribute flags are possible: TP810_EXTENDED Set if the received message is an extended message frame. Reset for standard message frames. TP810_REMOTE_FRAME Set if the received message is a remote transmission request (RTR) frame. TPMC810-SW-82 Linux Device Driver Page 11 of 35

MsgLen Receives the number of message data bytes (08). Data This buffer receives up to 8 data bytes. Data[0] receives message Data 0, Data[1] receives message Data 1 and so on. Timeout Status Specifies the amount of time (in ticks) the caller is willing to wait for execution of read. A value of 0 means wait indefinitely. This parameter receives status information about overrun conditions either in the CAN controller or intermediate software FIFO. TP810_SUCCESS TP810_FIFO_OVERRUN TP810_MSGOBJ_OVERRUN No messages lost One or more messages was overwritten in the receive queue FIFO. This problem occurs if the FIFO is too small for the application read interval. One or more messages were overwritten in the CAN controller message object because the interrupt latency is too large. Reduce the CAN bit rate or upgrade the system speed. EXAMPLE int fd; ssize_t numbytes; TP810_MSG_BUF msgbuf; msgbuf.timeout = 200; numbytes = read(fd, &msgbuf, sizeof(msgbuf)); if (numbytes > 0) /* process received CAN message */ RETURNS On success read returns the size of structure TP810_MSG_BUF. In the case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. TPMC810-SW-82 Linux Device Driver Page 12 of 35

ERRORS EINVAL EFAULT ECONNREFUSED EAGAIN ETIME EINTR Invalid argument. This error code is returned if the size of the message buffer is too small. Invalid pointer to the message buffer. The controller is in bus off state and no message is available in the driver receive queue. Note, as long as CAN messages are available in the receive queue FIFO, bus off conditions were not reported by a read function. This means you can read all CAN messages out of the receive queue FIFO during bus off state without an error result. Resource temporarily unavailable; the call might work if you try again later. This error occurs only if the device is opened with the flag O_NONBLOCK set. The allowed time to finish the read request is elapsed. Interrupted function call; an asynchronous signal occurred and prevented completion of the call. When this happens, you should try the call again. SEE ALSO GNU C Library description Low-Level Input/Output TPMC810-SW-82 Linux Device Driver Page 13 of 35

3.4 write() NAME write() read to a device SYNOPSIS #include <unistd.h> ssize_t write(int filedes, void *buffer, size_t size) DESCRIPTION The write function writes a CAN message to the device with descriptor filedes. A pointer to the callers message buffer (TP810_MSG_BUF) and the size of this structure are passed by the parameters buffer and size to the device. The TP810_MSG_BUF structure has the following layout: typedef struct unsigned long unsigned char unsigned char unsigned char long unsigned char Identifier; IOFlags; MsgLen; Data[8]; Timeout; Status; TP810_MSG_BUF, *PTP810_MSG_BUF; Identifier IOFLags Contains the message identifier of the CAN message to write. Contains a set of bit flags, which define message attributes and controls the write operation. To set more that one bit flag the predefined macros must be binary ORed. TP810_EXTENDED TP810_REMOTE_FRAME TP810_SINGLE_SHOT Transmit an extended message frame. If this macro isn't set or the "dummy" macro TP810_STANDARD is set a standard frame will be transmitted. A remote transmission request (RTR bit is set) will be transmitted. No re-transmission will be performed if an error occurred or the arbitration will be lost during transmission (single-shot transmission). TPMC810-SW-82 Linux Device Driver Page 14 of 35

MsgLen Data Timeout Status TP810_SELF_RECEPTION The message will be transmitted and simultaneously received if the acceptance filter is set to the corresponding identifier. Contains the number of message data bytes (0..8). This buffer contains up to 8 data bytes. Data[0] contains message Data 0, Data[1] contains message Data 1 and so on. Specifies the amount of time (in ticks) the caller is willing to wait for execution of write. This parameter is unused for this control function. EXAMPLE int fd; int result; TP810_MSG_BUF msgbuf; /* **Write two data bytes with extended identifier 1234 to **the CANbus and wait max. 200 ticks on execution. **The transmitted frame will be received simultaneously. */ msgbuf.identifier = 1234; msgbuf.timeout = 200; msgbuf.ioflags = TP810_EXTENDED TP810_SELF_RECEPTION; msgbuf.msglen = 2; msgbuf.data[0] = 0xaa; msgbuf.data[1] = 0x55; result = write(fd, &msgbuf, sizeof(msgbuf)); if( result!= sizeof(tp810_msg_buf)) printf( "\nwrite failed --> Error = %d.\n", errno ); TPMC810-SW-82 Linux Device Driver Page 15 of 35

RETURNS On success write returns the size of structure TP810_MSG_BUF. In the case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. ERRORS EINVAL EFAULT ECONNREFUSED EAGAIN ETIME EINTR Invalid argument. This error code is returned if the size of the message buffer is too small. Invalid pointer to the message buffer. The controller is in bus off state and unable to transmit messages. Resource temporarily unavailable; the call might work if you try again later. This error occurs only if the device is opened with the flag O_NONBLOCK set. The allowed time to finish the write request is elapsed. This occurs if currently no message object is available or if the CAN bus is overloaded and the priority of the message identifier is too low. Interrupted function call; an asynchronous signal occurred and prevented completion of the call. When this happens, you should try the call again. SEE ALSO GNU C Library description Low-Level Input/Output TPMC810-SW-82 Linux Device Driver Page 16 of 35

3.5 ioctl() NAME ioctl() device control functions SYNOPSIS #include <sys/ioctl.h> int ioctl(int filedes, int request [, void *argp]) DESCRIPTION The ioctl function sends a control code directly to a device, specified by filedes, causing the corresponding device to perform the requested operation. The argument request specifies the control code for the operation. The optional argument argp depends on the selected request and is described for each request in detail later in this chapter. The following ioctl codes are defined in TPMC810.h: Symbol TP810_IOCSBITTIMING TP810_IOCSSETFILTER TP810_IOCBUSON TP810_IOCBUSOFF TP810_IOCFLUSH TP810_IOCGCANSTATUS TP810_IOCENABLE_SELFTEST TP810_IOCDISABLE_SELFTEST TP810_IOCENABLE_LISTENONLY TP810_IOCDISABLE_LISTENONLY TP810_IOCSSETLIMIT Meaning Setup a new bit timing Setup acceptance filter Enter the bus on state Enter the bus off state Flush one or all receive queues Returns CAN controller status information Enable self test mode Disable self test mode Enable listen only mode Disable listen only mode Set new error warning limit See behind for more detailed information on each control code. To use these TPMC810 specific control codes the header file TPMC810.h must be included in the application TPMC810-SW-82 Linux Device Driver Page 17 of 35

RETURNS On success, zero is returned. In the case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. ERRORS EINVAL Invalid argument. This error code is returned if the requested ioctl function is unknown. Please check the argument request. Other function dependant error codes will be described for each ioctl code separately. Note, the TPMC810 driver always returns standard Linux error codes. SEE ALSO ioctl man pages TPMC810-SW-82 Linux Device Driver Page 18 of 35

3.5.1 TP810_IOCSBITTIMING NAME TP810_IOCSBITTIMING - Setup new bit timing DESCRIPTION This ioctl function modifies the bit timing register of the CAN controller to setup a new CAN bus transfer speed. A pointer to the caller's parameter buffer (TP810_TIMING) is passed by the argument pointer arg to the driver. Keep in mind to setup a valid bit timing value before changing into the Bus On state. The TP810_TIMING structure has the following layout: typedef struct unsigned short unsigned short TP810_TIMING, *PTP810_TIMING; TimingValue TimingValue; ThreeSamples; This parameter holds the new value for the bit timing register 0 (bit 07) and for the bit timing register 1 (bit 815). Possible transfer rates are between 5 Kbit per second and 1 Mbit per second. The include file 'tpmc810.h' contains predefined transfer rate symbols (TP810_5KBIT TP810_1MBIT). For other transfer rates please follow the instructions of the SJA1000 Product Specification, which is also part of the engineering kit TPMC810-EK. ThreeSamples If this parameter is TRUE (1) the CAN bus is sampled three times per bit time instead of one. Use one sample point for faster bit rates and three sample points for slower bit rate to make the CAN bus more immune against noise spikes. TPMC810-SW-82 Linux Device Driver Page 19 of 35

EXAMPLE int fd; int result; TP810_TIMING BitTimingParam; BitTimingParam.TimingValue = TP810_100KBIT; BitTimingParam.ThreeSamples = FALSE; result = ioctl(fd, TP810_IOCSBITTIMING, (char*)&bittimingparam); if (result < 0) /* handle ioctl error */ SEE ALSO tpmc810.h for predefined bus timing constants SJA1000 Product Specification Manual 6.5.1/2 BUS TIMING REGISTER TPMC810-SW-82 Linux Device Driver Page 20 of 35

3.5.2 TP810_IOCSSETFILTER NAME TP810_IOCSSETFILTER - Setup acceptance filter DESCRIPTION This ioctl function modifies the acceptance filter of the specified CAN controller device. The acceptance filter compares the received identifier with the acceptance filter and decides whether a message should be accepted or not. If a message passes the acceptance filter it is stored in the RXFIFO. The acceptance filter is defined by the acceptance code registers and the acceptance mask registers. The bit patterns of messages to be received are defined in the acceptance code register. The corresponding acceptance mask registers allow defining certain bit positions to be "don't care" (a 1 at a bit position means "don't care"). A pointer to the caller's parameter buffer (TP810_FILTER) is passed by the parameter pointer arg to the driver. The TP810_FILTER structure has the following layout: typedef struct int unsigned long SingleFilter; AcceptanceCode; unsigned long AcceptanceMask; TP810_FILTER, *PTP810_FILTER; SingleFilter Set TRUE (1) for single filter mode. Set FALSE (0) for dual filter mode. AcceptanceCode The contents of this parameter will be written to acceptance code register of the controller. AcceptanceMask The contents of this parameter will be written to the acceptance mask register of the controller. A detailed description of the acceptance filter and possible filter modes can be found in the SJA1000 Product Specification Manual. TPMC810-SW-82 Linux Device Driver Page 21 of 35

EXAMPLE int fd; int result; TP810_FILTER AcceptFilter; /* Not relevant because all bits are "don't care" */ AcceptFilter.AcceptanceCode = 0x0; /* Mark all bit position don't care */ AcceptFilter.AcceptanceMask = 0xffffffff; /* Single Filter Mode */ AcceptFilter.SingleFilter = 1; // TRUE result = ioctl(fd, TP810_IOCSSETFILTER, (char*)&acceptfilter); if (result < 0) /* handle ioctl error */ SEE ALSO SJA1000 Product Specification Manual 6.4.15 ACCEPTANCE FILTER TPMC810-SW-82 Linux Device Driver Page 22 of 35

3.5.3 TP810_IOCBUSON NAME TP810_IOCBUSON - Enter the bus on state DESCRIPTION This ioctl function sets the specified CAN controller into the Bus On state. After an abnormal rate of occurrences of errors on the CAN bus or after driver startup, the CAN controller enters the Bus Off state. This control function resets the "reset mode" bit in the mode register. The CAN controller begins the busoff recovery sequence and resets the transmit and receive error counters. If the CAN controller counts 128 packets of 11 consecutive recessive bits on the CAN bus, the Bus Off state is exited. The optional argument can be omitted for this ioctl function. Before the driver is able to communicate over the CAN bus after driver startup, this control function must be executed. EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCBUSON); if (result < 0) /* handle ioctl error */ ERRORS This ioctl function returns no specific error codes. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 23 of 35

3.5.4 TP810_IOCBUSOFF NAME TP810_IOCBUSOFF - Enter the bus off state DESCRIPTION This ioctl function sets the specified CAN controller into the Bus Off state. After execution of this control function the CAN controller is completely removed from the CAN bus and cannot communicate until the control function TP810_IOCBUSON is executed. Note: During a pending write of another concurrent thread it s not possible to set the device bus off. The optional argument pointer can be omitted for this ioctl function. EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCBUSOFF); if (result < 0) /* handle ioctl error */ ERRORS EBUSY EIO Another concurrent thread is writing to the device. Try it again later. Unable to enter the BUSOFF mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 24 of 35

3.5.5 TP810_IOCFLUSH NAME TP810_IOCFLUSH - Flush the received message FIFO DESCRIPTION This ioctl function flushes the FIFO buffer of received messages. The optional argument pointer can be omitted for this ioctl function. EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCFLUSH); if (result < 0) /* handle ioctl error */ ERRORS This ioctl function returns no function specific error codes. TPMC810-SW-82 Linux Device Driver Page 25 of 35

3.5.6 TP810_IOCGCANSTATUS NAME TP810_IOCGCANSTATUS - Returns CAN controller status information DESCRIPTION This ioctl function returns the actual contents of several CAN controller registers for diagnostic purposes. A pointer to the callers status buffer (TP810_STATUS) and the size of this structure is passed by the parameters buff and count to the device. The TP810_STATUS structure has the following layout: typedef struct unsigned char unsigned char unsigned char unsigned char unsigned char unsigned char unsigned char ArbitrationLostCapture; ErrorCodeCapture; TxErrorCounter; RxErrorCounter; ErrorWarningLimit; StatusRegister; ModeRegister; unsigned char RxMessageCounterMax; TP810_STATUS, *PTP810_STATUS; ArbitrationLostCapture This parameter receives content of the arbitration lost capture register. This register contains information about the bit position of losing arbitration. ErrorCodeCapture This parameter receives content of the error code capture register. This register contains information about the type and location of errors on the bus. TxErrorCounter This parameter receives content of the TX error counter register. This register contains the current value of the transmit error counter. RxErrorCounter This parameter receives content of the TX error counter register. This register contains the current value of the receive error counter. ErrorWarningLimit This parameter receives content of the error warning limit register. StatusRegister This parameter receives content of the status register. TPMC810-SW-82 Linux Device Driver Page 26 of 35

ModeRegister This parameter receives the content of the mode register. RxMessageCounterMax Contains the peak value of messages in the RXFIFO. This internal counter value will be reset to 0 after reading. EXAMPLE int fd; int result; TP810_STATUS CanStatus; result = ioctl(fd, TP810_IOCGCANSTATUS, (char*)&canstatus); if (result < 0) /* handle ioctl error */ SEE ALSO SJA1000 Product Specification Manual TPMC810-SW-82 Linux Device Driver Page 27 of 35

3.5.7 TP810_IOCENABLE_SELFTEST NAME TP810_IOCENABLE_SELFTEST - Enable self test mode DESCRIPTION This ioctl function enables the self test facility of the SJA1000 CAN controller. In this mode a full node test is possible without any other active node on the bus using the self reception facility (see also 3.4). The CAN controller will perform a successful transmission even if there is no acknowledge received. Also in self test mode the normal functionality is given, that means the CAN controller is able to receive messages from other nodes and can transmit message to other nodes if any connected. The optional argument pointer can be omitted for this ioctl function. This ioctl command will be accepted only in reset mode (BUSOFF). Enter TP810_IOCBUSOFF first otherwise you will get an error (EACCES). EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCENABLE_SELFTEST, NULL); if (result < 0) /* handle ioctl error */ ERRORS EACCES The CAN controller is in operating mode. This mode can be changed only in reset mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 28 of 35

3.5.8 TP810_IOCDISABLE_SELFTEST NAME TP810_IOCDISABLE_SELFTEST - Disable self test mode DESCRIPTION This ioctl function disables the self test facility of the SJA1000 CAN controller, which was before enabled with the ioctl command TP810_IOCENABLE_SELFTEST. The optional argument pointer can be omitted for this function. This ioctl command will be accepted only in reset mode (BUSOFF). Enter TP810_IOCBUSOFF first otherwise you will get an error (EACCES). EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCDISABLE_SELFTEST, NULL); if (result < 0) /* handle ioctl error */ ERRORS EACCES The CAN controller is in operating mode. This mode can be changed only in reset mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 29 of 35

3.5.9 TP810_IOCENABLE_LISTENONLY NAME TP810_IOCENABLE_LISTENONLY - Enable listen only mode DESCRIPTION This ioctl function enables the listen only facility of the SJA1000 CAN controller. In this mode the CAN controller would give no acknowledge to the CAN-bus, even if a message is received successfully. Message transmission is not possible. All other functions can be used like in normal mode. This mode can be used for software driver bit rate detection and 'hot-plugging'. The optional argument pointer can be omitted for this ioctl function. This ioctl command will be accepted only in reset mode (BUSOFF). Enter TP810_IOCBUSOFF first otherwise you will get an error (EACCES). EXAMPLE int fd; int result; result = ioctl(fd, TP810_IOCENABLE_LISTENONLY); if (result < 0) /* handle ioctl error */ ERRORS EACCES The CAN controller is in operating mode. This mode can be changed only in reset mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 30 of 35

3.5.10 TP810_IOCDISABLE_ LISTENONLY NAME TP810_IOCDISABLE_ LISTENONLY - Disable listen only mode DESCRIPTION This ioctl function disables the listen only facility of the SJA1000 CAN controller, which was before enabled with the ioctl command TP810_IOCENABLE_ LISTENONLY. The optional argument pointer can be omitted in this ioctl function. This ioctl command will be accepted only in reset mode (BUSOFF). Enter TP810_IOCBUSOFF first otherwise you will get an error (EACCES). EXAMPLE int fd; int result; result = ioctl(fd, TP810_DISABLE_LISTENONLY); if (result < 0) /* handle ioctl error */ ERRORS EACCES The CAN controller is in operating mode. This mode can be changed only in reset mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 31 of 35

3.5.11 TP810_IOCSSETLIMIT NAME TP810_IOCSSETLIMIT - Set new error warning limit DESCRIPTION This ioctl function sets a new error warning limit in the corresponding CAN controller register. The default value (after hardware reset) is 96. The new error warning limit will be set in an unsigned char variable. A pointer to this variable is passed by the argument pointer arg to the driver. This ioctl command will be accepted only in reset mode (BUSOFF). Enter TP810_IOCBUSOFF first otherwise you will get an error (EACCES). EXAMPLE int fd; int result; unsigned char limit; limit = 200; result = ioctl(fd, TP810_IOCSSETLIMIT, (char*)&limit); if (result < 0) /* handle ioctl error */ ERRORS EACCES The CAN controller is in operating mode. This mode can be changed only in reset mode. SEE ALSO SJA1000 Product Specification Manual 6.4.3 MODE REGISTER (MOD) TPMC810-SW-82 Linux Device Driver Page 32 of 35

3.6 Step by Step Driver Initialization The following code example illustrates all necessary steps to initialize a CAN device for communication. /* ** ( 1.) Setup CAN bus bit timing */ BitTimingParam.TimingValue = TP810_100KBIT; BitTimingParam.ThreeSamples = FALSE; result = ioctl(fd, TP810_IOCSBITTIMING, (char*)&bittimingparam); /* ** ( 2.) Setup acceptance filter masks */ AcceptFilter.AcceptanceCode = 0x0; AcceptFilter.AcceptanceMask = 0xFFFFFFFF; AcceptFilter.SingleFilter = 1; result = ioctl(fd, TP810_IOCSSETFILTER, (char*)&acceptfilter); /* ** ( 3.) Enter Bus On State */ result = ioctl(fd, TP810_IOCBUSON); Now you should be able to send and receive CAN messages with appropriate calls to write() and read() functions. TPMC810-SW-82 Linux Device Driver Page 33 of 35

4 Diagnostic If the TPMC810 does not work properly it is helpful to get some status information from the driver respective kernel. To get debug output from the driver enable the following symbols in tpmc810drv.c by replacing #undef with #define : #define DEBUG_TPMC810 #define DEBUG_TPMC810_INTR The Linux /proc file system provides information about kernel, resources, driver, devices and so on. The following screen dumps displays information of a correct running TPMC810 driver (see also the proc man pages). # cat /proc/pci Bus 0, device 15, function 0: Communication controller: PCI device 1498:032a (TEWS Datentechnik GmBH) (rev 0). IRQ 5. Non-prefetchable 32 bit memory at 0xcfffce80 [0xcfffceff]. I/O at 0xd400 [0xd47f]. Non-prefetchable 32 bit memory at 0xcfffcc00 [0xcfffcdff]. # cat /proc/interrupts CPU0 0: 1210564 XT-PIC timer 1: 6 XT-PIC keyboard 2: 0 XT-PIC cascade 5: 4051 XT-PIC usb-ohci, TPMC810 8: 1 XT-PIC rtc 10: 10358 XT-PIC usb-ohci, ehci-hcd, eth0 11: 0 XT-PIC usb-uhci, usb-uhci 12: 49 XT-PIC PS/2 Mouse 14: 29896 XT-PIC ide0 15: 8 XT-PIC ide1 NMI: 0 ERR: 0 TPMC810-SW-82 Linux Device Driver Page 34 of 35

# cat /proc/ioports 0000-001f : dma1 0020-003f : pic1 0040-005f : timer 0060-006f : keyboard 0070-007f : rtc d000-d01f : VIA Technologies, Inc. USB (#2) d000-d01f : usb-uhci d400-d47f : PCI device 1498:032a (TEWS Datentechnik GmBH) d800-d8ff : Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ d800-d8ff : 8139too dc00-dcff : Standard Microsystems Corp [SMC] 83C170QF ff00-ff0f : Silicon Integrated Systems [SiS] 5513 [IDE] ff00-ff07 : ide0 ff08-ff0f : ide1 # cat /proc/iomem 00000000-0009fbff : System RAM 0009fc00-0009ffff : reserved 000a0000-000bffff : Video RAM area 000c0000-000c7fff : Video ROM 000f0000-000fffff : System ROM 00100000-0ffeffff : System RAM 00100000-0025821d : Kernel code 0025821e-002d8243 : Kernel data cfffcb00-cfffcbff : VIA Technologies, Inc. USB 2.0 cfffcb00-cfffcbff : ehci-hcd cfffcc00-cfffcdff : PCI device 1498:032a (TEWS Datentechnik GmBH) cfffcc00-cfffcdff : TPMC810 cfffce80-cfffceff : PCI device 1498:032a (TEWS Datentechnik GmBH) cfffcf00-cfffcfff : Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ cfffcf00-cfffcfff : 8139too TPMC810-SW-82 Linux Device Driver Page 35 of 35