FreeRTOS Monotonic Clock #46
@ -48,8 +48,7 @@ ReturnValue_t Clock::getClock(timeval* time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t Clock::getClockMonotonic(timeval* time) {
|
ReturnValue_t Clock::getClockMonotonic(timeval* time) {
|
||||||
TickType_t ticks = Timekeeper::getTicks();
|
*time = Timekeeper::instance()->getMonotonicClockOffset() + getUptime();
|
||||||
*time = Timekeeper::ticksToTimeval(ticks);
|
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ ReturnValue_t Clock::getUptime(timeval* uptime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeval Clock::getUptime() {
|
timeval Clock::getUptime() {
|
||||||
TickType_t ticksSinceStart = xTaskGetTickCount();
|
TickType_t ticksSinceStart = Timekeeper::instance()->getTicks();
|
||||||
return Timekeeper::ticksToTimeval(ticksSinceStart);
|
return Timekeeper::ticksToTimeval(ticksSinceStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,13 @@ Timekeeper* Timekeeper::instance() {
|
|||||||
return myinstance;
|
return myinstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timekeeper::setOffset(const timeval& offset) { this->offset = offset; }
|
void Timekeeper::setOffset(const timeval& offset) {
|
||||||
|
if (not monotonicClockInitialized) {
|
||||||
|
this->monotonicClockOffset = offset;
|
||||||
|
monotonicClockInitialized = true;
|
||||||
|
}
|
||||||
|
this->offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
|
timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
|
||||||
timeval uptime;
|
timeval uptime;
|
||||||
@ -33,3 +39,7 @@ timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TickType_t Timekeeper::getTicks() { return xTaskGetTickCount(); }
|
TickType_t Timekeeper::getTicks() { return xTaskGetTickCount(); }
|
||||||
|
|
||||||
|
const timeval Timekeeper::getMonotonicClockOffset() const {
|
||||||
|
return monotonicClockOffset;
|
||||||
|
}
|
||||||
|
@ -18,9 +18,14 @@ class Timekeeper {
|
|||||||
Timekeeper();
|
Timekeeper();
|
||||||
|
|
||||||
timeval offset;
|
timeval offset;
|
||||||
|
// Set when offset is initialized the first time
|
||||||
|
timeval monotonicClockOffset;
|
||||||
|
bool monotonicClockInitialized = false;
|
||||||
|
|
||||||
static Timekeeper* myinstance;
|
static Timekeeper* myinstance;
|
||||||
|
|
||||||
|
void setMonotonicClockOffset(const timeval& monotonicClockOffset);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Timekeeper* instance();
|
static Timekeeper* instance();
|
||||||
virtual ~Timekeeper();
|
virtual ~Timekeeper();
|
||||||
@ -34,6 +39,7 @@ class Timekeeper {
|
|||||||
|
|
||||||
const timeval& getOffset() const;
|
const timeval& getOffset() const;
|
||||||
void setOffset(const timeval& offset);
|
void setOffset(const timeval& offset);
|
||||||
|
const timeval getMonotonicClockOffset() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ */
|
#endif /* FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ */
|
||||||
|
@ -192,6 +192,8 @@ class Clock {
|
|||||||
static MutexIF *timeMutex;
|
static MutexIF *timeMutex;
|
||||||
static uint16_t leapSeconds;
|
static uint16_t leapSeconds;
|
||||||
static bool leapSecondsSet;
|
static bool leapSecondsSet;
|
||||||
|
static bool monotonicClockInitialized;
|
||||||
|
static timeval monotonicClockOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_TIMEMANAGER_CLOCK_H_ */
|
#endif /* FSFW_TIMEMANAGER_CLOCK_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user