update ex11
[des2015.git] / mart / ex09 / ex09a1.c
1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <sys/mman.h>
5
6 #include <native/task.h>
7 #include <native/timer.h>
8 #include <native/intr.h>
9
10 #include <rtdk.h>
11
12 #define KBDIRQ 1
13
14 RT_TASK task;
15
16 void keyboard_handler(void *arg)
17 {
18 RT_INTR intr;
19 rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
20 int kps = 0;
21 while(1){
22 rt_printf("#Kbd interrupt %d\n",
23 kps += rt_intr_wait(&intr, TM_INFINITE));
24 }
25 }
26
27 int main(int argc, char* argv[])
28 {
29 /* Perform auto-init of rt_print buffers if the task doesn't do so */
30 rt_print_auto_init(1);
31
32 /* Avoids memory swapping for this program */
33 mlockall(MCL_CURRENT | MCL_FUTURE);
34
35 rt_task_create(&task, "task", 0, 50, 0);
36 rt_task_start(&task, &keyboard_handler, 0);
37
38 rt_printf("CRTL+C to stop\n");
39 pause();
40 }