49 #define _GNU_SOURCE // use all Posix features (and then some). 54 #define _XOPEN_SOURCE 600 // use all Posix98 features. 62 #include <sys/types.h> 67 #include "../oro_limits.h" 73 #include "../../rtt-config.h" 74 #if !defined(OROBLD_OS_AGNOSTIC) || defined(OROBLD_OS_LXRT_INTERNAL) // define the latter to include nevertheless the RTAI header files 78 #if defined(OROBLD_OS_LXRT_INTERNAL) 79 #define CONFIG_RTAI_LXRT_INLINE 1 83 #include <rtai_config.h> 84 #include <rtai_lxrt.h> 98 typedef struct oro_lxrt_t {
100 } __LXRT_HANDLE_STRUCT;
105 #endif // OROBLD_OS_AGNOSTIC // for RTAI header files. 119 #define __LXRT_USERSPACE__ 143 #define SCHED_LXRT_HARD 0 144 #define SCHED_LXRT_SOFT 1 145 #define ORO_SCHED_RT 0 146 #define ORO_SCHED_OTHER 1 148 #define ORO_WAIT_ABS 0 149 #define ORO_WAIT_REL 1 153 // rtai undef cfr boost::graph library adjacency_list.hpp:443 162 #ifndef OROBLD_OS_AGNOSTIC 168 timevl.tv_sec = nano2count(hrt) / 1000000000LL;
169 timevl.tv_nsec = nano2count(hrt) % 1000000000LL;
174 #ifdef OROSEM_OS_LXRT_CHECK 175 #define CHK_LXRT_CALL() do { if(rt_buddy() == 0) { \ 176 printf("LXRT NOT INITIALISED IN THIS THREAD pid=%d,\n\ 177 BUT TRIES TO INVOKE LXRT FUNCTION >>%s<< ANYWAY\n", getpid(), __FUNCTION__ );\ 178 assert( rt_buddy() != 0 ); }\ 180 #define CHK_LXRT_PTR(ptr) do { if(ptr == 0) { \ 181 printf("TRIED TO PASS NULL POINTER TO LXRT IN THREAD pid=%d,\n\ 182 IN TRYING TO INVOKE LXRT FUNCTION >>%s<<\n", getpid(), __FUNCTION__ );\ 183 assert( ptr != 0 ); }\ 186 #define CHK_LXRT_CALL() 187 #define CHK_LXRT_PTR( a ) 194 inline TICK_TIME
ticksPerSec(
void) {
return nano2count( 1000 * 1000 * 1000 ); }
196 inline TICK_TIME
nano2ticks(NANO_TIME t) {
return nano2count(t); }
197 inline NANO_TIME
ticks2nano(TICK_TIME t) {
return count2nano(t); }
202 nanosleep(rqtp,rmtp);
210 m->sem = rt_sem_init( rt_get_name(0) , value);
211 return m->sem == 0 ? -1 : 0;
217 return rt_sem_delete( m->sem );
223 return rt_sem_signal( m->sem );
229 return rt_sem_wait( m->sem );
235 return rt_sem_wait_if(m->sem);
241 return rt_sem_count(m->sem);
248 ret = rt_sem_wait_timed(m->sem, nano2count(delay) ) ;
249 #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) 250 # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR > 3 251 return (ret == RTE_TIMOUT) ? -1 : 0;
253 return (ret == SEM_TIMOUT) ? -1 : 0;
256 return (ret == SEM_TIMOUT) ? -1 : 0;
264 ret = rt_sem_wait_until(m->sem, nano2count(when) ) ;
265 #if defined(CONFIG_RTAI_VERSION_MINOR) && defined(CONFIG_RTAI_VERSION_MAJOR) 266 # if CONFIG_RTAI_VERSION_MAJOR == 3 && CONFIG_RTAI_VERSION_MINOR > 3 267 return (ret == RTE_TIMOUT) ? -1 : 0;
269 return (ret == SEM_TIMOUT) ? -1 : 0;
272 return (ret == SEM_TIMOUT) ? -1 : 0;
279 m->sem = rt_typed_sem_init( rt_get_name(0),1, BIN_SEM | PRIO_Q);
280 return m->sem == 0 ? -1 : 0;
286 return rt_sem_delete(m->sem);
293 m->sem = rt_typed_sem_init( rt_get_name(0), 1, RES_SEM);
294 return m->sem == 0 ? -1 : 0;
300 return rt_sem_delete(m->sem);
306 return rt_sem_wait(m->sem);
312 return rt_sem_wait(m->sem);
318 return rt_sem_wait_if(m->sem) > 0 ? 0 : -EAGAIN;
324 return rt_sem_wait_if(m->sem) > 0 ? 0 : -EAGAIN;
330 return rt_sem_wait_until(m->sem, nano2count(abs_time)) < SEM_TIMOUT ? 0 : -EAGAIN;
336 return rt_sem_wait_until(m->sem, nano2count(abs_time)) < SEM_TIMOUT ? 0 : -EAGAIN;
343 return rt_sem_signal(m->sem);
349 return rt_sem_signal(m->sem);
355 cond->cond = rt_cond_init(0);
356 return cond->cond == 0 ? -1 : 0;
362 return rt_cond_delete(cond->cond);
368 int ret = rt_cond_wait(cond->cond, mutex->sem );
377 int ret = rt_cond_wait_until(cond->cond, mutex->sem, nano2count(abs_time) );
380 if ( ret == SEM_TIMOUT )
388 return rt_cond_broadcast(cond->cond);
394 char printkbuf [2000];
396 va_start (list, fmt);
397 vsprintf(printkbuf, fmt, list);
400 return rtai_print_to_screen(printkbuf);
404 #else // OSBLD_OS_AGNOSTIC 465 #endif // OSBLD_OS_AGNOSTIC static int rtos_sem_value(rt_sem_t *m)
static int rtos_mutex_rec_lock(rt_rec_mutex_t *m)
static int rtos_cond_timedwait(rt_cond_t *cond, rt_mutex_t *mutex, NANO_TIME abstime)
int rtos_printf(const char *fmt,...)
static int rtos_mutex_unlock(rt_mutex_t *m)
static int rtos_sem_init(rt_sem_t *m, int value)
static int rtos_mutex_trylock(rt_mutex_t *m)
int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
static int rtos_cond_destroy(rt_cond_t *cond)
TICK_TIME rtos_get_time_ticks(void)
static void rtos_enable_rt_warning()
static const TICK_TIME InfiniteTicks
static int rtos_mutex_destroy(rt_mutex_t *m)
NANO_TIME ticks2nano(TICK_TIME t)
static int rtos_sem_wait_until(rt_sem_t *m, NANO_TIME when)
struct oro_rtai_cond_t rt_cond_t
TIME_SPEC ticks2timespec(TICK_TIME hrt)
TICK_TIME nano2ticks(NANO_TIME t)
static const double InfiniteSeconds
struct oro_rtai_sem_t rt_sem_t
static int rtos_sem_trywait(rt_sem_t *m)
static int rtos_sem_destroy(rt_sem_t *m)
static int rtos_mutex_rec_lock_until(rt_rec_mutex_t *m, NANO_TIME abs_time)
TICK_TIME ticksPerSec(void)
static int rtos_mutex_rec_unlock(rt_rec_mutex_t *m)
static int rtos_mutex_rec_destroy(rt_rec_mutex_t *m)
static int rtos_cond_broadcast(rt_cond_t *cond)
NANO_TIME rtos_get_time_ns(void)
static int rtos_cond_init(rt_cond_t *cond)
static int rtos_sem_signal(rt_sem_t *m)
static int rtos_mutex_rec_trylock(rt_rec_mutex_t *m)
static int rtos_sem_wait_timed(rt_sem_t *m, NANO_TIME delay)
static int rtos_sem_wait(rt_sem_t *m)
static int rtos_mutex_rec_init(rt_rec_mutex_t *m)
static int rtos_mutex_lock(rt_mutex_t *m)
static const NANO_TIME InfiniteNSecs
struct timespec TIME_SPEC
static void rtos_disable_rt_warning()
static int rtos_mutex_init(rt_mutex_t *m)
static int rtos_mutex_lock_until(rt_mutex_t *m, NANO_TIME abs_time)
RTOS_RTAI_TASK * rtaitask
static int rtos_cond_wait(rt_cond_t *cond, rt_mutex_t *mutex)