]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/examples/libs/libirq/async_isr.c
ef53d86d8940564670fd76533838efc90144d9a3
[l4.git] / l4 / pkg / examples / libs / libirq / async_isr.c
1 /*
2  * (c) 2008-2009 Technische Universität Dresden
3  * This file is part of TUD:OS and distributed under the terms of the
4  * GNU General Public License 2.
5  * Please see the COPYING-GPL-2 file for details.
6  */
7 /*
8  * This example shall show how to use the libirq.
9  */
10
11 #include <l4/irq/irq.h>
12 #include <l4/util/util.h>
13
14 #include <stdio.h>
15
16 enum { IRQ_NO = 17 };
17
18 static void isr_handler(void *data)
19 {
20   (void)data;
21   printf("Got IRQ %d\n", IRQ_NO);
22 }
23
24 int main(void)
25 {
26   const int seconds = 5;
27   l4irq_t *irqdesc;
28
29   if (!(irqdesc = l4irq_request(IRQ_NO, isr_handler, 0, 0xff, 0)))
30     {
31       printf("Requesting IRQ %d failed\n", IRQ_NO);
32       return 1;
33     }
34
35   printf("Attached to key IRQ %d\nPress keys now, will terminate in %d seconds\n",
36          IRQ_NO, seconds);
37
38   l4_sleep(seconds * 1000);
39
40   if (l4irq_release(irqdesc))
41     {
42       printf("Failed to release IRQ\n");
43       return 1;
44     }
45
46   printf("Bye\n");
47   return 0;
48 }