Push exercise 1 and 2
[des2015.git] / natanael / ex01 / ex01b.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
9 #include <rtdk.h>
10 #include <errno.h>
11 RT_TASK demo_task;
12
13 void demo(void *arg)
14 {
15 RT_TASK *curtask;
16 RT_TASK_INFO curtaskinfo;
17 int retval;
18
19 // hello world
20 rt_printf("Hello World!\n");
21
22 // inquire current task
23 // below is commented and makes error
24 // curtask=rt_task_self();
25 retval = rt_task_inquire(curtask,&curtaskinfo);
26
27 /* send error message */
28 if (retval < 0 )
29 {
30 rt_printf("Sending error %d : %s\n",-retval,strerror(-retval));
31 } else {
32 rt_printf("taskOne sent message to taskTwo\n");
33 }
34
35 // print task name
36 rt_printf("Task name : %s \n", curtaskinfo.name);
37
38 }
39
40 int main(int argc, char* argv[])
41 {
42 char str[10] ;
43
44 // Perform auto-init of rt_print buffers if the task doesn't do so
45 rt_print_auto_init(1);
46
47 // Lock memory : avoid memory swapping for this program
48 mlockall(MCL_CURRENT|MCL_FUTURE);
49
50 rt_printf("start task\n");
51
52 /*
53 * Arguments: &task,
54 * name,
55 * stack size (0=default),
56 * priority,
57 * mode (FPU, start suspended, ...)
58 */
59 sprintf(str,"hello");
60 rt_task_create(&demo_task, str, 0, 50, 0);
61
62 /*
63 * Arguments: &task,
64 * task function,
65 * function argument
66 */
67 rt_task_start(&demo_task, &demo, 0);
68 }