[index]
[next]
Real-Time Linux Introduction
- Linux is a free Unix-like operating system that runs on a variety
of platforms, including PCs. Numerous Linux distributions such as
Red Hat, Debian and Mandrake bundle the Linux OS with tools, productivity
software, games, etc.
- The Linux scheduler, like that of other OSes such as Windows or MacOS, is
designed for best average response, so it feels fast and interactive
even when running many programs.
- However, it doesn't guarantee that any particular task will always
run by a given deadline. A task may be suspended for an arbitrarily
long time, for example while a Linux device driver services a disk
interrupt.
- Scheduling guarantees are offered by real-time operating
systems (RTOSes), such as QNX, LynxOS or VxWorks. RTOSes are typically
used for control or communications applications, not general purpose
computing.
- Linux has been adapted for real-time support. These adaptations
are termed "Real-Time Linux" (RT Linux).
- Numerous versions of RT Linux are available, free or commercial.
Two commonly available free RT Linux versions are
- the
Real-Time Application Interface (RTAI), developed
by the Milan Polytechnical University and available at www.aero.polimi.it/~rtai/
- RTL, developed by New Mexico Tech and now maintained by FSM Labs,
Inc., with a free version available at www.rtlinux.org.
- These RT Linux systems are patches to the basic Linux kernel
source code. Instructions for building an RT Linux system from a
the Linux source code are provided with these RT Linux
systems. Briefly the process involves setting up the basic Linux
system, getting the latest Linux kernel source code from www.kernel.org,
patching the kernel source code, and compiling the patched
kernel. More information on RT Linux in general is provided in [AEO].
- See www.isd.mel.nist.gov/projects/rtlinux
for more information.
This tutorial is composed of examples that begin with the simple
exection of a fixed-period task, and introduces other topics such as
multiple tasks of varying periods and priorities, interrupt service
routines, and communication and synchronization with non-realtime
processes. The source code is highly commented when new concepts are
introduced.
Examples are located in subdirectories, and the tutorial will proceed
with these:
-
The Basics -- what RT Linux is, how to set up and
compile real time programs
-
A Single Periodic Task -- demonstrates a single fixed-period task that toggles
the speaker at 1 kHz, also demonstrating how to read and write I/O
addresses
-
Two Periodic Tasks -- demonstrates two fixed-period tasks, one that toggles
the speaker at between 100 Hz and 10 kHz and another that sets the
frequency each second. The role of priorities is described.
-
A Variable-Period Task -- demonstrates a single variable-period task that
smoothly changes the speaker frequency between 1 kHz and 10 kHz. The
differences between periodic and variable execution are described.
-
FIFO Communication -- demonstrates the use of first-in, first-out queues
(FIFOs) to exchange data with a regular Linux process. The user enters
a frequency and the RT task acknowledges, then toggles the speaker at
that frequency.
-
Interrupt Service Routines -- demonstrates an interrupt service routine (ISR). The ISR
is attached to the parallel port interrupt, and increments and writes
a number to a FIFO each time the interrupt is triggered.
-
Shared Memory Communication -- demonstrates shared memory communication between an RT task
and a user-level Linux process.
-
Semaphores -- demonstrates how to use semaphores to ensure consistent
access to shared data structures.
-
RC Airplane Servomotor Control -- demonstrates the control of two RC airplane servo motors using
two variable-period tasks. Through a FIFO a user process can set
the position and speed of each motor indepedently.
-
LED Wand Clock -- demonstrates an LED wand clock using many of the concepts
previously introduced: two tasks, an ISR, and FIFOs.
-
Determining Stack Size -- demonstrates how to estimate the stack size for a task.
-
Measuring Timing Jitter -- demonstrates how to read the Pentium time stamp counter
and measure the timing jitter for a periodic task.
-
Floating Point in RT Tasks --
demonstrates how to use floating point in real-time tasks and ensure
that the floating point unit context is saved and restored
Supplementary Material:
To build the tutorial, do the following in the top-level directory:
./configure
make
make install
To run the examples, change into the appropriate subdirectory and
execute the 'run' script, e.g.,
cd ex01_periodic
./run
No approval or endorsement of any commercial product by the National
Institute of Standards and Technology is intended or implied. Certain
commercial equipment, instruments, or materials are identified in this
report in order to facilitate understanding. Such identification does
not imply recommendation or endorsement by the National Institute of
Standards and Technology, nor does it imply that the materials or
equipment identified are necessarily the best available for the
purpose.
This publication was prepared by United States Government employees as
part of their official duties and is, therefore, a work of the
U.S. Government and not subject to copyright.
Contact:
Fred Proctor
Group Leader, Control Systems Group
National Institute of Standards and Technology
100 Bureau Drive, Stop 8230
Gaithersburg, MD 20899-8230
frederick.proctor@nist.gov
Next: The Basics of Real-Time Linux
Last modified: 11-Jan-2006