Push exercise 1 and 2
[des2015.git] / natanael / ex02 / ex02c.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 RT_TASK demo_task;
11
12 void demo(void *arg)
13 {
14 RT_TASK *curtask;
15 RT_TASK_INFO curtaskinfo;
16
17 // inquire current task
18 curtask=rt_task_self();
19 rt_task_inquire(curtask,&curtaskinfo);
20
21 // print task name
22 int num = * (int *)arg;
23 rt_printf("Task name : %s - Argument %d \n", curtaskinfo.name,num);
24 }
25
26 int main(int argc, char* argv[])
27 {
28 char str[10] ;
29 int i;
30
31 // Perform auto-init of rt_print buffers if the task doesn't do so
32 rt_print_auto_init(1);
33
34 // Lock memory : avoid memory swapping for this program
35 mlockall(MCL_CURRENT|MCL_FUTURE);
36
37 rt_printf("start task\n");
38
39 for (i=0; i<5; i++)
40 {
41 /*
42 * Arguments: &task,
43 * name,
44 * stack size (0=default),
45 * priority,
46 * mode (FPU, start suspended, ...)
47 */
48 sprintf(str,"hello-%d",i);
49 rt_task_create(&demo_task, str, 0, 50+i, 0);
50
51 /*
52 * Arguments: &task,
53 * task function,
54 * function argument
55 */
56 rt_task_start(&demo_task, &demo, &i);
57 }
58
59 }