38 #define _XOPEN_SOURCE 600 // use all Posix features. 42 #include <semaphore.h> 49 #include "../oro_limits.h" 66 #define ORO_WAIT_ABS 0 68 #define ORO_WAIT_REL 1 86 #define ORO_SCHED_RT SCHED_FIFO 87 #define ORO_SCHED_OTHER SCHED_OTHER 90 // high-resolution time to timespec 95 timevl.tv_sec = hrt / 1000000000LL;
96 timevl.tv_nsec = hrt % 1000000000LL;
103 clock_gettime(CLOCK_MONOTONIC, &tv);
108 static inline NANO_TIME rtos_get_realtime_ns(
void )
127 return nanosleep( rqtp, rmtp );
151 return sem_init(m, 0, value);
156 return sem_destroy(m);
171 return sem_trywait(m);
177 if ( sem_getvalue(m, &val) == 0)
189 return pthread_mutex_init(m, 0 );
194 return pthread_mutex_destroy(m);
199 pthread_mutexattr_t attr;
200 int ret = pthread_mutexattr_init(&attr);
201 if (ret != 0)
return ret;
204 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
205 if (ret != 0)
return ret;
207 ret = pthread_mutex_init(m, &attr);
209 pthread_mutexattr_destroy(&attr);
215 return pthread_mutex_destroy(m);
220 return pthread_mutex_lock(m);
225 return pthread_mutex_lock(m);
235 return pthread_mutex_timedlock(m, &arg_time);
245 return pthread_mutex_timedlock(m, &arg_time);
254 if (relative_time < 0)
return ETIMEDOUT;
264 if (relative_time < 0)
return ETIMEDOUT;
270 return pthread_mutex_trylock(m);
275 return pthread_mutex_trylock(m);
280 return pthread_mutex_unlock(m);
285 return pthread_mutex_unlock(m);
300 pthread_condattr_t attr;
301 int ret = pthread_condattr_init(&attr);
302 if (ret != 0)
return ret;
305 ret = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
307 pthread_condattr_destroy(&attr);
311 ret = pthread_cond_init(cond, &attr);
312 pthread_condattr_destroy(&attr);
319 return pthread_cond_destroy(cond);
324 return pthread_cond_wait(cond, mutex);
330 return pthread_cond_timedwait(cond, mutex, &arg_time);
335 return pthread_cond_broadcast(cond);
338 #define rtos_printf printf int rtos_mutex_init(rt_mutex_t *m)
const double InfiniteSeconds
int rtos_mutex_rec_lock(rt_rec_mutex_t *m)
const TICK_TIME InfiniteTicks
int rtos_cond_destroy(rt_cond_t *cond)
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_mutex_rec_init(rt_rec_mutex_t *m)
int rtos_sem_trywait(rt_sem_t *m)
int rtos_mutex_rec_trylock(rt_rec_mutex_t *m)
int rtos_sem_signal(rt_sem_t *m)
int rtos_mutex_rec_trylock_for(rt_rec_mutex_t *m, NANO_TIME relative_time)
int rtos_cond_timedwait(rt_cond_t *cond, rt_mutex_t *mutex, NANO_TIME abs_time)
int rtos_cond_wait(rt_cond_t *cond, rt_mutex_t *mutex)
TIME_SPEC ticks2timespec(TICK_TIME hrt)
cyg_tick_count_t TICK_TIME
int rtos_mutex_unlock(rt_mutex_t *m)
int rtos_mutex_rec_unlock(rt_rec_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_until(rt_mutex_t *m, NANO_TIME abs_time)
int rtos_mutex_rec_lock_until(rt_rec_mutex_t *m, NANO_TIME abs_time)
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
int rtos_mutex_trylock(rt_mutex_t *m)
NANO_TIME ticks2nano(TICK_TIME count)
Time conversions from system ticks to nano seconds.
cyg_recursive_mutex_t rt_rec_mutex_t
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)
int rtos_sem_value(rt_sem_t *m)
int rtos_mutex_trylock_for(rt_mutex_t *m, NANO_TIME relative_time)
void rtos_enable_rt_warning()
Allows the RTOS to print a warning when we violate real-time constraints.
struct timespec TIME_SPEC
int rtos_cond_init(rt_cond_t *cond)
int rtos_sem_wait(rt_sem_t *m)
int rtos_cond_broadcast(rt_cond_t *cond)
int rtos_mutex_rec_destroy(rt_rec_mutex_t *m)