final commit
[des2015.git] / natanael / ex02 / ex02d.c
index f54ded3..a77e783 100644 (file)
@@ -11,24 +11,23 @@ RT_TASK demo_task;
 
 void demo(void *arg)
 {
-  sleep(1);
   RT_TASK *curtask;
   RT_TASK_INFO curtaskinfo;
   // Read system clock
   RTIME period = 1e9;
+  rt_task_sleep(period);
 
   // inquire current task
   curtask=rt_task_self();
   rt_task_inquire(curtask,&curtaskinfo);
 
   // determine the period
-  int num = * (int *)arg;
-  period*=num;
-  rt_task_set_periodic(NULL,TM_NOW,period);
+  int num = *(int *)arg;
+  period *= num;
+  rt_task_set_periodic(NULL, TM_NOW, period);
   
   while(1){
-         // print task name
-         rt_printf("Task name : %s - Period %d \n", curtaskinfo.name,num);
+         rt_printf("Task name: %s - Period %d\n", curtaskinfo.name, num);
          rt_task_wait_period(NULL);
   }
 }
@@ -39,34 +38,18 @@ int main(int argc, char* argv[])
   int i;
   int periods[3];
 
-  // Perform auto-init of rt_print buffers if the task doesn't do so
   rt_print_auto_init(1);
-
-  // Lock memory : avoid memory swapping for this program
-  mlockall(MCL_CURRENT|MCL_FUTURE);
-
+  mlockall(MCL_CURRENT | MCL_FUTURE);
   rt_printf("start task\n");
 
   for (i=0; i<3; i++)
   {
-         /*
-          * Arguments: &task,
-          *            name,
-          *            stack size (0=default),
-          *            priority,
-          *            mode (FPU, start suspended, ...)
-          */
-         sprintf(str,"hello-%d",i);
-         periods[i]=i+1;
+         sprintf(str, "hello-%d", i);
+         periods[i] = i + 1;
          rt_task_create(&demo_task, str, 0, 50, 0);
-         
-         /*
-          * Arguments: &task,
-          *            task function,
-          *            function argument
-          */
          rt_task_start(&demo_task, &demo, &periods[i]);
   }
+
   rt_printf("end program by CTRL-C\n");
   pause();
-}
\ No newline at end of file
+}