void rtt_sleep(int ms) { TIME_SPEC ts; ts.tv_sec = 0; ts.tv_nsec = ms * 1000*1000; rtos_nanosleep(&ts, NULL); }
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK* t) { #if 0 //under plain gnulinux, sched_yield may have little influence, so sleep // to force rescheduling of other threads. NANO_TIME timeRemaining = 1000; // 1ms TIME_SPEC ts( ticks2timespec( timeRemaining ) ); rtos_nanosleep( &ts , NULL ); #else int ret = sched_yield(); if ( ret != 0) perror("rtos_task_yield"); #endif }
INTERNAL_QUAL int rtos_task_wait_period( RTOS_TASK* task ) { if ( task->period == 0 ) return 0; //rtos_printf("Time is %lld nsec, Mark is %lld nsec.\n",rtos_get_time_ns(), task->periodMark ); // CALCULATE in nsecs NANO_TIME timeRemaining = task->periodMark - rtos_get_time_ns(); // next wake-up time : task->periodMark += task->period; if ( timeRemaining > 0 ) { //rtos_printf("Waiting for %lld nsec\n",timeRemaining); TIME_SPEC ts( ticks2timespec( timeRemaining ) ); rtos_nanosleep( &ts , NULL ); return 0; } return -1; }