next up previous
Next: Sharing Memory betweeen kerne, Up: Interrupts Previous: Soft-Interrupts

RTLinux sigaction

RTLinux basically runs as kernel space modules that spawn rt-threads, the RTLinux sigaction allows to couple user-space tasks to interrupt events, the handler is executed in realtime the main routine is non-rt though - this does allow a fairly simple coupling of events especially as you easily can share data between the sigaction handler and user-space (simple global variables will do in many cases).

Now on to an example of this. Your mouse interrupt may be different than the one shown here, to find the interrupt your mouse is using execute cat /proc/interrupts and replace the #define MOUSE_IRQ 12 by the number used by your mouse. The only header file you need to use RTLinux sigaction in your user-space application is the RTLinux_sigaction.h.


#include <stdio.h>
#include <rtlinux_signal.h>

#define MOUSE_IRQ 12  

void my_handler(int);
struct rtlinux_sigaction sig, oldsig;

scount is a global variable in this example - showing that you can share variables and thus data between the realtime handler and the non-realtime user-space application fairly easy. In the main routine itself we do no more than fill out the RTLinux sigaction structure pointing to our handler (see below).


int scount=0;

int main(void) 
{
  sig.sa_handler = my_handler;
  sig.sa_flags = RTLINUX_SA_PERIODIC;
  rtlinux_sigaction(MOUSE_IRQ, 
    &sig, 
    &oldsig);

After requesting the user to wiggle the mouse we sleep for a few seconds - in this time the interrupt service routine will be called on every mouse interrupt and will increment scount, note that your mouse will not work properly if you are running this from a graphics environment during this test, which is why we only do this for a few seconds here... Basically this is coupling a user-space application to a hardware interrupt but still we need to split between what is done in the signal handler which can be seen as a interrupt service routine, as the rtlinux sigaction directly coupled this handler to the hardware interrupt.


  printf("IRQ's pleas...\n");
  sleep(3); 
  
  sig.sa_handler = RTLINUX_SIG_IGN;
  rtlinux_sigaction(MOUSE_IRQ, 
    &sig,
    &oldsig);

To make your mouse functional again - the RTLinux sigaction handler is turned off again thus now the regular Linux handler will be called again, and the main routing of the user-space application continues - printing the number of received interrupts and exiting.


  
  printf("got %i mouse IRQ's\n",
    scount);

  return 0;
}

void my_handler(int argument)
{
  scount++;
}

next up previous
Next: Sharing Memory betweeen kerne, Up: Interrupts Previous: Soft-Interrupts
Der Herr Hofrat
2003-01-06