6 #include <native/task.h>
7 #include <native/timer.h>
8 #include <native/mutex.h>
15 RTIME timeblock
= 1e7
;
24 rt_mutex_acquire(&mutex
, TM_INFINITE
);
25 rt_printf("Low priority task locks semaphore\n");
26 rt_task_sleep(timeblock
*3);
27 rt_printf("Low priority task unlocks semaphore\n");
28 rt_mutex_release(&mutex
);
30 rt_printf(".....Low priority task ends\n");
35 rt_task_sleep(timeblock
*2);
37 for(i
= 0; i
<10; i
++){
38 rt_printf("Medium task running\n");
39 rt_timer_spin(timeblock
);
41 rt_printf(".....Medium priority task ends\n");
44 void t_high(void *arg
)
46 rt_task_sleep(timeblock
*3);
49 rt_printf("High priority task tries to locks semaphore\n");
50 rt_mutex_acquire(&mutex
, TM_INFINITE
);
51 rt_printf("High priority task locks semaphore\n");
52 rt_timer_spin(timeblock
*3);
53 rt_printf("High priority task unlocks semaphore\n");
54 rt_mutex_release(&mutex
);
56 rt_printf(".....High priority task ends\n");
59 int main(int argc
, char* argv
[])
61 /* Perform auto-init of rt_print buffers if the task doesn't do so */
62 rt_print_auto_init(1);
64 /* Avoids memory swapping for this program */
65 mlockall(MCL_CURRENT
| MCL_FUTURE
);
67 /* create the two tasks */
68 rt_task_create(&tl
, "t_low", 0, 49, 0);
69 rt_task_create(&tm
, "t_med", 0, 50, 0);
70 rt_task_create(&th
, "t_high", 0, 51, 0);
72 /* create semaphore and start in blocked mode */
73 rt_mutex_create(&mutex
, "mutex");
75 /* start the two tasks */
76 rt_task_start(&tl
, &t_low
, 0);
77 rt_task_start(&tm
, &t_med
, 0);
78 rt_task_start(&th
, &t_high
, 0);