Next Previous Contents

5. Compiling and Executing

In order to execute the program, hello.c, (after booting rtlinux, ofcourse) you must do the following :

  1. 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'.
         include rtl.mk
         all: hello.o
         clean:
             rm -f *.o
         hello.o: hello.c
             $(CC) ${INCLUDE} ${CFLAGS} -c hello.c
    
  2. 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.
  3. For compiling the code, use the command 'make'.
            $ make 
    
  4. 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).
            $ rtlinux start hello
    

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:

        $ dmesg

To stop the program, you need to remove it from the kernel. To do so, type:

        $ rtlinux stop hello

Alternate ways for inserting and removing the module is to use insmod and rmmod respectively.

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!

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() :

        struct sched_param p;
        p . sched_priority = 1;
        pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);

Next Previous Contents

Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:57:46