The 9th Symposium on Accelerator &ience and Technology, Tsukuba, Japan 1993

Development of Device Drivers Embedded in Real Time OSfor SPring-S SR Control System
T.Masuda, S.Fujiwara, T.Nakamura, H.Takebe, and T.Wada
JAERI-RIKEN SPring-8 Project Team
SPring-8, Kamigori, Hyogo, 678-12, JAPANmasuda@rknaSO.riken.go.jp

We introduced LynxOS and HP-RT and wrote
LynxOS device drivers for some l/0 boards. We will
write HP-RT device drivers in the near future.

Abstract

A distributed computer system has been adopted forthe SPring-8 SR control system. For lower levelcomputers, we intend to adopt VMEbus computer
II. FEATURES OF THE REAL TIME OS
systems with the real time OS which are compliant
with POSIX.
A. LynxOS
For R&D study, we introduced LynxOS and wrote
device drivers for Digital Output(DO), DigitalLynxOS is a product of Lynx Real Time Systems Inc.
Input(DI) and Analog Input(AI) boards on VMEbus.
is one of the real time OS called "real time UNIX".
andThey were successfully operated with device drivers.
It provides us with a superior environment for softwaredevelopment of UNIX such as GUI (Graphical UserI. INTRODUCTIONInterface) based on X window system, standard network
system based on Ethernet and TCP /IP, and so on.
The control system of the SPring-8 storage ring (SR) Furthermore, it provides us with real time functions
is designed to have three levels of hierarchy such as such as preemption and priority-based task schedulingpresentation layer, processing layer and equipment which UNIX dose not have.
LynxOS is developed with emphasis on
layer. An open system based on international standardsand open system. It is binary levelstandardization
is preferable because of its expandability andUNIX SystemV R.3 and Source levelwithcompatible
layer,maintainability [1,2]. In the presentation
UNIX 4.3 BSD. As for the shell, inwithcompatible
OSUNIX
runningEngineering Work Stations(EWSs)
bash, csh and improved sh shells
supports
it2.1
versionprovidesUNIX
theselect
Toused.
areX-terminalanda merit of vender independence. In the processing as well as dlsh shell. Dlsh is its original shell.
LynxOS also complies with POSIX 1003.1 ,1003.4
layer, VMEbus computer systems are used.
The selecting criteria of an OS for VMEbus computer and 1003.4a. POSIX 1003.1 is a main part of POSIX. It
system are having real time features and being defines interface with application programs. POSIX
compliant with POSIX(Portable Operating Systerri 1003.4 and 1003.4al are extensions for real time feature
Interface for computer environment). POSIX is a and define interface with real time application
standard OS proposed by IEEE committee. Among such programs. Therefore users' programs on LynxOS areOS's, LynxOS and HP-RT are commercially available portable to other OS's which are compliant withPOSIX1003.1 and 1003.4.
candidates [3].
LynxOS supports many platforms such asGenerally speaking, there are two ways to accessprograms.
M68030/40, i860, M88K, SPARC and R3000.
application
i80386/486,
fromboards
1/0
and to control
One is the way with "shared memory", and the other The kernel is about 190KB. It is ROMable and can be
is with a "device driver". The merits of using shared used as an embedded system.
memory are faster access speed and easy realization.
However, using device driver is more preferable, B.HP-RT
because it has advantages as bellow.
• Hardware interrupt can be treated.
• Faster timer interruption can be treated.
• Application programs can be independent of aparticular hardware.

HP-RT, a product of Hewlett Packard Co., is basedon LynxOS. Its kernel is modified and tuned for PARISC. The main difference of it from LynxOS is thedevelopment environment. LynxOS provides us with alThe POSIX 1003.4 and 4a are currently drafts.

-79-

self-development environment, while HP-RT provides
a cross-development environment. Loading softwarefrom host system to target system requires much labor ofdevelopers.
When application programs aredeveloped, HP-RT must be accompanied by a particularhost system, HP9000 series 700 or 800. Although larger
initial cost is required, HP-UX provides us withsuperior development supporting tools such asSoftBench.

ill. DEVICE DRIVER DEVELOPMENT
Device drivers are embedded in the OS kernel andglue the kernel to devices such as VME I/0 boards.
Device drivers convert the commands from the kernel
into those the devices can understand, and vice versa.
A device driver is a collection of function routines
called "entry points" only through which the kernel
can access the driver.
A. Feature of the LynxOS device driver

Device drivers are embedded in the kernel. We
have to modify the configuration table file and reboot
the system to remake the kernel when a new device
driver are added. This process is called "staticloading" of the device driver. Static loading requires
much labor during the development. Therefore
powerful and useful functions called "dynamic loading"are provided for developers. Device drivers can belinked or unlinked to the kernel with some commands
from shelL AU things we need to do are merely todeclare the entry points in the form of specific structurein the device driver.
Neither to modify theconfiguration file nor to reboot the system are required.
There are no performance penalty. When thedevelopment is finished, the device drivers may beloaded statically.
Debugging tools for the development of device
drivers are poor. Before version 2.1, only the way to
debug device drivers is to print the information on
console with cprintf or kprintf functions . In version 2.1,
skdb(Simple Kernel level Debugger) debugger isprovided. We will test it though it seems that it dose
not have sufficient power.

A device driver contains eight entry points. The
names of entry points and their purposes are shown inC. Hardware Interruption
Table.l. Writing a device driver is to describe howeach entry point should react when the entry point is
We have implemented hardware interrupts fromaccessed from the kernel.
1/0 boards with the device drivers. All things wehave to do in the device driver are to describe an
Table 1. LynxOS device driver entry points and its"interrupt software handler" and to establish apurpose.
relation between the header address of "interrupt
software handler" and interrupt vector number which
is sent to CPU from the I/0 device which demands an
Entry Point
Purposeinterruption. The latter is implemented with a driver
service call related to the hardware interrupt
dispatches in the install entry point. This service callcalled when device is opened
open
has an interrupt vector number and address of ancalled when device is closed
close"interrupt software handler" as arguments. It is very
readcalled to read dataeasy to implement a hardware interrupt with thiswrite
called to write dataservice call.
selectsupport select system call
ioctl
device control
D. Some tests with developed device driver
installcalled to install major device
uninstallcalled to remove major device
We have developed LynxOS device drivers forthree types of VME boards. They are DO, DI (with nohardware interruption) and AI (with hardware
Many special library functions with C interface areinterruption). Generally speaking, since an AI board
provided for writing device drivers. They are called
has more functions than DilDO boards, making athe "driver service calls". These functions support
device driver for an AI board is more complex. We
dynamic memory allocation, 1 msec and 10 msec timer
developed a simple device driver for the AI board
interrupt, hardware interrupt dispatches, software
which supported the least functions we need. Allinterrupt, thread, semaphore, signal, DMA chain,etc.
developed device drivers work well, and support all
Device drivers can be written in C language.
functions we need.
We examined the processing time for analog data
B. Development Environment
acquisition with the developed device driver. The
conditions of these tests are using the AI board with-80-12bit ADC, 30 J..Lsec sampling rate, taking 64 samples Table 2. The processing time of the data acquisition
process and the loop process when they run at theper one read cycle and acquiring data from a fixedsame time. The numbers in the parenthesis arechannel.
processing times when they run alone.
The processing time were measured withgettimeofday system call which provides the current
system time with the resolution of 10 msec. As the data acquisition data acquisition looping processprocessing time to be measured is actually less than 10processmodemsec, we measured the average processing time
47.8 sec (24.8 sec) 45.8 sec (23.0 sec)polling
repeated 1000 or 10000 cycles.
H/W interrupt 53.0 sec (30.0 sec) 23.0 sec (23.0 sec)a) comparison between device access ways

IV. SUMMARY
We compared two different device access ways, byusing shared memory and by using a device driver.
We wrote and examined the LynxOS device
Both data acquisition modes were set to the polling drivers. We also intend to write those of HP-RT andmode In the polling mode, a flag which is set when 64 test their compatibility with LynxOS.
samplings are finished is always polled. One dataacquisition cycle by using shared memory included
V. REFERENCES
getting shared memory, setting the device operation,
reading the data and releasing shared memory. One
data acquisition cycle with a device driver included [1] T. Wada: "Design of the Control System for theSPring-8", RIKEN Accel.,Prog. Rep., 24, 202 (1990).
opening the device, setting the device operation,(2] T. Wada, T .Kumahara,H. Yonehara,H.Y oshikawa,reading the data and closing the device.
T.Masuda, and Wang Zhen: "Design of SPring-8
It took about 2.5 msec by using shared memory perControl System", Proceedings of the International
one data acquisition cycle and about 16.5 msec by using aConference on Accelerator and Large Experimental
device driver. In the case of using device driver, thePhysics Control Systems, KEK, Tsukuba, Japan,
overhead time for opening and closing device are very
November, 1991, pp. 151-153
large. The processing time required for setting andreading is about 2.5 msec. It is as fast as the processing [3] T.Masuda, T.Nakamura, T.Wada and Z.Wang:"The Real Time Operating System of Front-End
time by using shared memory.
Processors for the SPring-8", RIKEN Accel.,Prog.
Rep., 25, 240 (1991).
b) comparison between data acquisition modes
We compared two data acquisition modes, thepolling mode and the hardware interrupt mode. The
polling mode is described in a). In the hardwareinterrupt mode, an interrupt occurs when 64 samplings
are finished.
It took about 16.5 msec in the polling mode andabout 17 msec in the hardware interrupt mode per one
data acquisition cycle. It seems that there is a littleoverhead time to process the hardware interrupt.
We compared the influence on the other process
between data acquisition modes by polling mode andhardware interrupt mode. A data acquisition process
and another process, looping process, were run at thesame time. The data acquisition processes are the sameones as above.
The result is shown in Table.2. The time of dataacquisition process includes the time of opening thedevice, 10000 cycles of setting the board and reading
the data, and closing the device. It shows that dataacquisition in polling mode influences largely looping
process.

-81-