Merge branch 'master' of github.com:dopefishh/des2015
[des2015.git] / mart / ex07 / ex07a.c
index 11eac9b..857f329 100644 (file)
@@ -1,5 +1,3 @@
-/* ex07a.c */
-
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
@@ -31,69 +29,70 @@ RT_SEM mysync;
 
 void demo(void *arg)
 {
-    RTIME starttime, runtime;
-    int num=*(int *)arg;
-    RT_TASK *curtask;
-    RT_TASK_INFO curtaskinfo;
+       RTIME starttime;
+       RTIME runtime;
+       int num = *(int *)arg;
+       RT_TASK *curtask;
+       RT_TASK_INFO curtaskinfo;
 
-    rt_printf("Task  : %d\n",num);
+       rt_printf("Task : %d\n", num);
 
-    rt_sem_p(&mysync,TM_INFINITE);
+       rt_sem_p(&mysync,TM_INFINITE);
 
-    // let the task run RUNTIME(=200) jiffies in steps of SPINTIME(=20) jiffies
-    runtime = 0;
-    while(runtime < EXECTIME) {
-      rt_timer_spin(SPINTIME*BASEPERIOD);  // spin cpu doing nothing
-      // note: rt_timer_spin function does not accept jiffies only nanoseconds
-      //       deviates from timing conventions throughout the Xenomai API
+       // let the task run RUNTIME(=200) jiffies in steps of SPINTIME(=20) jiffies
+       runtime = 0;
+       while(runtime < EXECTIME) {
+               rt_timer_spin(SPINTIME*BASEPERIOD);  // spin cpu doing nothing
+               // note: rt_timer_spin function does not accept jiffies only nanoseconds
+               //       deviates from timing conventions throughout the Xenomai API
 
-      runtime = runtime + SPINTIME;
+               runtime += SPINTIME;
 
-      rt_printf("Running Task  : %d  at time : %d\n",num,runtime);
-    }
-    rt_printf("End Task  : %d\n",num);
+               rt_printf("Running Task: %d at time: %d\n", num, runtime);
+       }
+       rt_printf("End Task: %d\n", num);
 }
 
 //startup code
 void startup()
 {
-  int i;
-  char  str[10] ;
-
-  // semaphore to sync task startup on
-  rt_sem_create(&mysync,"MySemaphore",0,S_FIFO);
-
-  // change to period mode because round robin does not work
-  // in one shot mode
-  rt_timer_set_mode(BASEPERIOD);// set tick period
-  for(i=0; i < NTASKS; i++) {
-    rt_printf("start task  : %d\n",i);
-    sprintf(str,"task%d",i);
-    rt_task_create(&demo_task[i], str, 0, 50, 0);
-    rt_task_start(&demo_task[i], &demo, &i);
-  }
-  rt_printf("wake up all tasks\n");
-  rt_sem_broadcast(&mysync);
+       int i;
+       char  str[10] ;
+
+       // semaphore to sync task startup on
+       rt_sem_create(&mysync, "MySemaphore", 0, S_FIFO);
+
+       // change to period mode because round robin does not work
+       // in one shot mode
+       rt_timer_set_mode(BASEPERIOD);// set tick period
+       for(i = 0; i < NTASKS; i++) {
+               rt_printf("start task: %d\n", i);
+               sprintf(str, "task%d", i);
+               rt_task_create(&demo_task[i], str, 0, 50, 0);
+               rt_task_start(&demo_task[i], &demo, &i);
+       }
+       rt_printf("wake up all tasks\n");
+       rt_sem_broadcast(&mysync);
 }
 
 void init_xenomai() {
-  /* Avoids memory swapping for this program */
-  mlockall(MCL_CURRENT|MCL_FUTURE);
+       /* Avoids memory swapping for this program */
+       mlockall(MCL_CURRENT | MCL_FUTURE);
 
-  /* Perform auto-init of rt_print buffers if the task doesn't do so */
-  rt_print_auto_init(1);
+       /* Perform auto-init of rt_print buffers if the task doesn't do so */
+       rt_print_auto_init(1);
 }
 
 int main(int argc, char* argv[])
 {
-  printf("\nType CTRL-C to end this program\n\n" );
+       printf("\nType CTRL-C to end this program\n\n" );
 
-  // code to set things to run xenomai
-  init_xenomai();
+       // code to set things to run xenomai
+       init_xenomai();
 
-  //startup code
-  startup();
+       //startup code
+       startup();
 
-  // wait for CTRL-c is typed to end the program
-  pause();
+       // wait for CTRL-c is typed to end the program
+       pause();
 }