void demo(void *arg) { //Round Robin rt_task_set_mode(0,T_RRB,NULL); rt_task_slice(NULL,15); //time slice in jiffies RTIME starttime, runtime; int num=*(int *)arg; RT_TASK *curtask; RT_TASK_INFO curtaskinfo; rt_printf("Task : %d\n",num); 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 runtime = runtime + SPINTIME; rt_printf("Running Task : %d at time : %d\n",num,runtime); } rt_printf("End Task : %d\n",num); }
void busy_wait_ms(unsigned long delay){ unsigned long count = 0; while (count <= delay*10){ rt_timer_spin(1000*100); count++; } }
void prioHigh(void *arg){ int err = 0; rt_task_sleep(WAIT); int i = 0; while(i<3) { rt_printf("High priority task tries to lock semaphore\n"); err = rt_sem_p(&mysync,TM_INFINITE); if(err < 0) rt_printf("Failed pending semaphore; error: %d: %s", err, strerror(-err)); err = 0; rt_printf("High priority task locks semaphore\n"); rt_timer_spin(SPINTIME); // spin cpu doing nothing i++; rt_printf("High priority task unlocks semaphore\n"); err = rt_sem_v(&mysync); if(err < 0) rt_printf("Failed signaling semaphore; error: %d: %s", err, strerror(-err)); err = 0; } rt_printf("..........................................High priority task ends\n"); }
void demo(void *arg) { RTIME starttime, runtime; int num=*(int *)arg; RT_TASK *curtask; RT_TASK_INFO curtaskinfo; curtask=rt_task_self(); rt_printf("Task : %d\n",num); rt_sem_p(&mysync,TM_INFINITE); runtime = 0; while(runtime < EXECTIME) { rt_timer_spin(SPINTIME); // spin cpu doing nothing runtime = runtime + SPINTIME; rt_printf("Running Task : %d at ms : %d\n",num,runtime/1000000); if(runtime == (EXECTIME/2)){ if(num == 2){ rt_task_set_priority(&demo_task[1],MID+10); rt_task_set_priority(&demo_task[0],LOW+10); } } } rt_printf("End Task : %d\n",num); }
void dummy_task(void *arg) { while(1) { rt_printf("Sleeping\n"); rt_task_sleep(2e9); rt_printf("Spinning\n"); rt_timer_spin(3e9); } }
void RT::OS::sleepTimestep(RT::OS::Task task) { xenomai_task_t *t = reinterpret_cast<xenomai_task_t *>(task); // Prevent significant early wake up from happening and drying the Linux system rt_task_sleep_until(t->next_t - t->wakeup_t); // Busy sleep until ready for the next cycle rt_timer_spin(rt_timer_ticks2ns(t->next_t - rt_timer_read())); // Update next interrupt time t->next_t += t->period; }
void prioMid(void *arg){ RTIME runtime; rt_task_sleep(WAIT); runtime = 0; while(runtime < EXECTIMEMID) { rt_timer_spin(SPINTIME); // spin cpu doing nothing runtime = runtime + SPINTIME; rt_printf("Medium task running\n"); } rt_printf("..........................................Medium priority task ends\n"); }
void demo(void *arg) { RTIME starttime, runtime; int num=*(int *)arg; RT_TASK *curtask; RT_TASK_INFO curtaskinfo; rt_printf("Task : %d\n",num); rt_sem_p(&mysync,TM_INFINITE); runtime = 0; while(runtime < EXECTIME) { rt_timer_spin(SPINTIME); // spin cpu doing nothing runtime = runtime + SPINTIME; rt_printf("Running Task : %d at ms : %d\n",num,runtime/1000000); } rt_printf("End Task : %d\n",num); }
void prioLow(void *arg) { int err = 0; RTIME runtime; runtime = 0; while(runtime < EXECTIMELOW) { err = rt_sem_p(&mysync,TM_INFINITE); if(err < 0) rt_printf("Failed pending semaphore; error: %d: %s", err, strerror(-err)); err = 0; rt_printf("Low priority task locks semaphore\n"); rt_timer_spin(SPINTIME); // spin cpu doing nothing runtime = runtime + SPINTIME; rt_printf("Low priority task unlocks semaphore\n"); err = rt_sem_v(&mysync); if(err < 0) rt_printf("Failed signaling semaphore; error: %d: %s", err, strerror(-err)); err = 0; } rt_printf("..........................................Low priority task ends\n"); }
int spin_timer(RTIME* ct) { rt_timer_spin(*ct); return 1; }
int wait_blink() { rt_timer_spin(200000); return 1; }