Tips

API

Although the API documentation of Xenomai is pretty good not all API functions are documented. An example of a not documented  function is rt_timer_read. To really find out which functions are available for Xenomai one has the look at the xenomai header files at :
E.g. rt_timer_read is declared in /usr/xenomai/include/native/timer.h .

Error handling

Xenomai uses the standard errors defined in the headers :
In the Xenomai API for each function is specified which specific errors are generated when an error happens. However the more general errors like passing the wrong value to a function are not specified by the API . Thus don't be surprised when you get an error code not specified in the API documentation.
By looking at the error code one can deal with each error seperately. However sometimes one just want the program to stop and print out the error. With the strerror function one can easily do that. The following example demonstrates this :
 
  #include <errno.h> 

...

/* send message */
retval = rt_task_send(&task_struct[1], &task_mcb , NULL, TM_INFINITE);

if (retval < 0 )
{
rt_printf("Sending error %d : %s\n",-retval,strerror(-retval));
} else {
rt_printf("taskOne sent message to taskTwo\n");
}

Note: often API's use the errno variable to pass the error code of a function, however Xenomai doesn't use that variable, but just returns the error code as the return value of the function call.

The rdtk real-time printing library

We do not use 'printf()' in xenomai realtime code because it uses Linux syscalls and therefore terribly slows down the real-time thread. Instead we use the 'rt_printf' command  from the rdtk real-time printing  library. This is a stand-alone real-time library for printf services. It is embedded into the Xenomai user space part but actually doesn't depend on any Xenomai service, just using the plain POSIX API. The librtprint API looks much like the printf(3) man page:
The basic idea of librdtk is to keep the print side as cheap as possible: no locks, no syscalls at all. Each thread that uses rt_printf & friends has its own local ring buffer. A central (per process) non-RT output thread takes care of forwarding the content of all thread ring buffers to the output streams. The message order is preserved loosely by a global sequence counter (arch-dependent CPU-wide or system-wide atomic_inc_return might be used in the future). The output thread uses periodic polling (default: 10 Hz) to avoid the need for special signalling mechanisms.
To start the non-RT output thread one always has to call the following at the beginning of a Xenomai programma :
rt_print_auto_init(1);
This performs auto-init of the rt_print buffers and start the non-RT output thread.