Recently I've been trying to grok Real Time Application Interface (more on www.rtai.org). It certainly wasn't a walk in the park, but still far far easier than RTLinux. This time at least I had a clue what was going on. Following this tutorial worked for me:#include <pthread.h> #include <sys/mman.h> // delay in nanoseconds
http://qrtailab.sourceforge.net/rtai_installation.html
.
Finally when everything is set up you can do:
sudo start_rtai
on command line. This starts RTAI.
Now for some programming. Here's a snippet:
/* led1.c, an LXRT LED blinker */
#include <rtai_lxrt.h>
#define TICKS 500000000 main()
{RT_TASK *task; int priority = 0, i; int stack_size = 4096;
int msg_size = 0; // use default
// get enough privilege to
// access the I/O ports.
iopl(3);
task = rt_task_init(nam2num("main"), priority, stack_size, msg_size);
if(task == 0)
{
printf("Task could not be initialized. Are you root?");
exit(1);
}
rt_set_oneshot_mode();
start_rt_timer(0);
mlockall(MCL_CURRENT
To compile this program it's necessary to run:
CFLAGS=$(rtai-config --lxrt-cflags
LDFLAGS=$(rtai-config --lxrt-ldflags
gcc $(CFLAGS) $(LDFLAGS) main.c -o blinker
Where main.c is the name of the source file and blinker is the name of output executable.
To run it you should write
sudo ./blinker
. Sudo is needed because of the direct hardware access. You should see that the leds hooked up to lpt port are blinking.
0 comments:
Post a Comment