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;
135 static inline TICK_TIME timespec2ticks(
const TIME_SPEC* ts)
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 ) {
219 static inline int rtos_sem_wait_timed(rt_sem_t* m, NANO_TIME delay )
222 return rt_sem_p(m, rt_timer_ns2ticks(delay) ) == 0 ? 0 : -1;
225 static inline int rtos_sem_wait_until(rt_sem_t* m, NANO_TIME when )
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);
353 static inline int rtos_cond_wait(rt_cond_t *cond, rt_mutex_t *mutex)
356 int ret = rt_cond_wait(cond, mutex, TM_INFINITE);
362 static inline int rtos_cond_timedwait(rt_cond_t *cond, rt_mutex_t *mutex, NANO_TIME abs_time)
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 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
TICK_TIME ticksPerSec(void)
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)