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.

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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

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

TIP610-SW-95 QNX-Neutrino Device Driver TIP610 16/20 Channel Digital I/O 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.

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

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

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

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

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

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

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

Shared Memory Memory mapped files

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.

OPTO32A 24 Input Bit, 8 Output Bit Optical Isolator Board

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

ECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University

ECEN 449 Microprocessor System Design. Review of C Programming

ECE 650 Systems Programming & Engineering. Spring 2018

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

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

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017

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

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

Lab 09 - Virtual Memory

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

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

Artisan Technology Group is your source for quality new and certified-used/pre-owned equipment

CSE 333 SECTION 3. POSIX I/O Functions

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

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

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

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

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

ICS-121. VxWORKS DEVICE DRIVER MANUAL

Page Which had internal designation P5

Advcan QNX Driver User Manual V1.02

File Systems: Consistency Issues

CSE 333 SECTION 3. POSIX I/O Functions

Operating systems. Lecture 9

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

Files. Eric McCreath

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

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

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

TPMC Digital Inputs/Outputs (Bit I/O) Version 2.0. User Manual. Issue February 2014

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

Linux Device Drivers Interrupt Requests

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

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

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

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

spwr_base & spwr_chan

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

Communication. Serial port programming

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

MaRTE OS Misc utilities

UNIX System Calls. Sys Calls versus Library Func

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

DIO-BM(PCI/C-PCI)Linux/RT GPH-2X72C. Bus Master Digital Input/Output Board Driver Software for Linux/RTLinux. Help for Linux.

CS240: Programming in C

Kernel Modules. Kartik Gopalan

Chapter 4. File Systems. Part 1

bytes per disk block (a block is usually called sector in the disk drive literature), sectors in each track, read/write heads, and cylinders (tracks).

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

System Calls & Signals. CS449 Spring 2016

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

Signal Example 1. Signal Example 2

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

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

Linux Kernel Modules & Device Drivers April 9, 2012

Release Notes CCURDSCC (WC-AD3224-DS)

DM6420 Driver for Linux User s Manual Version 2.01.xx

CLD SC58x CDC Library v.1.00 Users Guide Users Guide Revision For Use With Analog Devices ADSP-SC58x Series Processors. Closed Loop Design, LLC

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

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

Memory Mapping. Sarah Diesburg COP5641

MicroBlaze TFTP Server User Guide

PRINCIPLES OF OPERATING SYSTEMS

Memory System Case Studies Oct. 13, 2008

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

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

Operating Systems 2010/2011

FLICONV-API. Generated by Doxygen

MultiCom/MV 1.0. Comtrol RocketPort Guide. Copyright , Viewpoint Systems, Inc. All Rights Reserved

Pentium/Linux Memory System March 17, 2005

Transcription:

The Embedded I/O Company TPMC917-SW-82 Linux Device Driver 4 MB SRAM with Battery Backup and 4 Channel Serial Interface Version 1.0.x User Manual Issue 1.0.1 November 2006 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 Phone: +49-(0)4101-4058-0 25469 Halstenbek, Germany Fax: +49-(0)4101-4058-19 www.tews.com e-mail: info@tews.com TEWS TECHNOLOGIES LLC 9190 Double Diamond Parkway, Suite 127, Reno, NV 89521, USA www.tews.com Phone: +1 (775) 850 5830 Fax: +1 (775) 201 0347 e-mail: usasales@tews.com

TPMC917-SW-82 Linux Device Driver 4 MB SRAM with Battery Backup and 4 Channel Serial Interface 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.0 First Issue May 23, 2005 1.0.1 Installation section and Filelist modified, New Address TEWS LLC November 27, 2006 TPMC917-SW-82 - Linux Device Driver Page 2 of 31

Table of Contents 1 INTRODUCTION... 4 2 INSTALLATION... 5 2.1 Build and install the device driver...6 2.2 Uninstall the device driver...6 2.3 Install device driver into the running kernel...7 2.4 Remove device driver from the running kernel...8 2.5 Change Major Device Numbers...8 3 SERIAL DEVICE DRIVER PROGRAMMING... 9 3.1 Simple Programming example...9 3.2 ioctl()...10 3.2.1 TPMC917_IOCQ_BIST...11 4 SRAM DEVICE DRIVER PROGRAMMING... 14 4.1 Device Input/Output functions...14 4.1.1 open()...14 4.1.2 close()...16 4.1.3 mmap()...17 4.1.4 munmap()...19 4.1.5 ioctl()...21 4.1.5.1 TP917RAM_IOCG_GETMEMSIZE...23 4.1.5.2 TP917RAM_IOCX_READ...24 4.1.5.3 TP917RAM_IOCX_WRITE...26 4.1.5.4 TP917RAM_IOCQ_GETBATSTAT...28 4.1.5.5 TP917RAM_IOC_WAITBATLOW...29 5 DIAGNOSTIC... 30 TPMC917-SW-82 - Linux Device Driver Page 3 of 31

1 Introduction The TPMC917-SW-82 Linux Device Driver consists of a full-duplex serial driver and a custom SRAM device driver, which allow the operation of a TPMC917 PMC device on Linux (Kernel 2.4.x+ and 2.6.x+) operating systems. These two drivers are connected through a HAL (Hardware Abstraction Layer) driver. The TPMC917 Serial Device Driver is based on the standard Linux serial device driver and supports all standard terminal functions (TERMIOS). Supported features of Serial Device Driver (TPMC917-10 only): Baud rates up to 115.2kbaud Each channel has a 64 Byte transmit and receive hardware FIFO Programmable trigger level for transmit and receive FIFO. Hardware (RTS/CTS) and software flow control (XON/XOFF) direct controlled by the serial controller. The advantage of this feature is that the transmission of characters will immediately stop as soon as a complete character is transmitted and not when the transmit FIFO is empty for handshake under software control. This will greatly improve flow control reliability. Designed as Linux kernel module with dynamically loading. Supports shared IRQ s. Build on new style PCI driver layout Creates a TTY device ttytpmc917 and dial out device cuatpmc917 (Kernel 2.4.x only) with dynamically allocated or fixed major device numbers. DEVFS support for automatic device node creation Supported features of the SRAM Device Driver: Read variable sized data buffer from SRAM Write variable sized data buffer to SRAM map SRAM directly into user space monitor battery backup wait for backup battery level fall to low The TPMC917-SW-82 device driver supports the modules listed below: TPMC917-10 4 MB SRAM module with battery backup and (PMC) 4 channel RS232 TPMC917-20 4 MB SRAM module with battery backup (PMC) To get more information about the features and use of TPMC917 device it is recommended to read the manuals listed below. TPMC917 User manual TPMC917 Engineering Manual ST16C654 UART Hardware Manual TPMC917-SW-82 - Linux Device Driver Page 4 of 31

2 Installation The directory TPMC917-SW-82 on the distribution media contains the following files: TPMC917-SW-82-1.0.1.pdf TPMC917-SW-82-SRC.tar.gz Release.txt ChangeLog.txt This manual in PDF format GZIP compressed archive with driver source code Release information Release history The GZIP compressed archive TPMC917-SW-82-SRC.tar.gz contains the following files and directories: example/makefile example/tp917serexample.c example/tp917sersetspeed.c example/tp917ramexample.c example/tpmc917bist.c hal/ hal/makefile hal/tpmc917hal.c hal/tpmc917haldef.h hal/tpmc917def.h include/ include/tpxxxhwdep.c include/tpxxxhwdep.h include/tpmodule.h include/tpmodule.c ram/ ram/makefile ram/tpmc917ram.c ram/tpmc917ram.h ram/tpmc917ramdef.h ram/makenode serial/ serial/2.4.x serial/2.4.x/makefile serial/2.4.x/tpmc917serial.c serial/2.4.x/tpmc917serialdef.h serial/2.6.x serial/2.6.x/makefile serial/2.6.x/tpmc917serial.c serial/2.6.x/tpmc917serialdef.h serial/makenode tpmc917ram.h tpmc917.h Example application makefile Send and receive example application Speed configuration example application RAM access example application Example for using Built-In-Self-Test Hardware abstraction layer driver needed for all kernel versions HAL driver makefile HAL driver source file HAL driver private header file HAL driver public header file for Serial and Ram Hardware and kernel independent libraries low level hardware access functions source file Access functions header file Driver and kernel independent library header file Driver and kernel independent library source file RAM driver directory RAM driver makefile RAM driver source file RAM driver application header file RAM driver private header file Shell script to create RAM device nodes without DEVFS UART driver directory Kernel 2.4.x sources directory Serial driver makefile Serial driver source file Serial driver private header file Kernel 2.6.x sources directory Serial driver makefile Serial driver source file Serial driver private header file Shell script to create Serial device nodes without DEVFS RAM driver application header file Serial Driver header file In order to perform an installation, extract all files of the archive TPMC917-SW-82-SRC.tar.gz to the desired target directory. Login as root and change to the target directory Copy tpmc917.h and tpmc917ram.h to /lib/modules/<version>/build/include and /usr/include TPMC917-SW-82 - Linux Device Driver Page 5 of 31

2.1 Build and install the device driver Login as root Change to the hal/ target directory To create and install the HAL driver in the module directory /lib/modules/<version>/misc enter: # make install Change to the serial/<version> target directory To create and install the SERIAL driver in the module directory /lib/modules/<version>/misc enter: # make install For Linux kernel 2.6.x, there may be compiler warnings claiming some undefined tpmc917_hal_* symbols. These warnings are caused by the HAL driver, which is unknown during compilation of this SERIAL driver. The warnings can be ignored. Change to the ram/ target directory To create and install the RAM driver in the module directory /lib/modules/<version>/misc enter: # make install For Linux kernel 2.6.x, there may be compiler warnings claiming some undefined tpmc917_hal_* symbols. These warnings are caused by the HAL driver, which is unknown during compilation of this RAM driver. The warnings can be ignored. To update the kernel's module dependencies, enter the following command: # depmod -aq Some Linux distributions are using different declarations of the function remap_page_range with a differing number of parameters. If you get errors regarding this issue during compilation of tpmc917ram.c, change the corresponding macro definition (TP_USE_REMAP_4PARAMS) in this file. 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, change to the directories serial/2.4.x/, serial/2.6.x/, ram/ and hal/ and enter in each directory: # make uninstall TPMC917-SW-82 - Linux Device Driver Page 6 of 31

2.3 Install device driver into the running kernel SERIAL RAM modprobe registration callback 4. 5. 6. I/O modprobe HAL registration 2. 3. callback I/O PCI-Subsystem 7. 1. PNP Hardware To load the device drivers into the running kernel, login as root and execute one of the following commands. Both drivers will try to start the other remaining driver. # modprobe tpmc917ramdrv # modprobe tpmc917serialdrv 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 files makenode, which reside in Serial/ and Ram/ directory, to do this. If your kernel has enabled the device file system (devfs) then 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. Change to the directories Serial/ and Ram/ and enter in each directory: # sh makenode On success the device driver will create a minor device for each function found (serial channels and SRAM). The first serial channel on the first PMC module (TPMC917-10 only) can be accessed by device node /dev/ttystpmc917_0, the second channel by device node /dev/ttystpmc917_1 and so on. The first SRAM device node created is called /dev/tpmc917ram_0, a second device node will be named /dev/tpmc917ram_1 and so on. The assignment of device nodes to physical PMC modules depends on the search order of the PCI bus driver. TPMC917-SW-82 - Linux Device Driver Page 7 of 31

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 commands # modprobe r tpmc917ramdrv # modprobe r tpmc917serialdrv If your kernel has enabled devfs, all /dev/ttystpmc917_* and /dev/tpmc917ram_* 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 Device or resource busy and the driver will still remain in the system until you close all opened files and execute modprobe r again. 2.5 Change Major Device Numbers This paragraph is only for Linux kernels without DEVFS installed. The released TPMC917 driver (Serial + Ram) uses dynamic allocation of major device numbers. If this isn t suitable for the application it s possible to define a major number separately for the TTY and CUA driver as well as for the Ram driver. To change the major number for the Serial device driver, edit the file Serial/<version>/tpmc917serial.c, change the following symbols to appropriate values and enter make install to create a new driver. TPMC917_TTY_MAJOR TPMC917_CUA_MAJOR Defines the value for the terminal device. Valid numbers are in range between 0 and 255. A value of 0 means dynamic number allocation. Defines the value for the dial out device. Valid numbers are in range between 0 and 255. A value of 0 means dynamic number allocation. Example: #define TPMC917_TTY_MAJOR 122 #define TPMC917_CUA_MAJOR 123 To change the major number of the Ram device driver, edit the file Ram/tpmc917ramdef.h, change the following symbol to an appropriate value and enter make install to create a new driver. TPMC917_RAM_MAJOR Defines the value for the Ram device. Valid numbers are in range between 0 and 255. A value of 0 means dynamic number allocation. Be sure that the desired major number isn t used by other drivers. Please check /proc/devices to see which numbers are free. Keep in mind that it is necessary to create new device nodes if the major number for the TPMC917 driver has changed and the makenode script isn t used. TPMC917-SW-82 - Linux Device Driver Page 8 of 31

3 Serial Device Driver Programming The TPMC917 Serial Device Driver is loosely based on the standard Linux terminal driver. Due to this way of implementation the driver interface and functionality is compatible to the standard Linux terminal driver. Please refer to the TERMIOS man page and driver programming related man pages for more information about serial driver programming. 3.1 Simple Programming example This example program opens the first serial channel of a TPMC917-10 device for read/write. After the device is open, it writes a Hello World string to the device and receives up to 80 bytes from the serial channel. main() { int fd; int count; char buffer[81]; /* open the desired PMC device channel*/ fd = open( /dev/ttystpmc917_0, O_RDWR O_NOCTTY); if (fd < 0) exit(-1); /* write data to the certain channel */ count = write(fd, Hello World\n, 12); printf( %d bytes written\n, count); /* read up to 80 bytes from the device */ count = read(fd, buffer, 80) if (count < 0) { printf( read error\n ); } else { } buffer[count] = 0; printf( %d bytes read <%s>\n, count, buffer); } close(fd); The source files tpmc917example.c and tpmc917setspeed.c contains additional programming examples. TPMC917-SW-82 - Linux Device Driver Page 9 of 31

3.2 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 tpmc917.h: Value TPMC917_IOCQ_BIST Meaning Start Built-In-Self-Test See below for more detailed information on each control code. To use these TPMC917 specific control codes, the header file tpmc917.h must be included in the application. RETURNS On success, zero is returned. In 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 TPMC917 driver always returns standard Linux error codes. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 10 of 31

3.2.1 TPMC917_IOCQ_BIST NAME TPMC917_IOCQ_BIST Start Built-In-Self-Test DESCRIPTION The TPMC917 Serial driver supports a special IOCTL function for testing the module hardware and for system diagnostics. The optional argument can be omitted for this ioctl function. The functionality is called Built-In-Self-Test, or BIST. With BIST you can test each channel of all your modules separately. There are three different test classes. First is a line test, second an interrupt test and the last a data integrity test. All tests run with local channel loopback enabled, so you don t need an external cable connection. The line test contains a test of all modem lines, although some of them are not available on the connectors, as you can see RTS and CTS, DTR and DSR, OP1 and RI and finally OP2 and CD. Only the static states for both electrical levels are tested on each sender receiver line pair. TPMC917-SW-82 - Linux Device Driver Page 11 of 31

For testing interrupts the BIST transmits a test buffer with known data and size. All data should be received on the same channel during internal loopback. If not, there is an interrupt error. The buffer size is 1024 byte. The baud rate has to be set through the standard terminal IOCTL functions. The last test verifies received data to assert data integrity. EXAMPLE /* Start Built-In Selftest, */ result = ioctl(tty1, TPMC917_IOCQ_BIST, NULL); if (result) printf("error during Built-In Selftest <%d, 0x%08X>!\n", result, result); if (result < 0) { } printf("errno %d - %s\n", errno, strerror(errno)); else if (result > 0) { if (result & TPMC917_ERTSCTS) printf("rts/cts line broken!\n"); if (result & TPMC917_EDTRDSR) printf("dtr/dsr line broken!\n"); if (result & TPMC917_ERI) printf("op1/ri line broken!\n"); if (result & TPMC917_ECD) printf("op2/dcd line broken!\n"); if (result & TPMC917_EDATA) printf("data integrity test failed!\n"); }else printf("info: Port %s successfully tested.\n", DevName); TPMC917-SW-82 - Linux Device Driver Page 12 of 31

RETURNS If return value is >0 one of three tests failed. Use the following flags to get a detailed error description. TPMC917_ERTSCTS TPMC917_EDTRDSR TPMC917_ERI TPMC917_ECD TPMC917_EDATA If set RTS/CTS line broken. If set DTR/DSR line broken. If set OP1/RI line broken. If set OP2/CD line broken. Data integrity test failed. No correct transmission possible. ERRORS ETIME EAGAIN ERESTARTSYS A timeout occurred during wait, interrupts do not work correctly. Your task should never been blocked. Change it to use the Built-In-Self-Test. Interrupted by external signal. TPMC917-SW-82 - Linux Device Driver Page 13 of 31

4 SRAM Device Driver Programming The TPMC917 SRAM Device Driver provides read/write access to the onboard SRAM, maps the SRAM directly into user space and supplies battery monitoring facilities. 4.1 Device Input/Output functions This chapter describes the interface to the device driver I/O system. 4.1.1 open() NAME open() opens 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 has to be opened. This is a bit mask. 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 hcurrent;... hcurrent = open( /dev/tpmc917ram_0, O_RDWR);... RETURNS The usual return value from open is a non-negative integer file descriptor. In case of an error, a value of 1 is returned. The global variable errno contains the detailed error code. TPMC917-SW-82 - Linux Device Driver Page 14 of 31

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 TPMC917-SW-82 - Linux Device Driver Page 15 of 31

4.1.2 close() NAME close() closes a file descriptor. SYNOPSIS #include <unistd.h> int close ( int filedes ) DESCRIPTION The close function closes the file descriptor filedes. EXAMPLE int hcurrent;... if (close(hcurrent)!= 0) { * handle close error conditions */ } RETURNS The usual return value from close is 0. In 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 TPMC917-SW-82 - Linux Device Driver Page 16 of 31

4.1.3 mmap() NAME mmap() maps kernel memory into user space SYNOPSIS #include <sys/mman.h> void *mmap ( void *addr, size_t len, int prot, int flags, int filedes, off_t off ) DESCRIPTION The mmap() function establishes a mapping between a process' address space and a file or shared memory object. PARAMETERS addr len prot flags Specifies a preferred address where the memory should be mapped. If it is NULL, the address is determined automatically. Size of memory to be mapped (in bytes). Should be 0x400000 for TPMC917 (4 MB) to map all available memory. Describes which operations can be performed on the mapped memory. Should be PROT_READ PROT_WRITE to allow both read and write operations. Describes the mapping flags. Should be MAP_FILE MAP_SHARED. filedes File descriptor to RAM device previously opened by a call to open(). off Offset relative to the beginning of the memory section. Should be 0 to map all available memory. TPMC917-SW-82 - Linux Device Driver Page 17 of 31

EXAMPLE int hcurrent; unsigned char* psram; psram = mmap( NULL, /* preferred address */ 0x400000, /* size of memory to be mapped */ PROT_READ PROT_WRITE, /* memory protection */ MAP_FILE MAP_SHARED, /* flags */ hcurrent, /* file descriptor */ 0); /* offset */ if (psram == MAP_FAILED) { } /* handle error */ RETURNS The usual return value of mmap() is a pointer which can be used by the application to directly access the memory. In case of an error, MAP_FAILED is returned. The global variable errno contains the detailed error code. ERRORS Error codes may be returned by the I/O system during mmap. For more information about mmap error codes, please refer to the man page of mmap and the detailed description of Linux' memory management functions (mman). SEE ALSO GNU C Library description Low-Level Input/Output TPMC917-SW-82 - Linux Device Driver Page 18 of 31

4.1.4 munmap() NAME munmap() unmap pages of memory SYNOPSIS #include <sys/mman.h> int munmap ( void *addr, size_t len ) DESCRIPTION The munmap() function removes the mappings for pages in the specified range. PARAMETERS addr len Specifies the address returned by a previous call to mmap(). Size of memory mapped by a previous call to mmap(). EXAMPLE int hcurrent; int result; unsigned char* psram; result = munmap( psram, /* address returned by mmap() */ 0x400000); /* size of mapped memory */ if (result < 0) { } /* handle error */ RETURNS Upon successful completion, munmap() returns 0; otherwise, it returns -1. The global variable errno contains the detailed error code. TPMC917-SW-82 - Linux Device Driver Page 19 of 31

ERRORS EINVAL The specified arguments are invalid. Other error codes may be returned by the I/O system during munmap. SEE ALSO GNU C Library description Low-Level Input/Output TPMC917-SW-82 - Linux Device Driver Page 20 of 31

4.1.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 tpmc917ram.h: Value TP917RAM_IOCG_GETMEMSIZE TP917RAM_IOCX_READ TP917RAM_IOCX_WRITE TP917RAM_IOCQ_GETBATSTAT TP917RAM_IOC_WAITBATLOW Meaning Get size of TPMC917 onboard memory. Read from TPMC917 onboard memory. Write to TPMC917 onboard memory. Get state of TPMC917 onboard backup battery. Wait until the state of the backup battery falls to low. See below for more detailed information on each control code. To use these TPMC917 specific control codes the header file tpmc917ram.h must be included in the application. TPMC917-SW-82 - Linux Device Driver Page 21 of 31

RETURNS On success, zero is returned. In 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 TPMC917 RAM driver always returns standard Linux error codes. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 22 of 31

4.1.5.1 TP917RAM_IOCG_GETMEMSIZE NAME TP917RAM_IOCG_GETMEMSIZE Get size of TPMC917 onboard memory. DESCRIPTION This TPMC917 SRAM Ioctl function returns the SRAM s memory size located on the TPMC917 module. A pointer to an unsigned long value must be supplied to the device driver, where the size is returned. EXAMPLE #include tpmc917ram.h int hcurrent; int result; unsigned long MemorySize;... result = ioctl( hcurrent, TP917RAM_IOCG_GETMEMSIZE, &MemorySize ); if (result >= 0) { printf("\memory Size = %ld (0x%lX)\n", MemorySize, MemorySize); } else { } printf("\nget Memory Size failed --> Error = %d\n", errno); ERRORS EFAULT Invalid pointer to the parameter buffer. Please check the argument argp. All other returned error codes are system error conditions. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 23 of 31

4.1.5.2 TP917RAM_IOCX_READ NAME TP917RAM_IOCX_READ Read from TPMC917 onboard memory. DESCRIPTION This TPMC917 SRAM Ioctl function writes a dynamically adjustable data buffer into the onboard SRAM. No data verification is performed. The parameter argp passes a pointer to a TP917RAM_MEMIO_BUF structure to the device driver. The TP917RAM_MEMIO_BUF structure has the following layout: typedef struct { unsigned long unsigned long offset; size; unsigned char pdata[1]; /* dynamically expandable */ } TP917RAM_MEMIO_BUF; Members offset size pdata Specifies the offset relative to the beginning of the SRAM, from where the data is retrieved. The SRAM is treated like a linear contiguous memory block Specifies the number of bytes to read. The data buffer must be large enough to hold the amount of data. Specifies the data buffer, which can be dynamically enlarged. TPMC917-SW-82 - Linux Device Driver Page 24 of 31

EXAMPLE #include tpmc917ram.h int int unsigned long TP917RAM_MEMIO_BUF hcurrent; result; totalsize; *pmemiobuf; /* ** allocate enough memory and read 20 bytes from SRAM, Offset=0 */ totalsize = sizeof(tp917ram_memio_buf) + 20*sizeof(unsigned char); pmemiobuf = (TP917RAM_MEMIO_BUF*)malloc( totalsize ); memset( pmemiobuf, 0, totalsize ); pmemiobuf->size = 20; pmemiobuf->offset = 0; result = ioctl( hcurrent, TP917RAM_IOCX_READ, pmemiobuf ); if (result >= 0) { /* data successfully read */ printf( Data= %s \n, pmemiobuf->pdata ); } else { } printf("\nread from memory failed --> Error = %d\n", errno); ERRORS EFAULT Invalid pointer to the parameter buffer. Please check the argument argp. All other returned error codes are system error conditions. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 25 of 31

4.1.5.3 TP917RAM_IOCX_WRITE NAME TP917RAM_IOCX_WRITE Write to TPMC917 onboard memory. DESCRIPTION This TPMC917 SRAM Ioctl function writes a dynamically adjustable data buffer into the onboard SRAM. No data verification is performed. The parameter argp passes a pointer to a TP917RAM_MEMIO_BUF structure to the device driver. The TP917RAM_MEMIO_BUF structure has the following layout: typedef struct { unsigned long unsigned long offset; size; unsigned char pdata[1]; /* dynamically expandable */ } TP917RAM_MEMIO_BUF; Members offset size pdata Specifies the offset relative to the beginning of the SRAM, where the data is to be written. The SRAM is treated like a linear contiguous memory block Specifies the number of bytes to be written. The data buffer must be large enough to hold the amount of data. Specifies the data buffer, which can be dynamically enlarged. TPMC917-SW-82 - Linux Device Driver Page 26 of 31

EXAMPLE #include tpmc917ram.h int int unsigned long TP917RAM_MEMIO_BUF hcurrent; result; totalsize; *pmemiobuf; /* ** allocate enough memory and read 20 bytes from SRAM, Offset=0 */ totalsize = sizeof(tp917ram_memio_buf) + 20*sizeof(unsigned char); pmemiobuf = (TP917RAM_MEMIO_BUF*)malloc( totalsize ); memset( pmemiobuf, 0, totalsize ); pmemiobuf->size = 20; pmemiobuf->offset = 0; result = ioctl( hcurrent, TP917RAM_IOCX_READ, pmemiobuf ); if (result >= 0) { /* data successfully read */ printf( Data= %s \n, pmemiobuf->pdata ); } else { } printf("\nread from memory failed --> Error = %d\n", errno); ERRORS EFAULT Invalid pointer to the parameter buffer. Please check the argument argp. All other returned error codes are system error conditions. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 27 of 31

4.1.5.4 TP917RAM_IOCQ_GETBATSTAT NAME TP917RAM_IOCQ_GETBATSTAT Get size of TPMC917 onboard memory. DESCRIPTION This TPMC917 SRAM Ioctl function returns the state of the SRAM s battery backup. The parameter argp passes a pointer to an unsigned long value to the device driver. Possible returned values are TP917_BATTERY_LOW and TP917_BATTERY_OK (see tpmc917ram.h). EXAMPLE #include tpmc917ram.h int hcurrent; int result; unsigned long BatteryState; result = ioctl( hcurrent, TP917RAM_IOCQ_GETBATSTAT, &BatteryState ); if (result >= 0) { if (BatteryState == TP917_BATTERY_LOW) { printf( BATTERY LOW!!! \n ); } else { printf( Battery OK.\n ); } } else { printf("\nget Battery State failed --> Error = %d\n", errno); } ERRORS EFAULT Invalid pointer to the parameter buffer. Please check the argument argp. All other returned error codes are system error conditions. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 28 of 31

4.1.5.5 TP917RAM_IOC_WAITBATLOW NAME TP917RAM_IOC_WAITBATLOW Wait until the state of the backup battery falls to low. DESCRIPTION This TPMC917 SRAM Ioctl function waits indefinitely until the SRAM s battery backup state turns to low. No timeout can be specified, so this function should be called out of a dedicated battery monitoring thread. No additional parameter is necessary. EXAMPLE #include tpmc917ram.h int int hcurrent; result; result = ioctl( hcurrent, TP917RAM_IOC_WAITBATLOW, 0 ); if (result >= 0) { printf( BATTERY LOW!!! \n ); } else { printf("\nwait for Battery Low failed --> Error = %d\n", errno); } ERRORS All returned error codes are system error conditions. SEE ALSO ioctl man pages TPMC917-SW-82 - Linux Device Driver Page 29 of 31

5 Diagnostic If the TPMC917 driver does not work properly it is helpful to get some status information from the driver respective kernel. The Linux /proc file system provides information about kernel, resources, drivers, devices and so on. The following screen dumps display information of a correct running TPMC917 driver (see also the proc man pages). # cat /proc/modules tpmc917serialdrv tpmc917ramdrv tpmc917haldrv mousedev input parport_pc lp parport autofs 21964 0 (autoclean) (unused) 10128 0 (unused) 24108 0 [tpmc917serialdrv tpmc917ramdrv] 5428 1 (autoclean) 5792 0 (autoclean) [mousedev] 18756 1 (autoclean) 8868 0 (autoclean) 36480 1 (autoclean) [parport_pc lp] 12948 0 (autoclean) (unused) # cat /proc/tty/driver/tpmc917serial TEWS TECHNOLOGIES - TPMC917 UART driver (Kernel 2.4.x): 1.0.1 revision: 2006-11-28 0: uart:st16c654 port:e0897000 irq:5 tx:0 rx:0 1: uart:st16c654 port:e0897008 irq:5 tx:0 rx:0 2: uart:st16c654 port:e0897010 irq:5 tx:0 rx:0 3: uart:st16c654 port:e0897018 irq:5 tx:0 rx:0 4: uart:st16c654 port:e0899000 irq:11 tx:0 rx:0 5: uart:st16c654 port:e0899008 irq:11 tx:0 rx:0 6: uart:st16c654 port:e0899010 irq:11 tx:0 rx:0 7: uart:st16c654 port:e0899018 irq:11 tx:0 rx:0 # cat /proc/tty/drivers tpmc917serial /dev/cuatpmc917 252 0-127 serial:callout tpmc917serial /dev/ttytpmc917 253 0-127 serial serial /dev/cua 5 64-127 serial:callout serial /dev/ttys 4 64-127 serial pty_slave /dev/pts 143 0-255 pty:slave pty_master /dev/ptm 135 0-255 pty:master pty_slave /dev/pts 142 0-255 pty:slave pty_master /dev/ptm 134 0-255 pty:master pty_slave /dev/pts 141 0-255 pty:slave pty_master /dev/ptm 133 0-255 pty:master pty_slave /dev/pts 140 0-255 pty:slave pty_master /dev/ptm 132 0-255 pty:master pty_slave /dev/pts 139 0-255 pty:slave pty_master /dev/ptm 131 0-255 pty:master TPMC917-SW-82 - Linux Device Driver Page 30 of 31

pty_slave /dev/pts 138 0-255 pty:slave pty_master /dev/ptm 130 0-255 pty:master pty_slave /dev/pts 137 0-255 pty:slave pty_master /dev/ptm 129 0-255 pty:master pty_slave /dev/pts 136 0-255 pty:slave pty_master /dev/ptm 128 0-255 pty:master pty_slave /dev/ttyp 3 0-255 pty:slave pty_master /dev/pty 2 0-255 pty:master /dev/vc/0 /dev/vc/0 4 0 system:vtmaster /dev/ptmx /dev/ptmx 5 2 system /dev/console /dev/console 5 1 system:console /dev/tty /dev/tty 5 0 system:/dev/tty unknown /dev/vc/%d 4 1-63 console # cat /proc/interrupts CPU0 0: 151112 XT-PIC timer 1: 6 XT-PIC keyboard 2: 0 XT-PIC cascade 5: 0 XT-PIC TPMC917RAM, TPMC917, TPMC917, TPMC917, TPMC917 8: 1 XT-PIC rtc 11: 3475 XT-PIC eth0, TPMC917RAM, TPMC917, TPMC917, TPMC917, TPMC917 12: 47 XT-PIC PS/2 Mouse 14: 13085 XT-PIC ide0 15: 0 XT-PIC ide1 NMI: 0 ERR: 0 # lspci v... 00:0a.0 Class 0808: TEWS Datentechnik GmBH: Unknown device 0395 (rev 0a) Subsystem: TEWS Datentechnik GmBH: Unknown device 000a Flags: medium devsel, IRQ 5 Memory at eb823000 (32-bit, non-prefetchable) [size=128] Memory at eb000000 (32-bit, non-prefetchable) [size=4m] Memory at eb821000 (32-bit, non-prefetchable) [size=64] 00:0b.0 Class 0808: TEWS Datentechnik GmBH: Unknown device 0395 (rev 0a) Subsystem: TEWS Datentechnik GmBH: Unknown device 000a Flags: medium devsel, IRQ 11 Memory at eb822000 (32-bit, non-prefetchable) [size=128] Memory at eb400000 (32-bit, non-prefetchable) [size=4m] Memory at eb824000 (32-bit, non-prefetchable) [size=64] TPMC917-SW-82 - Linux Device Driver Page 31 of 31