30 #define _GNU_SOURCE // use all Posix features (and then some). 35 #define _XOPEN_SOURCE 600 // use all Posix98 features. 43 #include <sys/types.h> 48 #include "../oro_limits.h" 54 #include "../../rtt-config.h" 55 #if !defined(OROBLD_OS_AGNOSTIC) || defined(OROBLD_OS_LXRT_INTERNAL) // define the latter to include nevertheless the RTAI header files 59 #if defined(OROBLD_OS_LXRT_INTERNAL) 60 #define CONFIG_RTAI_LXRT_INLINE 1 64 #include <rtai_config.h> 65 #include <rtai_lxrt.h> 79 typedef struct oro_lxrt_t {
81 } __LXRT_HANDLE_STRUCT;
86 #endif // OROBLD_OS_AGNOSTIC // for RTAI header files. 100 #define __LXRT_USERSPACE__ 124 #define SCHED_LXRT_HARD 0 125 #define SCHED_LXRT_SOFT 1 126 #define ORO_SCHED_RT 0 127 #define ORO_SCHED_OTHER 1 129 #define ORO_WAIT_ABS 0 130 #define ORO_WAIT_REL 1 134 // rtai undef cfr boost::graph library adjacency_list.hpp:443 143 #ifndef OROBLD_OS_AGNOSTIC 149 timevl.tv_sec = nano2count(hrt) / 1000000000LL;
150 timevl.tv_nsec = nano2count(hrt) % 1000000000LL;
155 #ifdef OROSEM_OS_LXRT_CHECK 156 #define CHK_LXRT_CALL() do { if(rt_buddy() == 0) { \ 157 printf("LXRT NOT INITIALISED IN THIS THREAD pid=%d,\n\ 158 BUT TRIES TO INVOKE LXRT FUNCTION >>%s<< ANYWAY\n", getpid(), __FUNCTION__ );\ 159 assert( rt_buddy() != 0 ); }\ 161 #define CHK_LXRT_PTR(ptr) do { if(ptr == 0) { \ 162 printf("TRIED TO PASS NULL POINTER TO LXRT IN THREAD pid=%d,\n\ 163 IN TRYING TO INVOKE LXRT FUNCTION >>%s<<\n", getpid(), __FUNCTION__ );\ 164 assert( ptr != 0 ); }\ 167 #define CHK_LXRT_CALL() 168 #define CHK_LXRT_PTR( a ) 175 inline TICK_TIME
ticksPerSec(
void) {
return nano2count( 1000 * 1000 * 1000 ); }
177 inline TICK_TIME
nano2ticks(NANO_TIME t) {
return nano2count(t); }
178 inline NANO_TIME
ticks2nano(TICK_TIME t) {
return count2nano(t); }
183 nanosleep(rqtp,rmtp);
191 m->sem = rt_sem_init( rt_get_name(0) , value);
192 return m->sem == 0 ? -1 : 0;
198 return rt_sem_delete( m->sem );
204 return rt_sem_signal( m->sem );
210 return rt_sem_wait( m->sem );
216 return rt_sem_wait_if(m->sem);
222 return rt_sem_count(m->sem);
225 static inline int rtos_sem_wait_timed(
rt_sem_t* m, NANO_TIME delay )
229 ret = rt_sem_wait_timed(m->sem, nano2count(delay) ) ;
230 #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) 231 # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR > 3 232 return (ret == RTE_TIMOUT) ? -1 : 0;
234 return (ret == SEM_TIMOUT) ? -1 : 0;
237 return (ret == SEM_TIMOUT) ? -1 : 0;
241 static inline int rtos_sem_wait_until(
rt_sem_t* m, NANO_TIME when )
245 ret = rt_sem_wait_until(m->sem, nano2count(when) ) ;
246 #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) 247 # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR > 3 248 return (ret == RTE_TIMOUT) ? -1 : 0;
250 return (ret == SEM_TIMOUT) ? -1 : 0;
253 return (ret == SEM_TIMOUT) ? -1 : 0;
260 m->sem = rt_typed_sem_init( rt_get_name(0),1, BIN_SEM | PRIO_Q);
261 return m->sem == 0 ? -1 : 0;
267 return rt_sem_delete(m->sem);
274 m->sem = rt_typed_sem_init( rt_get_name(0), 1, RES_SEM);
275 return m->sem == 0 ? -1 : 0;
281 return rt_sem_delete(m->sem);
287 return rt_sem_wait(m->sem);
293 return rt_sem_wait(m->sem);
299 return rt_sem_wait_if(m->sem) > 0 ? 0 : -EAGAIN;
305 return rt_sem_wait_if(m->sem) > 0 ? 0 : -EAGAIN;
311 return rt_sem_wait_until(m->sem, nano2count(abs_time)) < SEM_TIMOUT ? 0 : -EAGAIN;
317 return rt_sem_wait_until(m->sem, nano2count(abs_time)) < SEM_TIMOUT ? 0 : -EAGAIN;
324 return rt_sem_signal(m->sem);
330 return rt_sem_signal(m->sem);
336 cond->cond = rt_cond_init(0);
337 return cond->cond == 0 ? -1 : 0;
343 return rt_cond_delete(cond->cond);
349 int ret = rt_cond_wait(cond->cond, mutex->sem );
358 int ret = rt_cond_wait_until(cond->cond, mutex->sem, nano2count(abs_time) );
361 if ( ret == SEM_TIMOUT )
369 return rt_cond_broadcast(cond->cond);
375 char printkbuf [2000];
377 va_start (list, fmt);
378 vsprintf(printkbuf, fmt, list);
381 return rtai_print_to_screen(printkbuf);
385 #else // OSBLD_OS_AGNOSTIC 437 int rtos_sem_wait_timed(
rt_sem_t* m, NANO_TIME delay );
438 int rtos_sem_wait_until(
rt_sem_t* m, NANO_TIME when );
446 #endif // OSBLD_OS_AGNOSTIC 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_printf(const char *fmt,...)
'real-time' print function.
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_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)
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)
RTOS_RTAI_TASK * rtaitask
int rtos_cond_broadcast(rt_cond_t *cond)
int rtos_mutex_rec_destroy(rt_rec_mutex_t *m)