X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mart%2Fex07%2Fex07a.c;h=857f329aa9f1fa1ac3305947e34121d23d950841;hb=684df3dff41d6b109bf1733ac75c347f27afa464;hp=11eac9b26e65b7fbee527241622fe8b2d44feec3;hpb=6112e32082df65a2852fe3cc11b87d7bc0816fe2;p=des2015.git diff --git a/mart/ex07/ex07a.c b/mart/ex07/ex07a.c index 11eac9b..857f329 100644 --- a/mart/ex07/ex07a.c +++ b/mart/ex07/ex07a.c @@ -1,5 +1,3 @@ -/* ex07a.c */ - #include #include #include @@ -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(); }