Index: config/check_depend.cmake =================================================================== --- config/check_depend.cmake (revision 29869) +++ config/check_depend.cmake (working copy) @@ -52,7 +52,7 @@ SET(OROCLS_CORELIB_PROPERTIES_DEMARSHALLING_DRIVER "TinyDemarshaller") ENDIF ( XERCES AND XERCES_HEADERS ) -SET( OROCOS_TARGET gnulinux CACHE STRING "The Operating System target. One of [lxrt gnulinux xenomai macosx]") +SET( OROCOS_TARGET gnulinux CACHE STRING "The Operating System target. One of [lxrt gnulinux xenomai macosx win32]") STRING(TOUPPER ${OROCOS_TARGET} OROCOS_TARGET_CAP) SET(LINUX_SOURCE_DIR ${LINUX_SOURCE_DIR} CACHE PATH "path to linux source dir" FORCE) @@ -162,6 +162,16 @@ SET(OROPKG_OS_MACOSX FALSE CACHE INTERNAL "" FORCE) ENDIF(OROCOS_TARGET STREQUAL "macosx") +IF(OROCOS_TARGET STREQUAL "win32") + SET(OROPKG_OS_WIN32 TRUE CACHE INTERNAL "" FORCE) + SET(RTT_USER_LINKFLAGS "${RTT_USER_LINKFLAGS} -lpthread" CACHE INTERNAL "") +#--enable-all-export and --enable-auto-import are already set by cmake. +#but we need it here for the unit tests as well. + SET(RTT_LINKFLAGS "${RTT_LINKFLAGS} -Wl,--enable-auto-import" CACHE INTERNAL "") + LINK_LIBRARIES(pthreadGC2) +ELSE(OROCOS_TARGET STREQUAL "win32") + SET(OROPKG_OS_WIN32 FALSE CACHE INTERNAL "" FORCE) +ENDIF(OROCOS_TARGET STREQUAL "win32") IF(OROCOS_TARGET STREQUAL "ecos") Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt (revision 29869) +++ src/CMakeLists.txt (working copy) @@ -125,6 +125,7 @@ OUTPUT_NAME orocos-rtt-${OROCOS_TARGET} # Set accumulated compilation flags: (.so and .a) COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}" CLEAN_DIRECT_OUTPUT 1) ### Generate rtt-config.h : HAS NO ACCESS TO SUBDIRECTORY VARIABLES !!! Index: src/os/CMakeLists.txt =================================================================== --- src/os/CMakeLists.txt (revision 29869) +++ src/os/CMakeLists.txt (working copy) @@ -10,6 +10,7 @@ ADD_SUBDIRECTORY( xenomai ) ADD_SUBDIRECTORY( ecos ) ADD_SUBDIRECTORY( macosx ) +ADD_SUBDIRECTORY( win32 ) # Supported Hardware ADD_SUBDIRECTORY( oro_i386 ) Index: src/os/fosi.h =================================================================== --- src/os/fosi.h (revision 29869) +++ src/os/fosi.h (working copy) @@ -58,3 +58,7 @@ #ifdef OROPKG_OS_MACOSX #include "macosx/fosi.h" #endif + +#ifdef OROPKG_OS_WIN32 + #include "win32/fosi.h" +#endif Index: src/os/oro_i386/oro_atomic.h =================================================================== --- src/os/oro_i386/oro_atomic.h (revision 29869) +++ src/os/oro_i386/oro_atomic.h (working copy) @@ -37,7 +37,7 @@ -#include "../../rtt-config.h" +#include "rtt-config.h" #ifndef __ARCH_I386_ORO_ATOMIC__ #define __ARCH_I386_ORO_ATOMIC__ Index: src/os/oro_i386/oro_system.h =================================================================== --- src/os/oro_i386/oro_system.h (revision 29869) +++ src/os/oro_i386/oro_system.h (working copy) @@ -35,7 +35,7 @@ * * ***************************************************************************/ -#include "../../rtt-config.h" +#include "rtt-config.h" // do not rely on system headers : // i386 : Index: src/os/win32/fosi.c =================================================================== --- src/os/win32/fosi.c (revision 0) +++ src/os/win32/fosi.c (revision 0) @@ -0,0 +1,50 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#include "fosi.h" +#include +#include + +#undef rtos_printf +int rtos_printf(const char *fmt, ...) +{ + va_list list; + char printkbuf [2000]; + printkbuf[0] = '\0'; + va_start (list, fmt); + vsprintf(printkbuf, fmt, list); + va_end (list); + return printf(printkbuf); +} + + Index: src/os/win32/gnuthreads.cpp =================================================================== --- src/os/win32/gnuthreads.cpp (revision 0) +++ src/os/win32/gnuthreads.cpp (revision 0) @@ -0,0 +1,46 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + + +#include + +namespace RTT +{ namespace OS { + + const int LowestPriority = 1; + + const int HighestPriority = 99; + + const int IncreasePriority = 1; + +}} Index: src/os/win32/fosi.h =================================================================== --- src/os/win32/fosi.h (revision 0) +++ src/os/win32/fosi.h (revision 0) @@ -0,0 +1,281 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#ifndef __FOSI_H +#define __FOSI_H + +#define HAVE_FOSI_API + +#ifdef __cplusplus +extern "C" +{ +#endif + + +#include +#include +#include +#include +#include +#include +#include + + // Time Related +#include +#include +#include + + typedef unsigned int uint; + + typedef long long NANO_TIME; + typedef long long TICK_TIME; + + const TICK_TIME InfiniteTicks = LLONG_MAX; + const NANO_TIME InfiniteNSecs = LLONG_MAX; + const double InfiniteSeconds = DBL_MAX; + + typedef struct { + pthread_t thread; + pthread_attr_t attr; + + NANO_TIME periodMark; + NANO_TIME period; + + char* name; + + int priority; + } RTOS_TASK; + + + // support only OTHER scehduler +#define ORO_SCHED_RT SCHED_OTHER +#define ORO_SCHED_OTHER SCHED_OTHER + + /* + * Time Related stuff + */ +#include +#include +#include + + typedef struct timespec TIME_SPEC; + + /* fake clock_gettime for systems like darwin */ + #define CLOCK_REALTIME 0 + inline int clock_gettime(int clk_id /*ignored*/, struct timespec *tp) + { + struct timeval now; + int rv = gettimeofday(&now, NULL); + if (rv != 0){ + tp->tv_sec = 0; + tp->tv_nsec = 0; + return rv; + } + tp->tv_sec = now.tv_sec; + tp->tv_nsec = now.tv_usec * 1000; + return 0; + } + + // high-resolution time to timespec + inline TIME_SPEC ticks2timespec(TICK_TIME hrt) + { + TIME_SPEC timevl; + timevl.tv_sec = hrt / 1000000000LL; + timevl.tv_nsec = hrt % 1000000000LL; + return timevl; + } + + inline NANO_TIME rtos_get_time_ns( void ) + { + TIME_SPEC tv; + clock_gettime(CLOCK_REALTIME, &tv); + // we can not include the C++ Time.hpp header ! +#ifdef __cplusplus + return NANO_TIME( tv.tv_sec ) * 1000000000LL + NANO_TIME( tv.tv_nsec ); +#else + return ( NANO_TIME ) ( tv.tv_sec * 1000000000LL ) + ( NANO_TIME ) ( tv.tv_nsec ); +#endif + } + + /** + * This function should return ticks, + * but we use ticks == nsecs in userspace + */ + inline NANO_TIME rtos_get_time_ticks() + { + return rtos_get_time_ns(); + } + + inline int rtos_nanosleep( const TIME_SPEC * rqtp, TIME_SPEC * rmtp ) + { + return usleep(rqtp->tv_nsec/1000L); + } + + inline long long nano2ticks( long long nano ) + { + return nano; + } + + inline long long ticks2nano( long long count ) + { + return count; + } + + typedef sem_t rt_sem_t; + + static inline int rtos_sem_init(rt_sem_t* m, int value ) + { + return sem_init(m, 0, value); + } + + static inline int rtos_sem_destroy(rt_sem_t* m ) + { + return sem_destroy(m); + } + + static inline int rtos_sem_signal(rt_sem_t* m ) + { + return sem_post(m); + } + + static inline int rtos_sem_wait(rt_sem_t* m ) + { + return sem_wait(m); + } + + static inline int rtos_sem_trywait(rt_sem_t* m ) + { + return sem_trywait(m); + } + + static inline int rtos_sem_wait_timed(rt_sem_t* m, NANO_TIME delay ) + { + TIME_SPEC timevl, delayvl; + clock_gettime(CLOCK_REALTIME, &timevl); + delayvl = ticks2timespec(delay); + + // add current time with delay, detect&correct overflows. + timevl.tv_sec += delayvl.tv_sec; + timevl.tv_nsec += delayvl.tv_nsec; + if ( timevl.tv_nsec >= 1000000000) { + ++timevl.tv_sec; + timevl.tv_nsec -= 1000000000; + } + + assert( timevl.tv_nsec < 1000000000 ); + + return sem_timedwait( m, &timevl); + } + + static inline int rtos_sem_wait_until(rt_sem_t* m, NANO_TIME abs_time ) + { + TIME_SPEC arg_time = ticks2timespec( abs_time ); + return sem_timedwait( m, &arg_time); + } + + static inline int rtos_sem_value(rt_sem_t* m ) + { + int val = 0; + if ( sem_getvalue(m, &val) == 0) + return val; + return -1; + } + + + /* + * Mutex functions + */ + typedef pthread_mutex_t rt_mutex_t; + typedef pthread_mutex_t rt_rec_mutex_t; + + static inline int rtos_mutex_init(rt_mutex_t* m) + { + return pthread_mutex_init(m, 0 ); + } + + static inline int rtos_mutex_destroy(rt_mutex_t* m ) + { + return pthread_mutex_destroy(m); + } + + static inline int rtos_mutex_rec_init(rt_mutex_t* m) + { + pthread_mutexattr_t ma_t; + pthread_mutexattr_init(&ma_t); + pthread_mutexattr_settype(&ma_t,PTHREAD_MUTEX_RECURSIVE); + return pthread_mutex_init(m, &ma_t ); + } + + static inline int rtos_mutex_rec_destroy(rt_mutex_t* m ) + { + return pthread_mutex_destroy(m); + } + + static inline int rtos_mutex_lock( rt_mutex_t* m) + { + return pthread_mutex_lock(m); + } + + static inline int rtos_mutex_rec_lock( rt_mutex_t* m) + { + return pthread_mutex_lock(m); + } + + static inline int rtos_mutex_trylock( rt_mutex_t* m) + { + return pthread_mutex_trylock(m); + } + + static inline int rtos_mutex_rec_trylock( rt_mutex_t* m) + { + return pthread_mutex_trylock(m); + } + + static inline int rtos_mutex_unlock( rt_mutex_t* m) + { + return pthread_mutex_unlock(m); + } + + static inline int rtos_mutex_rec_unlock( rt_mutex_t* m) + { + return pthread_mutex_unlock(m); + } + + +#define rtos_printf printf + +#ifdef __cplusplus +} + +#endif +#endif Index: src/os/win32/win32.h =================================================================== --- src/os/win32/win32.h (revision 0) +++ src/os/win32/win32.h (revision 0) @@ -0,0 +1,37 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + +/** + * @file win32.h + * This file indicates that the Windows 32-bit version of + * orocos headers is installed. + */ Index: src/os/win32/CMakeLists.txt =================================================================== --- src/os/win32/CMakeLists.txt (revision 0) +++ src/os/win32/CMakeLists.txt (revision 0) @@ -0,0 +1,7 @@ +IF (OROCOS_TARGET STREQUAL "win32") + FILE( GLOB CPPS [^.]*.cpp [^.]*.c) + FILE( GLOB HPPS [^.]*.hpp [^.]*.h [^.]*.inl) + + GLOBAL_ADD_INCLUDE( rtt/os/win32 ${HPPS}) + GLOBAL_ADD_SRC( ${CPPS}) +ENDIF (OROCOS_TARGET STREQUAL "win32") Index: src/os/win32/fosi_internal.cpp =================================================================== --- src/os/win32/fosi_internal.cpp (revision 0) +++ src/os/win32/fosi_internal.cpp (revision 0) @@ -0,0 +1,248 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#include "../ThreadInterface.hpp" +#include "fosi.h" +#include "../fosi_internal_interface.hpp" +#include "../../Logger.hpp" +#include + +#define INTERNAL_QUAL + +namespace RTT +{ namespace OS { namespace detail { + +static const pthread_t zeroThread = {0,0}; + + INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK* main_task) + { + const char* name = "main"; + main_task->name = strcpy( (char*)malloc( (strlen(name) + 1) * sizeof(char)), name); + memset(&main_task->thread, 0, sizeof(main_task->thread)); + pthread_attr_init( &(main_task->attr) ); + struct sched_param sp; + sp.sched_priority=0; + // Set priority + // fixme check return value and bail out if necessary + pthread_attr_setschedparam(&(main_task->attr), &sp); + main_task->priority = sp.sched_priority; + return 0; + } + + INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK* main_task) + { + pthread_attr_destroy( &(main_task->attr) ); + free( main_task->name ); + return 0; + } + + INTERNAL_QUAL int rtos_task_create(RTOS_TASK* task, + int priority, + const char * name, + int sched_type, + void * (*start_routine)(void *), + ThreadInterface* obj) + { + int rv; // return value + rtos_task_check_priority( &sched_type, &priority ); + // Save priority internally, since the pthread_attr* calls are broken ! + // we will pick it up later in rtos_task_set_scheduler(). + task->priority = priority; + + // Set name + if ( strlen(name) == 0 ) + name = "Thread"; + task->name = strcpy( (char*)malloc( (strlen(name) + 1) * sizeof(char)), name); + + if ( (rv = pthread_attr_init(&(task->attr))) != 0 ){ + return rv; + } + // Set scheduler type (_before_ assigning priorities!) + if ( (rv = pthread_attr_setschedpolicy(&(task->attr), sched_type)) != 0){ + return rv; + } + pthread_attr_getschedpolicy(&(task->attr), &rv ); + assert( rv == sched_type ); + + struct sched_param sp; + sp.sched_priority=priority; + // Set priority + if ( (rv = pthread_attr_setschedparam(&(task->attr), &sp)) != 0 ){ + return rv; + } + rv = pthread_create(&(task->thread), &(task->attr), start_routine, obj); + // presume that p is unique!? + log(Debug) <<"Created Posix thread "<< task->thread.p <thread, &zeroThread, sizeof(task->thread))) && + rtos_task_check_scheduler( &sched_type) == -1 ) + return -1; + // if sched_type is different, the priority must change as well. + if (pthread_getschedparam(task->thread, &policy, ¶m) == 0) { + // now update the priority + param.sched_priority = task->priority; + rtos_task_check_priority( &sched_type, ¶m.sched_priority ); + // write new policy: + return pthread_setschedparam( task->thread, sched_type, ¶m); + } + return -1; + } + + INTERNAL_QUAL int rtos_task_get_scheduler(const RTOS_TASK* task) + { + int policy = -1; + struct sched_param param; + // first retrieve thread scheduling parameters: + if ( task && + (0 != memcmp(&task->thread, &zeroThread, sizeof(task->thread))) && + pthread_getschedparam(task->thread, &policy, ¶m) == 0) + return policy; + return -1; + } + + INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK* mytask, NANO_TIME nanosecs ) + { + // set period + mytask->period = nanosecs; + // set next wake-up time. + mytask->periodMark = rtos_get_time_ns() + nanosecs; + } + + INTERNAL_QUAL void rtos_task_set_period( RTOS_TASK* mytask, NANO_TIME nanosecs ) + { + mytask->period = nanosecs; + mytask->periodMark = rtos_get_time_ns() + nanosecs; + } + + INTERNAL_QUAL NANO_TIME rtos_task_get_period(const RTOS_TASK* t) + { + return t->period; + } + + INTERNAL_QUAL int rtos_task_wait_period( RTOS_TASK* task ) + { + if ( task->period == 0 ) + return 0; + + //rtos_printf("Time is %lld nsec, Mark is %lld nsec.\n",rtos_get_time_ns(), task->periodMark ); + // CALCULATE in nsecs + NANO_TIME timeRemaining = task->periodMark - rtos_get_time_ns(); + + if ( timeRemaining > 0 ) { + //rtos_printf("Waiting for %lld nsec\n",timeRemaining); + TIME_SPEC ts( ticks2timespec( timeRemaining ) ); + rtos_nanosleep( &ts , NULL ); + } + + // next wake-up time : + task->periodMark += task->period; + + return 0; + } + + INTERNAL_QUAL void rtos_task_delete(RTOS_TASK* mytask) + { + pthread_join( mytask->thread, 0); + pthread_attr_destroy( &(mytask->attr) ); + free(mytask->name); + } + + INTERNAL_QUAL int rtos_task_check_scheduler(int* scheduler) + { + *scheduler = SCHED_OTHER; + return -1; + } + + INTERNAL_QUAL int rtos_task_check_priority(int* scheduler, int* priority) + { + *priority = 0; + *scheduler = ORO_SCHED_OTHER; + return -1; + } + + INTERNAL_QUAL int rtos_task_set_priority(RTOS_TASK * task, int priority) + { + int policy = 0; + struct sched_param param; + // first retrieve thread scheduling parameters: + if( task && + (0 != memcmp(&task->thread, &zeroThread, sizeof(task->thread))) && + pthread_getschedparam(task->thread, &policy, ¶m) == 0) { + if ( rtos_task_check_priority( &policy, &priority ) != 0 ) + return -1; + param.sched_priority = priority; + task->priority = priority; // store for set_scheduler + // write new policy: + return pthread_setschedparam( task->thread, policy, ¶m); + } + return -1; + } + + INTERNAL_QUAL int rtos_task_get_priority(const RTOS_TASK *task) + { + // if sched_other, return the 'virtual' priority + int policy = 0; + struct sched_param param; + // first retrieve thread scheduling parameters: + if ( task == 0 ) + return -1; + + if ((0 == memcmp(&task->thread, &zeroThread, sizeof(task->thread))) || + pthread_getschedparam(task->thread, &policy, ¶m) != 0) + return task->priority; + return param.sched_priority; + } + + INTERNAL_QUAL const char * rtos_task_get_name(const RTOS_TASK* task) + { + return task->name; + } + + } +}} +#undef INTERNAL_QUAL Index: src/os/win32/CMakeLists.txt =================================================================== --- src/os/win32/CMakeLists.txt (revision 0) +++ src/os/win32/CMakeLists.txt (revision 0) @@ -0,0 +1,7 @@ +IF (OROCOS_TARGET STREQUAL "win32") + FILE( GLOB CPPS [^.]*.cpp [^.]*.c) + FILE( GLOB HPPS [^.]*.hpp [^.]*.h [^.]*.inl) + + GLOBAL_ADD_INCLUDE( rtt/os/win32 ${HPPS}) + GLOBAL_ADD_SRC( ${CPPS}) +ENDIF (OROCOS_TARGET STREQUAL "win32") Index: src/os/win32/fosi.c =================================================================== --- src/os/win32/fosi.c (revision 0) +++ src/os/win32/fosi.c (revision 0) @@ -0,0 +1,50 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#include "fosi.h" +#include +#include + +#undef rtos_printf +int rtos_printf(const char *fmt, ...) +{ + va_list list; + char printkbuf [2000]; + printkbuf[0] = '\0'; + va_start (list, fmt); + vsprintf(printkbuf, fmt, list); + va_end (list); + return printf(printkbuf); +} + + Index: src/os/win32/fosi.h =================================================================== --- src/os/win32/fosi.h (revision 0) +++ src/os/win32/fosi.h (revision 0) @@ -0,0 +1,281 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#ifndef __FOSI_H +#define __FOSI_H + +#define HAVE_FOSI_API + +#ifdef __cplusplus +extern "C" +{ +#endif + + +#include +#include +#include +#include +#include +#include +#include + + // Time Related +#include +#include +#include + + typedef unsigned int uint; + + typedef long long NANO_TIME; + typedef long long TICK_TIME; + + const TICK_TIME InfiniteTicks = LLONG_MAX; + const NANO_TIME InfiniteNSecs = LLONG_MAX; + const double InfiniteSeconds = DBL_MAX; + + typedef struct { + pthread_t thread; + pthread_attr_t attr; + + NANO_TIME periodMark; + NANO_TIME period; + + char* name; + + int priority; + } RTOS_TASK; + + + // support only OTHER scehduler +#define ORO_SCHED_RT SCHED_OTHER +#define ORO_SCHED_OTHER SCHED_OTHER + + /* + * Time Related stuff + */ +#include +#include +#include + + typedef struct timespec TIME_SPEC; + + /* fake clock_gettime for systems like darwin */ + #define CLOCK_REALTIME 0 + inline int clock_gettime(int clk_id /*ignored*/, struct timespec *tp) + { + struct timeval now; + int rv = gettimeofday(&now, NULL); + if (rv != 0){ + tp->tv_sec = 0; + tp->tv_nsec = 0; + return rv; + } + tp->tv_sec = now.tv_sec; + tp->tv_nsec = now.tv_usec * 1000; + return 0; + } + + // high-resolution time to timespec + inline TIME_SPEC ticks2timespec(TICK_TIME hrt) + { + TIME_SPEC timevl; + timevl.tv_sec = hrt / 1000000000LL; + timevl.tv_nsec = hrt % 1000000000LL; + return timevl; + } + + inline NANO_TIME rtos_get_time_ns( void ) + { + TIME_SPEC tv; + clock_gettime(CLOCK_REALTIME, &tv); + // we can not include the C++ Time.hpp header ! +#ifdef __cplusplus + return NANO_TIME( tv.tv_sec ) * 1000000000LL + NANO_TIME( tv.tv_nsec ); +#else + return ( NANO_TIME ) ( tv.tv_sec * 1000000000LL ) + ( NANO_TIME ) ( tv.tv_nsec ); +#endif + } + + /** + * This function should return ticks, + * but we use ticks == nsecs in userspace + */ + inline NANO_TIME rtos_get_time_ticks() + { + return rtos_get_time_ns(); + } + + inline int rtos_nanosleep( const TIME_SPEC * rqtp, TIME_SPEC * rmtp ) + { + return usleep(rqtp->tv_nsec/1000L); + } + + inline long long nano2ticks( long long nano ) + { + return nano; + } + + inline long long ticks2nano( long long count ) + { + return count; + } + + typedef sem_t rt_sem_t; + + static inline int rtos_sem_init(rt_sem_t* m, int value ) + { + return sem_init(m, 0, value); + } + + static inline int rtos_sem_destroy(rt_sem_t* m ) + { + return sem_destroy(m); + } + + static inline int rtos_sem_signal(rt_sem_t* m ) + { + return sem_post(m); + } + + static inline int rtos_sem_wait(rt_sem_t* m ) + { + return sem_wait(m); + } + + static inline int rtos_sem_trywait(rt_sem_t* m ) + { + return sem_trywait(m); + } + + static inline int rtos_sem_wait_timed(rt_sem_t* m, NANO_TIME delay ) + { + TIME_SPEC timevl, delayvl; + clock_gettime(CLOCK_REALTIME, &timevl); + delayvl = ticks2timespec(delay); + + // add current time with delay, detect&correct overflows. + timevl.tv_sec += delayvl.tv_sec; + timevl.tv_nsec += delayvl.tv_nsec; + if ( timevl.tv_nsec >= 1000000000) { + ++timevl.tv_sec; + timevl.tv_nsec -= 1000000000; + } + + assert( timevl.tv_nsec < 1000000000 ); + + return sem_timedwait( m, &timevl); + } + + static inline int rtos_sem_wait_until(rt_sem_t* m, NANO_TIME abs_time ) + { + TIME_SPEC arg_time = ticks2timespec( abs_time ); + return sem_timedwait( m, &arg_time); + } + + static inline int rtos_sem_value(rt_sem_t* m ) + { + int val = 0; + if ( sem_getvalue(m, &val) == 0) + return val; + return -1; + } + + + /* + * Mutex functions + */ + typedef pthread_mutex_t rt_mutex_t; + typedef pthread_mutex_t rt_rec_mutex_t; + + static inline int rtos_mutex_init(rt_mutex_t* m) + { + return pthread_mutex_init(m, 0 ); + } + + static inline int rtos_mutex_destroy(rt_mutex_t* m ) + { + return pthread_mutex_destroy(m); + } + + static inline int rtos_mutex_rec_init(rt_mutex_t* m) + { + pthread_mutexattr_t ma_t; + pthread_mutexattr_init(&ma_t); + pthread_mutexattr_settype(&ma_t,PTHREAD_MUTEX_RECURSIVE); + return pthread_mutex_init(m, &ma_t ); + } + + static inline int rtos_mutex_rec_destroy(rt_mutex_t* m ) + { + return pthread_mutex_destroy(m); + } + + static inline int rtos_mutex_lock( rt_mutex_t* m) + { + return pthread_mutex_lock(m); + } + + static inline int rtos_mutex_rec_lock( rt_mutex_t* m) + { + return pthread_mutex_lock(m); + } + + static inline int rtos_mutex_trylock( rt_mutex_t* m) + { + return pthread_mutex_trylock(m); + } + + static inline int rtos_mutex_rec_trylock( rt_mutex_t* m) + { + return pthread_mutex_trylock(m); + } + + static inline int rtos_mutex_unlock( rt_mutex_t* m) + { + return pthread_mutex_unlock(m); + } + + static inline int rtos_mutex_rec_unlock( rt_mutex_t* m) + { + return pthread_mutex_unlock(m); + } + + +#define rtos_printf printf + +#ifdef __cplusplus +} + +#endif +#endif Index: src/os/win32/fosi_internal.cpp =================================================================== --- src/os/win32/fosi_internal.cpp (revision 0) +++ src/os/win32/fosi_internal.cpp (revision 0) @@ -0,0 +1,248 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + +#include "../ThreadInterface.hpp" +#include "fosi.h" +#include "../fosi_internal_interface.hpp" +#include "../../Logger.hpp" +#include + +#define INTERNAL_QUAL + +namespace RTT +{ namespace OS { namespace detail { + +static const pthread_t zeroThread = {0,0}; + + INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK* main_task) + { + const char* name = "main"; + main_task->name = strcpy( (char*)malloc( (strlen(name) + 1) * sizeof(char)), name); + memset(&main_task->thread, 0, sizeof(main_task->thread)); + pthread_attr_init( &(main_task->attr) ); + struct sched_param sp; + sp.sched_priority=0; + // Set priority + // fixme check return value and bail out if necessary + pthread_attr_setschedparam(&(main_task->attr), &sp); + main_task->priority = sp.sched_priority; + return 0; + } + + INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK* main_task) + { + pthread_attr_destroy( &(main_task->attr) ); + free( main_task->name ); + return 0; + } + + INTERNAL_QUAL int rtos_task_create(RTOS_TASK* task, + int priority, + const char * name, + int sched_type, + void * (*start_routine)(void *), + ThreadInterface* obj) + { + int rv; // return value + rtos_task_check_priority( &sched_type, &priority ); + // Save priority internally, since the pthread_attr* calls are broken ! + // we will pick it up later in rtos_task_set_scheduler(). + task->priority = priority; + + // Set name + if ( strlen(name) == 0 ) + name = "Thread"; + task->name = strcpy( (char*)malloc( (strlen(name) + 1) * sizeof(char)), name); + + if ( (rv = pthread_attr_init(&(task->attr))) != 0 ){ + return rv; + } + // Set scheduler type (_before_ assigning priorities!) + if ( (rv = pthread_attr_setschedpolicy(&(task->attr), sched_type)) != 0){ + return rv; + } + pthread_attr_getschedpolicy(&(task->attr), &rv ); + assert( rv == sched_type ); + + struct sched_param sp; + sp.sched_priority=priority; + // Set priority + if ( (rv = pthread_attr_setschedparam(&(task->attr), &sp)) != 0 ){ + return rv; + } + rv = pthread_create(&(task->thread), &(task->attr), start_routine, obj); + // presume that p is unique!? + log(Debug) <<"Created Posix thread "<< task->thread.p <thread, &zeroThread, sizeof(task->thread))) && + rtos_task_check_scheduler( &sched_type) == -1 ) + return -1; + // if sched_type is different, the priority must change as well. + if (pthread_getschedparam(task->thread, &policy, ¶m) == 0) { + // now update the priority + param.sched_priority = task->priority; + rtos_task_check_priority( &sched_type, ¶m.sched_priority ); + // write new policy: + return pthread_setschedparam( task->thread, sched_type, ¶m); + } + return -1; + } + + INTERNAL_QUAL int rtos_task_get_scheduler(const RTOS_TASK* task) + { + int policy = -1; + struct sched_param param; + // first retrieve thread scheduling parameters: + if ( task && + (0 != memcmp(&task->thread, &zeroThread, sizeof(task->thread))) && + pthread_getschedparam(task->thread, &policy, ¶m) == 0) + return policy; + return -1; + } + + INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK* mytask, NANO_TIME nanosecs ) + { + // set period + mytask->period = nanosecs; + // set next wake-up time. + mytask->periodMark = rtos_get_time_ns() + nanosecs; + } + + INTERNAL_QUAL void rtos_task_set_period( RTOS_TASK* mytask, NANO_TIME nanosecs ) + { + mytask->period = nanosecs; + mytask->periodMark = rtos_get_time_ns() + nanosecs; + } + + INTERNAL_QUAL NANO_TIME rtos_task_get_period(const RTOS_TASK* t) + { + return t->period; + } + + INTERNAL_QUAL int rtos_task_wait_period( RTOS_TASK* task ) + { + if ( task->period == 0 ) + return 0; + + //rtos_printf("Time is %lld nsec, Mark is %lld nsec.\n",rtos_get_time_ns(), task->periodMark ); + // CALCULATE in nsecs + NANO_TIME timeRemaining = task->periodMark - rtos_get_time_ns(); + + if ( timeRemaining > 0 ) { + //rtos_printf("Waiting for %lld nsec\n",timeRemaining); + TIME_SPEC ts( ticks2timespec( timeRemaining ) ); + rtos_nanosleep( &ts , NULL ); + } + + // next wake-up time : + task->periodMark += task->period; + + return 0; + } + + INTERNAL_QUAL void rtos_task_delete(RTOS_TASK* mytask) + { + pthread_join( mytask->thread, 0); + pthread_attr_destroy( &(mytask->attr) ); + free(mytask->name); + } + + INTERNAL_QUAL int rtos_task_check_scheduler(int* scheduler) + { + *scheduler = SCHED_OTHER; + return -1; + } + + INTERNAL_QUAL int rtos_task_check_priority(int* scheduler, int* priority) + { + *priority = 0; + *scheduler = ORO_SCHED_OTHER; + return -1; + } + + INTERNAL_QUAL int rtos_task_set_priority(RTOS_TASK * task, int priority) + { + int policy = 0; + struct sched_param param; + // first retrieve thread scheduling parameters: + if( task && + (0 != memcmp(&task->thread, &zeroThread, sizeof(task->thread))) && + pthread_getschedparam(task->thread, &policy, ¶m) == 0) { + if ( rtos_task_check_priority( &policy, &priority ) != 0 ) + return -1; + param.sched_priority = priority; + task->priority = priority; // store for set_scheduler + // write new policy: + return pthread_setschedparam( task->thread, policy, ¶m); + } + return -1; + } + + INTERNAL_QUAL int rtos_task_get_priority(const RTOS_TASK *task) + { + // if sched_other, return the 'virtual' priority + int policy = 0; + struct sched_param param; + // first retrieve thread scheduling parameters: + if ( task == 0 ) + return -1; + + if ((0 == memcmp(&task->thread, &zeroThread, sizeof(task->thread))) || + pthread_getschedparam(task->thread, &policy, ¶m) != 0) + return task->priority; + return param.sched_priority; + } + + INTERNAL_QUAL const char * rtos_task_get_name(const RTOS_TASK* task) + { + return task->name; + } + + } +}} +#undef INTERNAL_QUAL Index: src/os/win32/gnuthreads.cpp =================================================================== --- src/os/win32/gnuthreads.cpp (revision 0) +++ src/os/win32/gnuthreads.cpp (revision 0) @@ -0,0 +1,46 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + + + +#include + +namespace RTT +{ namespace OS { + + const int LowestPriority = 1; + + const int HighestPriority = 99; + + const int IncreasePriority = 1; + +}} Index: src/os/win32/win32.h =================================================================== --- src/os/win32/win32.h (revision 0) +++ src/os/win32/win32.h (revision 0) @@ -0,0 +1,37 @@ +/*************************************************************************** + Copyright (c) 2009 S Roderick + (remove the x's above) + + *************************************************************************** + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public * + * License as published by the Free Software Foundation; * + * version 2 of the License. * + * * + * As a special exception, you may use this file as part of a free * + * software library without restriction. Specifically, if other files * + * instantiate templates or use macros or inline functions from this * + * file, or you compile this file and link it with other files to * + * produce an executable, this file does not by itself cause the * + * resulting executable to be covered by the GNU General Public * + * License. This exception does not however invalidate any other * + * reasons why the executable file might be covered by the GNU General * + * Public License. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307 USA * + * * + ***************************************************************************/ + +/** + * @file win32.h + * This file indicates that the Windows 32-bit version of + * orocos headers is installed. + */ Index: src/rtt-config.h.in =================================================================== --- src/rtt-config.h.in (revision 29869) +++ src/rtt-config.h.in (working copy) @@ -47,16 +47,39 @@ // Use RTT_HIDE to explicitly hide a symbol # define RTT_HIDE __attribute__((visibility("hidden"))) + // Use RTT_WEAK_USER to weaken a symbol in client code. +# define RTT_WEAK_USER # else # define RTT_API # define RTT_EXPORT __attribute__((visibility("default"))) # define RTT_HIDE __attribute__((visibility("hidden"))) +# define RTT_WEAK_USER __attribute__((weak)) # endif #else - // NOT GNU +/* +# if defined(__WIN32__) || defined(__CYGWIN__) +# if defined(RTT_DLL_EXPORT) +# define RTT_API __declspec(dllexport) +# define RTT_EXPORT __declspec(dllexport) +# define RTT_HIDE +# define RTT_WEAK_USER +# else +# define RTT_API __declspec(dllimport) +# define RTT_EXPORT __declspec(dllimport) +# define RTT_HIDE +# define RTT_WEAK_USER +//# define RTT_WEAK_USER __attribute__((weak)) //This makes ld segfault on cygwin :-( +# endif +# else + // UNKNOWN +#warning "Unknown platform, can't export symbols." +*/ # define RTT_API +# define RTT_API # define RTT_EXPORT # define RTT_HIDE +# define RTT_WEAK_USER +//#endif #endif #endif Index: tests/buffers_test.cpp =================================================================== --- tests/buffers_test.cpp (revision 29869) +++ tests/buffers_test.cpp (working copy) @@ -23,6 +23,10 @@ #include #include +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + using namespace std; // Registers the fixture into the 'registry' Index: tests/CMakeLists.txt =================================================================== --- tests/CMakeLists.txt (revision 29869) +++ tests/CMakeLists.txt (working copy) @@ -34,49 +34,57 @@ ADD_EXECUTABLE( core-test ${DO_EXCLUDE} test-runner.cpp time_test.cpp property_test.cpp logger_test.cpp buffers_test.cpp ) TARGET_LINK_LIBRARIES( core-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( core-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( core-test core-test ) ADD_EXECUTABLE( task-test ${DO_EXCLUDE} test-runner.cpp tasks_test.cpp taskthread_test.cpp tasks_multiple_test.cpp ) TARGET_LINK_LIBRARIES( task-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( task-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( task-test task-test ) ADD_EXECUTABLE( event-test ${DO_EXCLUDE} test-runner.cpp event_test.cpp eventservice_test.cpp ) TARGET_LINK_LIBRARIES( event-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( event-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( event-test event-test ) ADD_EXECUTABLE( taskcontext-test ${DO_EXCLUDE} test-runner.cpp generictask_test.cpp generictask_test_2.cpp generictask_test_3.cpp ) TARGET_LINK_LIBRARIES( taskcontext-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( taskcontext-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( taskcontext-test taskcontext-test ) ADD_EXECUTABLE( parser-test ${DO_EXCLUDE} test-runner.cpp types_test.cpp template_factory_test.cpp dispatch_test.cpp ) TARGET_LINK_LIBRARIES( parser-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( parser-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( parser-test parser-test ) ADD_EXECUTABLE( program-test ${DO_EXCLUDE} test-runner.cpp program_test.cpp function_test.cpp ) TARGET_LINK_LIBRARIES( program-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT}) SET_TARGET_PROPERTIES( program-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( program-test program-test ) ADD_EXECUTABLE( state-test ${DO_EXCLUDE} test-runner.cpp state_test.cpp ) TARGET_LINK_LIBRARIES( state-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( state-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( state-test state-test ) ADD_EXECUTABLE( dev-test ${DO_EXCLUDE} test-runner.cpp dev_test.cpp ) TARGET_LINK_LIBRARIES( dev-test orocos-rtt-${OROCOS_TARGET} ${CPPUNIT} ) SET_TARGET_PROPERTIES( dev-test PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}") + COMPILE_FLAGS "${CMAKE_CXX_FLAGS_ADD} ${RTT_CFLAGS} -DOROCOS_TARGET=${OROCOS_TARGET}" + LINK_FLAGS "${RTT_LINKFLAGS}") ADD_TEST( dev-test dev-test ) IF(ENABLE_CORBA) Index: tests/event_test.cpp =================================================================== --- tests/event_test.cpp (revision 29869) +++ tests/event_test.cpp (working copy) @@ -31,6 +31,10 @@ #include #include +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( EventTest ); Index: tests/logger_test.cpp =================================================================== --- tests/logger_test.cpp (revision 29869) +++ tests/logger_test.cpp (working copy) @@ -24,6 +24,10 @@ #include #include "os/PeriodicThread.hpp" +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + using namespace boost; using namespace std; Index: tests/tasks_multiple_test.cpp =================================================================== --- tests/tasks_multiple_test.cpp (revision 29869) +++ tests/tasks_multiple_test.cpp (working copy) @@ -23,6 +23,11 @@ #include "Logger.hpp" #include + +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + using namespace std; using namespace RTT; Index: tests/tasks_test.cpp =================================================================== --- tests/tasks_test.cpp (revision 29869) +++ tests/tasks_test.cpp (working copy) @@ -27,6 +27,10 @@ #include +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + using namespace std; using namespace boost; Index: tests/taskthread_test.cpp =================================================================== --- tests/taskthread_test.cpp (revision 29869) +++ tests/taskthread_test.cpp (working copy) @@ -30,6 +30,10 @@ #include #include +#ifdef OROPKG_OS_WIN32 +#define sleep(x) usleep((x) * 1000000L) +#endif + using namespace std; // Registers the fixture into the 'registry' @@ -218,7 +222,7 @@ rtsched = ORO_SCHED_OTHER; if ( OS::CheckPriority( rtsched, bprio ) ) { CPPUNIT_ASSERT( mtask.thread() != m3task.thread() ); - CPPUNIT_ASSERT_EQUAL( ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); + CPPUNIT_ASSERT_EQUAL( (int)ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); } } @@ -271,7 +275,7 @@ if ( OS::CheckPriority( rtsched, bprio ) ) { NonPeriodicActivity m3task(ORO_SCHED_OTHER, 15); CPPUNIT_ASSERT( mtask.thread() != m3task.thread() ); - CPPUNIT_ASSERT_EQUAL( ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); + CPPUNIT_ASSERT_EQUAL( (int)ORO_SCHED_OTHER, m3task.thread()->getScheduler() ); } } Index: tests/test-runner.cpp =================================================================== --- tests/test-runner.cpp (revision 29869) +++ tests/test-runner.cpp (working copy) @@ -20,6 +20,9 @@ #include #include +#include +#include +#include #include #include #include @@ -46,6 +49,10 @@ // Change the default outputter to a compiler error format outputter runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); +#if 1 + CppUnit::TextTestProgressListener progress; + runner.eventManager().addListener( &progress ); +#endif // Run the tests. bool wasSucessful = runner.run();