update ex11
[des2015.git] / mart / xenomai / ex09 / ex09a2.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 RT_TASK dummy_task;
16
17 void dummy_task_function(void *arg)
18 {
19 int i;
20 while(1){
21 rt_task_sleep(1e7); //let linux system have time to kill the program
22 rt_printf("Dummy task spinning\n");
23 rt_timer_spin(1e9);
24 rt_printf("Dummy task stopped\n");
25 }
26 }
27
28 void keyboard_handler(void *arg)
29 {
30 RT_INTR intr;
31 RT_TASK *ctask;
32 RT_TASK_INFO ctaskinfo;
33 ctask = rt_task_self();
34 rt_intr_create(&intr, "keyboard handler", KBDIRQ, I_PROPAGATE);
35 int kps = 0;
36 while(1){
37 rt_printf("Kbd interrupts: %d\n", kps += rt_intr_wait(&intr, TM_INFINITE));
38 rt_task_inquire(ctask, &ctaskinfo);
39 rt_printf("Prio: %d\n", ctaskinfo.cprio);
40 }
41 }
42
43 int main(int argc, char* argv[])
44 {
45 rt_print_auto_init(1);
46
47 mlockall(MCL_CURRENT | MCL_FUTURE);
48
49 rt_task_create(&task, "task", 0, 50, 0);
50 rt_task_create(&dummy_task, "dummy_task", 0, 51, 0);
51
52 rt_task_start(&task, &keyboard_handler, 0);
53 rt_task_start(&dummy_task, &dummy_task_function, 0);
54
55 rt_printf("CRTL+C to stop\n");
56 pause();
57 }