Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include "icl_core/os_posix_time.h"
00024
00025 #include <unistd.h>
00026
00027 #include "icl_core/os_lxrt.h"
00028
00029 #ifdef _SYSTEM_LXRT_
00030 # include <stdlib.h>
00031 # include <rtai_lxrt.h>
00032 # include <rtai_posix.h>
00033 # if defined(_SYSTEM_LXRT_33_) || defined(_SYSTEM_LXRT_35_)
00034 # include <mca_lxrt_extension.h>
00035 # endif
00036 #endif
00037
00038 namespace icl_core {
00039 namespace os {
00040 namespace hidden_posix {
00041
00042 void gettimeofday(struct timespec *time)
00043 {
00044 #ifdef _SYSTEM_LXRT_
00045 if (isThisLxrtTask())
00046 {
00047 # if defined(_SYSTEM_LXRT_33_) || defined(_SYSTEM_LXRT_35_)
00048 struct timeval tv;
00049 mcalxrt_do_gettimeofday(&tv);
00050 time->tv_sec = tv.tv_sec;
00051 time->tv_nsec = tv.tv_usec * 1000;
00052 # else
00053 RTIME real_time = rt_get_real_time_ns();
00054 nanos2timespec(real_time, time);
00055 # endif
00056 }
00057 else
00058 #endif
00059 {
00060 struct timeval tv;
00061 gettimeofday(&tv, 0);
00062 time->tv_sec = tv.tv_sec;
00063 time->tv_nsec = tv.tv_usec * 1000;
00064 }
00065 }
00066
00067 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
00068 {
00069 #ifdef _SYSTEM_LXRT_
00070 if (isThisLxrtTask())
00071 {
00072 rt_sleep(nano2count(RTIME(1000000*rqtp->tv_sec + rqtp->tv_nsec)));
00073 if (rmtp != NULL)
00074 {
00075
00076 rmtp->tv_sec = 0;
00077 rmtp->tv_nsec = 0;
00078 }
00079 return 0;
00080 }
00081 else
00082 #endif
00083 {
00084 return ::nanosleep(rqtp, rmtp);
00085 }
00086 }
00087
00088 unsigned int sleep(unsigned int seconds)
00089 {
00090 #ifdef _SYSTEM_LXRT_
00091 if (isThisLxrtTask())
00092 {
00093 rt_sleep(nano2count(RTIME(1000000000*seconds)));
00094 return 0;
00095 }
00096 else
00097 #endif
00098 {
00099 return ::sleep(seconds);
00100 }
00101 }
00102
00103 int usleep(unsigned long useconds)
00104 {
00105 #ifdef _SYSTEM_LXRT_
00106 if (isThisLxrtTask())
00107 {
00108 rt_sleep(nano2count(RTIME(1000*useconds)));
00109 return 0;
00110 }
00111 else
00112 #endif
00113 {
00114 return ::usleep(useconds);
00115 }
00116 }
00117
00118 }
00119 }
00120 }