F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
IntervalTimer.cpp
Go to the documentation of this file.
1
10#include <Fw/Types/Assert.hpp>
11#include <ctime>
12#include <cerrno>
13
14namespace 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}
#define FW_ASSERT(...)
Definition Assert.hpp:7
static void getRawTime(RawTime &time)
Definition File.cpp:6