next up previous
Next: Sound with a pc-speaker: Up: Example programs on MiniRTL-V2.3 Previous: Example programs on MiniRTL-V2.3

''Hello World'': hello.o

One of the first C-programs to master is ''hello world'', a simple program that will print ''hello world'' on your screen. In the real-time linux world its not much different, this simple ''real-time hello world'' will write hello world from the rt-side to the non-rt-side of your running rtlinux box. To see the messages hello.o is writing to you, you must call the Linux command dmesg, which will print the kernel messages to stdout. This is because on the real-time side of your box you can't directly access the console, so hello.o drops a message to the linux kernel and that in turn prints it via printk.

hello.c close to the simples module possible, init_module, cleanup_module as with all modules, and start_routine, the actual task, which is only a periodic rtl_printk of a message and any arguments received. After inserting hello.o with insmod, simply execute dmesg, and it will talk to you.


#include <rtl.h>
#include <time.h>
#include <pthread.h>
pthread_t thread;

void * start_routine(void *arg)
{
   struct sched_param p;
   p . sched_priority = 1;
   pthread_setschedparam (pthread_self(), 
      SCHED_FIFO, &p);

   pthread_make_periodic_np (pthread_self(), 
      gethrtime(), 500000000);

   while (1) {
      pthread_wait_np ();
      rtl_printf("I'm here; my arg is %x\n", 
         (unsigned) arg);
   }
   return 0;
}

int init_module(void) {
   return pthread_create (&thread, NULL, 
      start_routine, 0);
}

void cleanup_module(void) {
   pthread_delete_np (thread);
}



Der Herr Hofrat
2002-03-08