fdd2f28f0bc1fb44b7687b34e4f1281cbf0f69e5
[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 keypresses = 0;
21 while(1){
22 rt_printf("#Keypresses: %d\n", keypresses += rt_intr_wait(&intr, TM_INFINITE));
23 }
24 }
25
26 int main(int argc, char* argv[])
27 {
28 /* Perform auto-init of rt_print buffers if the task doesn't do so */
29 rt_print_auto_init(1);
30
31 /* Avoids memory swapping for this program */
32 mlockall(MCL_CURRENT | MCL_FUTURE);
33
34 rt_task_create(&task, "task", 0, 50, 0);
35 rt_task_start(&task, &keyboard_handler, 0);
36
37 rt_printf("CRTL+C to stop\n");
38 pause();
39 }