F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IntervalTimer.cpp
Go to the documentation of this file.
1 
9 #include <Os/IntervalTimer.hpp>
10 #include <Fw/Types/Assert.hpp>
11 #include <time.h>
12 #include <errno.h>
13 
14 namespace Os {
15  void IntervalTimer::getRawTime(RawTime& time) {
16  timespec t;
17 
18  FW_ASSERT(clock_gettime(CLOCK_REALTIME,&t) == 0,errno);
19  time.upper = t.tv_sec;
20  time.lower = 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 }
Os
Definition: File.cpp:7
IntervalTimer.hpp
Os::IntervalTimer::getDiffUsec
U32 getDiffUsec(void)
Definition: IntervalTimerCommon.cpp:34
Assert.hpp
Os::IntervalTimer::getRawTime
static void getRawTime(RawTime &time)
Definition: IntervalTimer.cpp:9
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9