os_posix_time.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include "icl_core/os_posix_time.h"
24 
25 #include <unistd.h>
26 
27 #include "icl_core/os_lxrt.h"
28 
29 #ifdef _SYSTEM_LXRT_
30 # include <stdlib.h>
31 # include <rtai_lxrt.h>
32 # include <rtai_posix.h>
33 # if defined(_SYSTEM_LXRT_33_) || defined(_SYSTEM_LXRT_35_)
34 # include <mca_lxrt_extension.h>
35 # endif
36 #endif
37 
38 namespace icl_core {
39 namespace os {
40 namespace hidden_posix {
41 
42 void gettimeofday(struct timespec *time)
43 {
44 #ifdef _SYSTEM_LXRT_
45  if (isThisLxrtTask())
46  {
47 # if defined(_SYSTEM_LXRT_33_) || defined(_SYSTEM_LXRT_35_)
48  struct timeval tv;
49  mcalxrt_do_gettimeofday(&tv);
50  time->tv_sec = tv.tv_sec;
51  time->tv_nsec = tv.tv_usec * 1000;
52 # else
53  RTIME real_time = rt_get_real_time_ns();
54  nanos2timespec(real_time, time);
55 # endif
56  }
57  else
58 #endif
59  {
60  struct timeval tv;
61  gettimeofday(&tv, 0);
62  time->tv_sec = tv.tv_sec;
63  time->tv_nsec = tv.tv_usec * 1000;
64  }
65 }
66 
67 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
68 {
69 #ifdef _SYSTEM_LXRT_
70  if (isThisLxrtTask())
71  {
72  rt_sleep(nano2count(RTIME(1000000*rqtp->tv_sec + rqtp->tv_nsec)));
73  if (rmtp != NULL)
74  {
75  // TODO: Do this right!
76  rmtp->tv_sec = 0;
77  rmtp->tv_nsec = 0;
78  }
79  return 0;
80  }
81  else
82 #endif
83  {
84  return ::nanosleep(rqtp, rmtp);
85  }
86 }
87 
88 unsigned int sleep(unsigned int seconds)
89 {
90 #ifdef _SYSTEM_LXRT_
91  if (isThisLxrtTask())
92  {
93  rt_sleep(nano2count(RTIME(1000000000*seconds)));
94  return 0;
95  }
96  else
97 #endif
98  {
99  return ::sleep(seconds);
100  }
101 }
102 
103 int usleep(unsigned long useconds)
104 {
105 #ifdef _SYSTEM_LXRT_
106  if (isThisLxrtTask())
107  {
108  rt_sleep(nano2count(RTIME(1000*useconds)));
109  return 0;
110  }
111  else
112 #endif
113  {
114  return ::usleep(useconds);
115  }
116 }
117 
118 }
119 }
120 }
Posix implementation of the global functions for time manipulation,.
time_t tv_sec
Seconds.
Definition: os_win32_time.h:36
unsigned int sleep(unsigned int seconds)
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
long tv_nsec
Nanoseconds.
Definition: os_win32_time.h:38
Contains global LXRT functions.
bool isThisLxrtTask()
Definition: os_lxrt.cpp:150
void gettimeofday(struct timespec *time)
int usleep(unsigned long useconds)


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58