F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
IntervalTimer.cpp
Go to the documentation of this file.
1 
9 #include <Os/IntervalTimer.hpp>
10 #include <Fw/Types/Assert.hpp>
11 #include <ctime>
12 #include <cerrno>
13 
14 namespace Os {
15  void IntervalTimer::getRawTime(RawTime& time) {
16  timespec t;
17  PlatformIntType status = clock_gettime(CLOCK_REALTIME,&t);
18  FW_ASSERT(status == 0,errno);
19  time.upper = static_cast<U32>(t.tv_sec);
20  time.lower = static_cast<U32>(t.tv_nsec);
21  }
22 
23  // Adapted from: http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html
24  // should be t1In - t2In
25  U32 IntervalTimer::getDiffUsec(const RawTime& t1In, const RawTime& t2In) {
26  RawTime result = {t1In.upper - t2In.upper, 0};
27  if (t1In.lower < t2In.lower) {
28  result.upper -= 1; // subtract nsec carry to seconds
29  result.lower = t1In.lower + (1000000000 - t2In.lower);
30  } else {
31  result.lower = t1In.lower - t2In.lower;
32  }
33  return (result.upper * 1000000) + (result.lower / 1000);
34  }
35 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
static void getRawTime(RawTime &time)