40 #define _DARWIN_C_SOURCE 52 #include <mach/mach_init.h> 53 #include <mach/task.h> 68 #define ORO_WAIT_ABS 0 70 #define ORO_WAIT_REL 1 87 #define ORO_SCHED_RT SCHED_FIFO 88 #define ORO_SCHED_OTHER SCHED_OTHER 99 #ifndef CLOCK_REALTIME 101 #define CLOCK_REALTIME 0 105 int rv = gettimeofday(&now, NULL);
111 tp->tv_sec = now.tv_sec;
112 tp->tv_nsec = now.tv_usec * 1000;
121 timevl.tv_sec = hrt / 1000000000LL;
122 timevl.tv_nsec = hrt % 1000000000LL;
134 return ( NANO_TIME ) ( tv.tv_sec * 1000000000LL ) + ( NANO_TIME ) ( tv.tv_nsec );
150 return nanosleep( rqtp, rmtp );
168 #include <mach/semaphore.h> 173 return semaphore_create(mach_task_self(), m, SYNC_POLICY_FIFO, value);
178 return semaphore_destroy(mach_task_self(), *m);
183 return semaphore_signal(*m);
188 return semaphore_wait(*m);
194 mach_timespec_t mach_delayvl = {
196 static_cast<unsigned int>(delayvl.tv_sec),
197 static_cast<clock_res_t> (delayvl.tv_nsec)
204 return semaphore_timedwait( *m, mach_delayvl);
221 delayvl.tv_sec = arg_time.tv_sec - timevl.tv_sec;
222 delayvl.tv_nsec = arg_time.tv_nsec - timevl.tv_nsec;
224 if ( delayvl.tv_nsec >= 1000000000) {
226 delayvl.tv_nsec -= 1000000000;
228 if ( delayvl.tv_nsec < 0) {
230 delayvl.tv_nsec += 1000000000;
233 assert( 0 <= delayvl.tv_sec);
234 assert( 0 <= delayvl.tv_nsec);
235 assert( delayvl.tv_nsec < 1000000000 );
237 mach_timespec_t mach_delayvl = {
239 static_cast<unsigned int>(delayvl.tv_sec),
240 static_cast<clock_res_t> (delayvl.tv_nsec)
246 int rc = semaphore_timedwait( *m, mach_delayvl);
248 return (KERN_OPERATION_TIMED_OUT == rc ? -1 : 0);
279 #define rtos_printf printf int rtos_mutex_init(rt_mutex_t *m)
static int rtos_sem_init(rt_sem_t *m, int value)
static NANO_TIME rtos_get_time_ticks()
static int rtos_sem_wait(rt_sem_t *m)
static int rtos_sem_wait_timed(rt_sem_t *m, NANO_TIME delay)
static int rtos_sem_destroy(rt_sem_t *m)
static int rtos_sem_signal(rt_sem_t *m)
static NANO_TIME rtos_get_time_ns(void)
cyg_tick_count_t TICK_TIME
static int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
static void rtos_disable_rt_warning()
int rtos_mutex_unlock(rt_mutex_t *m)
static int rtos_sem_wait_until(rt_sem_t *m, NANO_TIME abs_time)
rt_mutex_impl_t * rt_mutex_t
static long long nano2ticks(long long nano)
static int rtos_sem_trywait(rt_sem_t *m)
int rtos_mutex_lock(rt_mutex_t *m)
static const NANO_TIME InfiniteNSecs
static int clock_gettime(int clk_id, struct timespec *tp)
static long long ticks2nano(long long count)
static void rtos_enable_rt_warning()
static const double InfiniteSeconds
int rtos_mutex_destroy(rt_mutex_t *m)
static const TICK_TIME InfiniteTicks
struct timespec TIME_SPEC
static TIME_SPEC ticks2timespec(TICK_TIME hrt)