43 #define _XOPEN_SOURCE 600 // use all Posix features. 52 #include "../../rtt-config.h" 73 #include "../oro_limits.h" 75 #include <xeno_config.h> 76 #include <native/task.h> 77 #include <native/timer.h> 78 #include <native/mutex.h> 79 #include <native/sem.h> 80 #include <native/cond.h> 83 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) < 2300 84 #define rt_mutex_acquire rt_mutex_lock 85 #define rt_mutex_release rt_mutex_unlock 88 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) >= 2500 89 #define ORO_XENO_HAS_ACQUIRE_UNTIL 117 #define SCHED_XENOMAI_HARD 0 118 #define SCHED_XENOMAI_SOFT 1 119 #define ORO_SCHED_RT 0 120 #define ORO_SCHED_OTHER 1 122 #define ORO_WAIT_ABS 0 123 #define ORO_WAIT_REL 1 129 timevl.tv_sec = rt_timer_tsc2ns(hrt) / 1000000000LL;
130 timevl.tv_nsec = rt_timer_tsc2ns(hrt) % 1000000000LL;
137 return rt_timer_ns2tsc(ts->tv_nsec + ts->tv_sec*1000000000LL);
141 #ifdef OROSEM_OS_XENO_CHECK 142 #define CHK_XENO_CALL() do { if(rt_task_self() == 0) { \ 143 printf("RTT: XENO NOT INITIALISED IN THIS THREAD pid=%d,\n\ 144 BUT TRIES TO INVOKE XENO FUNCTION >>%s<< ANYWAY\n", getpid(), __FUNCTION__ );\ 145 assert( rt_task_self() != 0 ); }\ 147 #define CHK_XENO_PTR(ptr) do { if(ptr == 0) { \ 148 printf("RTT: TRIED TO PASS NULL POINTER TO XENO IN THREAD pid=%d,\n\ 149 IN TRYING TO INVOKE XENO FUNCTION >>%s<<\n", getpid(), __FUNCTION__ );\ 150 assert( ptr != 0 ); }\ 153 #define CHK_XENO_CALL() 154 #define CHK_XENO_PTR( a ) 157 static inline NANO_TIME
rtos_get_time_ns(
void) {
return rt_timer_ticks2ns(rt_timer_read()); }
161 static inline TICK_TIME
ticksPerSec(
void) {
return rt_timer_ns2tsc( 1000 * 1000 * 1000 ); }
168 static inline TICK_TIME
nano2ticks(NANO_TIME t) {
return rt_timer_ns2tsc(t); }
169 static inline NANO_TIME
ticks2nano(TICK_TIME t) {
return rt_timer_tsc2ns(t); }
174 RTIME ticks = rqtp->tv_sec * 1000000000LL + rqtp->tv_nsec;
175 rt_task_sleep( rt_timer_ns2ticks(ticks) );
182 return rt_sem_create( m, 0, value, S_PRIO);
188 return rt_sem_delete( m );
194 return rt_sem_v( m );
200 return rt_sem_p( m, TM_INFINITE );
206 return rt_sem_p( m, TM_NONBLOCK);
213 if (rt_sem_inquire(m, &sinfo) == 0 ) {
222 return rt_sem_p(m, rt_timer_ns2ticks(delay) ) == 0 ? 0 : -1;
228 return rt_sem_p(m, rt_timer_ns2ticks(when) - rt_timer_read() ) == 0 ? 0 : -1;
235 return rt_mutex_create(m, 0);
241 return rt_mutex_delete(m);
248 return rt_mutex_create(m, 0);
254 return rt_mutex_delete(m);
266 struct rt_mutex_info info;
267 rt_mutex_inquire(m, &info );
268 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) >= 2500 283 #if !defined(ORO_XENO_HAS_ACQUIRE_UNTIL) // see top of this file 288 return rt_mutex_acquire_until(m, rt_timer_ns2ticks(abs_time) );
332 rt_task_set_mode(0, T_WARNSW, NULL);
338 rt_task_set_mode(T_WARNSW, 0, NULL);
344 return rt_cond_create(cond, 0);
350 return rt_cond_delete(cond);
356 int ret = rt_cond_wait(cond, mutex, TM_INFINITE);
366 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) < 2500 367 return rt_cond_wait(cond, mutex, rt_timer_ns2ticks(abs_time) - rt_timer_read() );
369 return rt_cond_wait_until(cond, mutex, rt_timer_ns2ticks(abs_time) );
376 return rt_cond_broadcast(cond);
380 #define rtos_printf printf static const NANO_TIME InfiniteNSecs
static TIME_SPEC ticks2timespec(TICK_TIME hrt)
static int rtos_sem_init(rt_sem_t *m, int value)
static int rtos_mutex_rec_init(rt_rec_mutex_t *m)
static const TICK_TIME InfiniteTicks
static int rtos_cond_broadcast(rt_cond_t *cond)
static int rtos_sem_signal(rt_sem_t *m)
static NANO_TIME rtos_get_time_ns(void)
static int rtos_sem_destroy(rt_sem_t *m)
static int rtos_mutex_init(rt_mutex_t *m)
static TICK_TIME timespec2ticks(const TIME_SPEC *ts)
static int rtos_mutex_destroy(rt_mutex_t *m)
static int rtos_cond_init(rt_cond_t *cond)
static int rtos_mutex_rec_destroy(rt_rec_mutex_t *m)
static TICK_TIME rtos_get_time_ticks(void)
static int rtos_cond_destroy(rt_cond_t *cond)
static int rtos_mutex_rec_lock_until(rt_rec_mutex_t *m, NANO_TIME abs_time)
static int rtos_sem_wait(rt_sem_t *m)
static int rtos_mutex_rec_unlock(rt_rec_mutex_t *m)
static int rtos_mutex_trylock(rt_mutex_t *m)
static int rtos_mutex_trylock_for(rt_mutex_t *m, NANO_TIME relative_time)
static NANO_TIME ticks2nano(TICK_TIME t)
static int rtos_sem_wait_timed(rt_sem_t *m, NANO_TIME delay)
static int rtos_mutex_rec_trylock_for(rt_rec_mutex_t *m, NANO_TIME relative_time)
static int rtos_mutex_rec_lock(rt_rec_mutex_t *m)
static int rtos_mutex_lock_until(rt_mutex_t *m, NANO_TIME abs_time)
static void rtos_enable_rt_warning()
static TICK_TIME ticksPerSec(void)
static int rtos_cond_timedwait(rt_cond_t *cond, rt_mutex_t *mutex, NANO_TIME abs_time)
static int rtos_sem_value(rt_sem_t *m)
static int rtos_mutex_unlock(rt_mutex_t *m)
static int rtos_mutex_lock(rt_mutex_t *m)
static int rtos_mutex_rec_trylock(rt_rec_mutex_t *m)
static int rtos_sem_trywait(rt_sem_t *m)
static TICK_TIME nano2ticks(NANO_TIME t)
struct timespec TIME_SPEC
static void rtos_disable_rt_warning()
static const double InfiniteSeconds
static int rtos_cond_wait(rt_cond_t *cond, rt_mutex_t *mutex)
static int rtos_sem_wait_until(rt_sem_t *m, NANO_TIME when)
static int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)