94 lines
2.9 KiB
HTML
94 lines
2.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE>RTLinux HOWTO: Compiling and Executing </TITLE>
|
|
<LINK HREF="RTLinux-HOWTO-6.html" REL=next>
|
|
<LINK HREF="RTLinux-HOWTO-4.html" REL=previous>
|
|
<LINK HREF="RTLinux-HOWTO.html#toc5" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="RTLinux-HOWTO-6.html">Next</A>
|
|
<A HREF="RTLinux-HOWTO-4.html">Previous</A>
|
|
<A HREF="RTLinux-HOWTO.html#toc5">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s5">5. Compiling and Executing </A></H2>
|
|
|
|
<P>In order to execute the program, hello.c, (after booting rtlinux, ofcourse)
|
|
you must do the following :
|
|
<P>
|
|
<OL>
|
|
<LI>Compile the source code and create a module using the GCC compiler.
|
|
To simplify things, however, it is better to create a Makefile. Then you only need
|
|
to type 'make' to compile the code.
|
|
|
|
Makefile can be created by typing in the following lines in a file named 'Makefile'.
|
|
|
|
<PRE>
|
|
include rtl.mk
|
|
all: hello.o
|
|
clean:
|
|
rm -f *.o
|
|
hello.o: hello.c
|
|
$(CC) ${INCLUDE} ${CFLAGS} -c hello.c
|
|
</PRE>
|
|
|
|
</LI>
|
|
<LI>Locate and copy the rtl.mk file into the same directory as your hello.c and Makefile.
|
|
The rtl.mk file is an include file which contains
|
|
all the flags needed to compile the code. You can copy it from the RTLinux source
|
|
tree and place it alongside of the hello.c file.</LI>
|
|
<LI>For compiling the code, use the command 'make'.
|
|
|
|
<PRE>
|
|
$ make
|
|
</PRE>
|
|
|
|
</LI>
|
|
<LI>The resulting object binary must be inserted into the kernel, where it will be executed by
|
|
RTLinux. Use the command 'rtlinux' (you need to be the 'root' to do so).
|
|
|
|
<PRE>
|
|
$ rtlinux start hello
|
|
</PRE>
|
|
|
|
</LI>
|
|
</OL>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>You should now be able to see your hello.o program printing its message
|
|
every second. Depending on the configuration of your machine, you should
|
|
either be able to see it directly in your console, or by typing:
|
|
<P>
|
|
<PRE>
|
|
$ dmesg
|
|
</PRE>
|
|
<P>To stop the program, you need to remove it from the kernel. To do so, type:
|
|
<P>
|
|
<PRE>
|
|
$ rtlinux stop hello
|
|
</PRE>
|
|
<P>Alternate ways for inserting and removing the module is to use <EM>insmod</EM>
|
|
and <EM>rmmod</EM> respectively.
|
|
<P>
|
|
<P>Here, we have made our example program too simple. Contrary to what we have
|
|
seen, there may be multiple threads in a program. Priority can be set at thread
|
|
creation or modified later. Also, we can select the scheduling algorithm that
|
|
should be used. In fact, we can write our own scheduling algorithms!
|
|
<P>
|
|
<P>In our example, we can set priority of the thread as 1, and select FIFO scheduling
|
|
by inserting the following lines in the beginning of the function, thread_code() :
|
|
<P>
|
|
<PRE>
|
|
struct sched_param p;
|
|
p . sched_priority = 1;
|
|
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
|
|
</PRE>
|
|
<HR>
|
|
<A HREF="RTLinux-HOWTO-6.html">Next</A>
|
|
<A HREF="RTLinux-HOWTO-4.html">Previous</A>
|
|
<A HREF="RTLinux-HOWTO.html#toc5">Contents</A>
|
|
</BODY>
|
|
</HTML>
|