0% found this document useful (0 votes)
78 views

Mirko Holler March 2000: Installation & Examples

The document provides instructions for installing RT-Linux 2.0 on a system with kernel version 2.2.13. It describes downloading the pre-patched kernel, unpacking and compiling it, installing modules, and configuring the system to boot the real-time kernel. It also provides examples of real-time programs using interrupts on the parallel port and writing/reading from a real-time FIFO.

Uploaded by

Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Mirko Holler March 2000: Installation & Examples

The document provides instructions for installing RT-Linux 2.0 on a system with kernel version 2.2.13. It describes downloading the pre-patched kernel, unpacking and compiling it, installing modules, and configuring the system to boot the real-time kernel. It also provides examples of real-time programs using interrupts on the parallel port and writing/reading from a real-time FIFO.

Uploaded by

Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Mirko Holler March 2000

Installation & Examples

Page 1 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

Installation (RTL Version 2.0, Kernel-Version 2.2.13):

0. make sure you have gcc 2.7.2.3 or egcs 1.1.2 (2.91) or later installed.

You can verify that with gcc -v.

RT-Linux installation.

You have downloaded the RTL distribution with a prepatched kernel.


(http://www.rtlinux.org)

1. Unpack the kernel-source


Copy the tar-archive to /usr/src/rtlinux-2.0-prepatched.tgz
Untar the archive: tar -xzvf /usr/src/rtlinux-2.0-prepatched.tgz
The directory /usr/src/rtlinux-2.0 will be created.
In this directory there is a directory called linux.
Create a symbolic link: /usr/src/linux -> /usr/src/rtlinux-2.0/linux
rm /usr/src/linux
ln -s /usr/src/rtlinux-2.0/linux /usr/src/linux

2. Go into the /usr/src/linux directory and create your kernel-configuration

make config
or
make menuconfig
or
make xconfig

Whatever you do, be sure to select the "hard real time" option in the
basic configuration (under "Processor type and features").

Also, please disable APM support (under "general setup").


APM BIOS calls may have unpredictable effect on real-time performance.
(run also the command "chkconfig --del apmd" to make sure that apmd will
not be started in any runlevel)

Page 2 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

3. Compile the kernel

make dep

make bzImage

4. Create and install the modules

make modules

make modules_install

6. Create the rtl-system-map (/boot/System.map-<ver>-rtl2.0)


(this will also copy the kernel to /boot/vmlinuz-2.2.13-rtl2.0)

make install

7. Edit your lilo-configuration to be able to boot the real-time kernel

for example:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
promt
timeout=50
default=rtlinux

image=/boot/vmlinuz-<normalversion>
label=linux
initrd=/boot/initrd-<normalversion>
read-only
root=/dev/<yourroot>

image=/boot/vmlinuz-2.2.13-rtl2.0
label=rtlinux
read-only
root=/dev/<yourroot>

run lilo:

/sbin/lilo

Page 3 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

8. Boot the real-time kernel

shutdown -r now

You can verify whether the rt-linux symbols are in the kernel

/sbin/ksyms –a | grep rt_

9. Now you can cd to the /usr/src/rtlinux-2.0/rtl/ directory and type

make
make install

this will install real-rtme modules (rtl_fifo.o, rtl_sched.o, ...),


the rtlinux man pages,
as well as some header-files (/usr/include/rtlinux/rtl_*.h)

Page 4 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

An Example Program - Interrupts

The following program will produce a periodic output of +5 V


on the parallel-port (pins 2 & 3).
It will listen on the acknowledge-line of the parallel-port (pin 10) and wait for an interrupt.
If an interrupt is generated, it will set the Voltage on pins 2 & 3 down to 0V.

parport.c
#include <rtl.h>
#include <rtl_sync.h>
#include <time.h>
#include <pthread.h>
#include <asm/io.h>
#include <linux/kd.h>

pthread_t thread;

unsigned int intr_handler(unsigned int irq, struct pt_regs *regs)


{

outb(0, 0x378);
interrupt handler
rtl_hard_enable_irq(7); pin2: 0V

return 0;
} If got an IRQ, re-enable IRQ

void * start_routine(void *arg)


{
struct sched_param p;
100 µs
p . sched_priority = 1; 10 kHz
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);

pthread_make_periodic_np (pthread_self(), gethrtime(), 100000); //ns

while (1)
{
pthread_wait_np();
outb(3, 0x378); periodic trigger
} pins 2 & 3: 5V
return 0;
}

Page 5 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

int init_module(void) {
int status;
rtl_irqstate_t f;

rtl_no_interrupts(f);

status = rtl_request_irq(7, intr_handler); // if IRQ-Handler is OK


rtl_printf("rtl_request_irq: %d\n", status); // this will output 0
// on your console.
/* enbable parallel port interrupt */
outb_p(inb_p(0x37A) | 0x10, 0x37A);

outb_p(inb_p(0x21) & (~0x80), 0x21);


outb_p(0x20, 0x20);

rtl_hard_enable_irq(7); init module


enables interrupt
rtl_restore_interrupts(f);

outb(0, 0x378); //set LPT-outputs to 0

return pthread_create (&thread, NULL, start_routine, 0);


}

void cleanup_module(void) {
rtl_free_irq(7); cleanup module
pthread_delete_np (thread); disable interrupt
}

Makefile
all: parport.o

include rtl.mk

clean:
rm -f *.o

Page 6 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

You can compile the program. It is necessary that the file rtl.mk is present in the directory,
where you have the source code.
(This file can be found in directory /usr/src/rtlinux-2.0/rtl/rtl.mk)

cp /usr/src/rtlinux-2.0/rtl/rtl.mk .
make

Two modules are necessary to be able to run this program (rtl_sched & rtl_time)
(of course you must have booted the real-time kernel). Execute as root:

modprobe rtl_sched

Verify that both modules are loaded:

lsmod

Run the program

insmod parport.o

Now you can connect pin 2 with pin 10


and measure the Voltage on pin 3.
You will see something like this on the scope:
IRQ response
100 µs time
trigger

We measured the following values:


Processor Average [µs] Maximum[µs]
Pentium II / 300 MHz 5 <10
486 DX2 / 66MHz 35 65

If you measure something like this, you should


produce other Interrupts, too. We started X and
Netscape to have a high system-load and caused
many Interrupts by moving the mouse.

Page 7 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

An Example Program - FIFO

The following program will write 1kB data-blocks into a realtime-fifo while another “normal”
linux-program will read the data from that fifo.

Here is the “write – program” which uses functions from rtlinux

fifo.c:

#include <rtl.h>
#include <rtl_sync.h>
#include <time.h>
#include <rtl_fifo.h>

#define BUFSIZE 1024


char buf[BUFSIZE];

pthread_t thread;

void * start_routine(void *arg)


{
struct sched_param p;

int status;

p . sched_priority = 1; 10 ms
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); 100 Hz
pthread_make_periodic_np (pthread_self(), gethrtime(), 10000000); //ns

while (1)
{
status = rtf_put(0, buf, 1024); //write as often as possible
if (status <= 0) //1 kB of data into rt_fifo
pthread_wait_np(); //if fifo is full: wait 10 ms
}
return 0;
}

int init_module(void) {

rtf_create(0, 1024*1024);

return pthread_create (&thread, NULL, start_routine, 0);


}

void cleanup_module(void) {

rtf_destroy(0);

pthread_delete_np (thread);
}

Page 8 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

Makefile:

all: fifo.o

include rtl.mk

clean:
rm -f *.o

Here is the “read – program” which uses normal linux functions

read.c

#include <stdio.h>
#include <fcntl.h>

#define BUFSIZE 1024

char buf[BUFSIZE];

int main()
{
int fd0;
int n, c, d;
c = d = 0;

if ((fd0 = open("/dev/rtf0", O_RDONLY)) < 0) { //if rtfifo not in


fprintf(stderr, "Error opening /dev/rtf0\n"); //use: exit
exit(1);
}
while ( 1 == 1) {
n = read(fd0, buf, BUFSIZE); //read 1kB from fifo
c++;
if (c == 10000){
printf("read 10000 * 1024 bytes from fifo - "); //if read 10000 *
c = 0; //1kB print it out
d++; //and count how often
printf("nr. %d\n", d);
}
}
}

Page 9 http://midas.psi.ch/rtlinux [email protected]


Mirko Holler March 2000

You can compile the write program. It is necessary that the file rtl.mk is present in the
directory, where you have the source code.
(This file can be found in directory /usr/src/rtlinux-2.0/rtl/rtl.mk)

cp /usr/src/rtlinux-2.0/rtl/rtl.mk .
make

Two modules are necessary to be able to run this program (rtl_time, rtl_sched, rtl_posixio,
rtl_fifo / of course you must have booted the real-time kernel). Execute as root:

modprobe rtl_fifo

Verify that all four modules are loaded:

lsmod

Compile the read program:

gcc –o read read.c

Now you can run both programs simultaneously:

insmod fifo.o
./read

Stop the time the program needs to fill and empty the fifo and calculate the transfer-rate.

We measured the following values:

Processor ; Memory MB/s

Pentium II / 300 MHz ; 64 MB 69


486 DX2 / 66MHz ; 32 MB 6.5

Stop the read program: Ctrl+c,


Stop the write program by: rmmod fifo

Other examples can be found in Directory /usr/src/rtlinux-2.0/rtl/examples – hopefully they work.


Check my homepage at http://midas.psi.ch/rtlinux for additional information.

Page 10 http://midas.psi.ch/rtlinux [email protected]

You might also like