final commit
[des2015.git] / natanael / ex09 / ex09a1.c
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <sys/mman.h>
5 #include <native/intr.h>
6 #include <sys/io.h>
7 #include <native/task.h>
8
9 RT_INTR keypress;
10 RT_TASK key_isr;
11 #define KEYBOARD_IRQ 1
12
13 void key_handler(void *arg)
14 {
15 int count = 0;
16 int nr_interrupts_waiting;
17 while(1) {
18 rt_printf("%d\n",count++);
19 nr_interrupts_waiting = rt_intr_wait(&keypress,TM_INFINITE);
20 if (nr_interrupts_waiting>0)
21 {
22 }
23 }
24 }
25
26 //startup code
27 void startup()
28 {
29 rt_intr_create(&keypress, NULL, KEYBOARD_IRQ, I_PROPAGATE);
30
31 rt_task_create(&key_isr, NULL,0,50,0);
32 rt_task_start(&key_isr, &key_handler, NULL);
33 }
34
35 void init_xenomai() {
36 /* Avoids memory swapping for this program */
37 mlockall(MCL_CURRENT|MCL_FUTURE);
38
39 /* Perform auto-init of rt_print buffers if the task doesn't do so */
40 rt_print_auto_init(1);
41 }
42
43 int main(int argc, char* argv[])
44 {
45 printf("\nType CTRL-C to end this program\n\n" );
46
47 // code to set things to run xenomai
48 init_xenomai();
49
50 //startup code
51 startup();
52
53 // wait for CTRL-c is typed to end the program
54 pause();
55 }