L4Re - L4 Runtime Environment
examples/libs/libirq/async_isr.c

libirq usage example using asynchronous ISR handler functionality.

/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
* economic rights: Technische Universit├Ąt Dresden (Germany)
*
* This file is part of TUD:OS and distributed under the terms of the
* GNU General Public License 2.
* Please see the COPYING-GPL-2 file for details.
*/
/*
* This example shall show how to use the libirq.
*/
#include <l4/irq/irq.h>
#include <l4/util/util.h>
#include <stdio.h>
enum { IRQ_NO = 17 };
static void isr_handler(void *data)
{
(void)data;
printf("Got IRQ %d\n", IRQ_NO);
}
int main(void)
{
const int seconds = 5;
l4irq_t *irqdesc;
if (!(irqdesc = l4irq_request(IRQ_NO, isr_handler, 0, 0xff, 0)))
{
printf("Requesting IRQ %d failed\n", IRQ_NO);
return 1;
}
printf("Attached to key IRQ %d\nPress keys now, will terminate in %d seconds\n",
IRQ_NO, seconds);
l4_sleep(seconds * 1000);
if (l4irq_release(irqdesc))
{
printf("Failed to release IRQ\n");
return 1;
}
printf("Bye\n");
return 0;
}