18 #define _DARWIN_C_SOURCE 30 #include <mach/mach_init.h> 31 #include <mach/task.h> 46 #define ORO_WAIT_ABS 0 48 #define ORO_WAIT_REL 1 65 #define ORO_SCHED_RT SCHED_FIFO 66 #define ORO_SCHED_OTHER SCHED_OTHER 77 #ifndef CLOCK_REALTIME 79 #define CLOCK_REALTIME 0 80 static inline int clock_gettime(
int clk_id ,
struct timespec *tp)
83 int rv = gettimeofday(&now, NULL);
89 tp->tv_sec = now.tv_sec;
90 tp->tv_nsec = now.tv_usec * 1000;
99 timevl.tv_sec = hrt / 1000000000LL;
100 timevl.tv_nsec = hrt % 1000000000LL;
112 return ( NANO_TIME ) ( tv.tv_sec * 1000000000LL ) + ( NANO_TIME ) ( tv.tv_nsec );
128 return nanosleep( rqtp, rmtp );
131 static inline long long nano2ticks(
long long nano )
136 static inline long long ticks2nano(
long long count )
146 #include <mach/semaphore.h> 151 return semaphore_create(mach_task_self(), m, SYNC_POLICY_FIFO, value);
156 return semaphore_destroy(mach_task_self(), *m);
161 return semaphore_signal(*m);
166 return semaphore_wait(*m);
172 mach_timespec_t mach_delayvl = {
174 static_cast<unsigned int>(delayvl.tv_sec),
175 static_cast<clock_res_t> (delayvl.tv_nsec)
182 return semaphore_timedwait( *m, mach_delayvl);
187 return rtos_sem_wait_timed(m,0);
199 delayvl.tv_sec = arg_time.tv_sec - timevl.tv_sec;
200 delayvl.tv_nsec = arg_time.tv_nsec - timevl.tv_nsec;
202 if ( delayvl.tv_nsec >= 1000000000) {
204 delayvl.tv_nsec -= 1000000000;
206 if ( delayvl.tv_nsec < 0) {
208 delayvl.tv_nsec += 1000000000;
211 assert( 0 <= delayvl.tv_sec);
212 assert( 0 <= delayvl.tv_nsec);
213 assert( delayvl.tv_nsec < 1000000000 );
215 mach_timespec_t mach_delayvl = {
217 static_cast<unsigned int>(delayvl.tv_sec),
218 static_cast<clock_res_t> (delayvl.tv_nsec)
224 int rc = semaphore_timedwait( *m, mach_delayvl);
226 return (KERN_OPERATION_TIMED_OUT == rc ? -1 : 0);
257 #define rtos_printf printf int rtos_mutex_init(rt_mutex_t *m)
const double InfiniteSeconds
const TICK_TIME InfiniteTicks
NANO_TIME rtos_get_time_ns(void)
Get "system" time in nanoseconds.
int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
const NANO_TIME InfiniteNSecs
int rtos_sem_trywait(rt_sem_t *m)
int rtos_sem_signal(rt_sem_t *m)
TIME_SPEC ticks2timespec(TICK_TIME hrt)
cyg_tick_count_t TICK_TIME
int rtos_mutex_unlock(rt_mutex_t *m)
void rtos_disable_rt_warning()
Disallows the RTOS to print a warning when we violate real-time constraints.
int rtos_sem_destroy(rt_sem_t *m)
int rtos_mutex_lock(rt_mutex_t *m)
TICK_TIME rtos_get_time_ticks(void)
Get "system" time in ticks FIXME see https://proj.fmtc.be/orocos-bugzilla/show_bug.cgi?id=60
NANO_TIME ticks2nano(TICK_TIME count)
Time conversions from system ticks to nano seconds.
int rtos_sem_init(rt_sem_t *m, int value)
All these should return zero in case of succes.
TICK_TIME nano2ticks(NANO_TIME nano)
Time conversions from nano seconds to system ticks.
int rtos_mutex_destroy(rt_mutex_t *m)
void rtos_enable_rt_warning()
Allows the RTOS to print a warning when we violate real-time constraints.
struct timespec TIME_SPEC
int rtos_sem_wait(rt_sem_t *m)