RTLinux


RTLinux is a real-time operating system that runs Linux or FreeBSD as a task under the real-time kernel. It is developed and sold by Finite State Machine Labs and has the unique ability to act as a high-performance, predictable real-time operating system, while still allowing users to run the plethora of software available for the Linux operating system.


This means that an embedded systems developer can create drivers to monitor and control hardware with microsecond response times, while simultaneously running advanced software like web server and GUI window managers. RTLinux relies on the Linux system for accessing most resources like disk drives, networks, printers, and such. Only when you need real-time response speeds will you have to develop an RTLinux driver. Even then, a special two-part driver can be built in such a way that the real-time driver can pass events and messages to the Linux operating system, where more traditional software can process the information in a more lesuirely manner.


RTLinux runs standard Linux as a low-priority task under its real-time kernel. It also makes sure that the Linux kernel can always been interrupted if needed to handle quick real-time response needs. This opens the door for many new opportunities to use Linux for embedded systems, since Linux itself is not a real-time system with guarenteed response times to interrupts and other external events. It is available in an open-source, free version and a more polished, more capable Professional version.


RTLinux supports almost all Intel 386 processors, Alpha processors and the PowerPC processor. The Professional version also supports MIPS processors. It can be reduced down to fit on a single floppy disk, with Linux and a few applications thrown in for good measure. This small version will run in about 4 MB of RAM. The RTLinux response time is published as a worst-case of about 15 microseconds between the time an interrupt is presented to the CPU and the time it takes for the interrupt service routine to begin running. These figures are based on the Intel x86 processors. Alpha and PowerPC processors have slightly better figures. You should also note that the figure is a "worst-case" value. Typical response times are even better. Keep in mind though, it is the worst-case that you must worry about.


RTLinux is available in an open-source version licensed under the GPL scheme. There are no royalties or licensing fees needed to use either RTLinux or Linux itself. There is a more Professional version available that might require license fees however. Consult FSMLabs web site for more details.


There are several versions of RTLinux. One of them is called miniRTL and it is designed to fit on a single floppy disk and generally is used to support Intel processor running on PC-104 bus systems. It includes network support, via Ethernet, PPP or SLIP, and has telnet, SSH, and web server software built-in. An optional product call RtiC-Lab adds a graphical user interface designed for data collection and control of industrial equipment. RTLinux is a powerful and flexible option for any embedded systems with the power to run Linux.


Installing RTLinux


RTLinux expects to be installed into the /usr/src/rtlinux folder on a working Linux system by default. You can install it to other locations if desired. Follow this commands to install the software (after logging in as root):

  cd /usr/src
  tar xzvf <path>/rtlinux-3.0.tar.gz
  cd ..
  tar xzvf <path>/rtldoc-3.0.tar.gz

The next step is to patch the Linux kernel source code. This is required to make Linux work correctly under RTLinux. These changes to the original source code are very minimal, so future versions of the Linux kernel can still be easily supported. The patch files are specific to the revision level of Linux, therefore it is mandatory that you have the correct version of Linux installed. You will see a couple of files named "kernel_patch*" in the main directory where RTLinux was installed. Examine the beginning of the file to determine which Linux kernel source code you will need. The lines that start with VERSION, PATCHLEVEL and SUBLEVEL must match the kernel, or nothing will work.


Example:


  kernel_patch-2.2 file

  VERSION = 2
  PATCHLEVEL = 2
  SUBLEVEL = 18


This indicates that you must have the kernel for Linux version 2.2.18. Higher revisions will probably not work correctly. Visit http://www.kernel.org to download the correct Linux kernel. Once downloaded, the kernel should be installed under /usr/src/linux, either directly, or pointed to via a software link.


Next, you must ensure that you compiler is up to date. RTLinux requires gcc 2.7.2.3, egcs 1.1.2 or egcs 2.91. You can check this with the command 'gcc -v' or 'egcs -v'. Other versions may work, but are not tested by FSMLabs.


Now that you have both the Linux kernel source code and the RTLinux source code installed, you must patch the kernel with the one of the patch files supplied with RTLinux. For example:

  cd /usr/src/linux
  patch -p1 < ../rtlinux-3.0/kernel_patch-2.2

The patch applied above will change certain files in the kernel source code. Most of these changes involve modifying the interrupt handling functions in the Linux kernel to not expect a true hardware interrupt from the CPU, but instead to work with a software generated interrupt from the RTLinux micro-kernel instead. This means that RTLinux's kernel will receive all 'true' interrupts first and as needed will invoke Linux's interrupt handlers. This modification is what allows RTLinux to be considered a true 'real-time' operating system.


Next we must configure and build a new kernel. The steps are:

  cd /usr/src/linux
  make mrproper
  make menuconfig (or xconfig)
  make dep
  make bzImage
  make modules
  make modules_install

Now that the new kernel is built, you must set your system up to boot from the new kernel. Many people use the Linux Loader (LILO) to do this. The steps to boot from the new kernel using LILO are:


  cp /usr/src/linux/arch/<arch-type>/boot/bzImage /rtzImage
  vi /etc/lilo.conf

  Add the following to the lilo.conf file:

  image = /rtzImage
    label = RTLinux
    root = /dev/hda1 (or whatever is appropriate)
    read-only

Save the file and then issue the 'lilo' command to update the boot loader. Now you can reboot and select RTLinux at the LILO prompt, or from the LILO menu.


The next step is to build the RTLinux specific drivers and utilities you will require. Follow these steps:


  cd /usr/src/rtlinux-3.0 (or wherever you installed RTLinux)
  make menuconfig (or xconfig)
  make
  make devices
  make install

Once that is completed, you now have RTLinux installed on your system. You are now ready to begin creating software to work with your real-time operating system. Programming for RTLinux is very similar to programming a standard Linux program. Consult your Linux documentation and the RTLinux documentation for details on this.


RTLinux includes a number of sample applications to get you started. They can be found in the /usr/src/rtlinux-3.0/examples directory.

You may wish to download the sample project created in class by clicking on RTLproject1.tgz. Bob Linner, a student in class, has also made some improvements to the original project, which can also be downloaded by clicking on RTLproject1.1.tgz. Bob's improvements allow the original project to operate faster, primarily by slowing down the real-time counter, once the count reaches 1000. This then gives up some of the CPU time and allows the non-real-time reader program enough CPU cycles to operate correctly. The original version of the source code is found in the ".0" files after extracting the project from the tarball. Thanks Bob!