6 #include <native/task.h>
7 #include <native/timer.h>
8 #include <native/sem.h>
15 #define BASEPERIOD 0 // baseperiod 0 to get ns
17 #define EXECTIME 2e8 // execution time in ns
18 #define SPINTIME 1e7 // spin time in ns
20 RT_TASK demo_task
[NTASKS
];
27 int num
= *(int *)arg
;
29 RT_TASK_INFO curtaskinfo
;
31 rt_printf("Task: %d\n", num
);
33 rt_sem_p(&mysync
, TM_INFINITE
);
36 while(runtime
< EXECTIME
) {
37 rt_timer_spin(SPINTIME
); // spin cpu doing nothing
38 runtime
= runtime
+ SPINTIME
;
39 rt_printf("Running Task: %d at ms: %d\n", num
, runtime
/1000000);
41 rt_printf("End Task: %d\n", num
);
50 // semaphore to sync task startup on
51 rt_sem_create(&mysync
, "MySemaphore", 0, S_FIFO
);
54 rt_timer_set_mode(BASEPERIOD
);
56 for(i
= 0; i
< NTASKS
; i
++) {
57 rt_printf("start task: %d\n",i
);
58 sprintf(str
,"task%d",i
);
59 rt_task_create(&demo_task
[i
], str
, 0, i
== 1 ? 52 : 50+i
, 0);
60 rt_task_start(&demo_task
[i
], &demo
, &i
);
63 rt_printf("wake up all tasks\n");
64 rt_sem_broadcast(&mysync
);
68 /* Avoids memory swapping for this program */
69 mlockall(MCL_CURRENT
|MCL_FUTURE
);
71 /* Perform auto-init of rt_print buffers if the task doesn't do so */
72 rt_print_auto_init(1);
75 int main(int argc
, char* argv
[])
77 printf("\nType CTRL-C to end this program\n\n" );
79 // code to set things to run xenomai
85 // wait for CTRL-c is typed to end the program