fix: do not mix an epoch offset into the FreeRTOS monotonic clock #74

Merged
tbaumgartl merged 2 commits from baumgartl/fix-freertos-monotonic-clock into main 2026-09-25 14:24:15 +02:00
4 changed files with 3 additions and 18 deletions
+2 -1
View File
@@ -48,7 +48,8 @@ ReturnValue_t Clock::getClock(timeval* time) {
}
ReturnValue_t Clock::getClockMonotonic(timeval* time) {
*time = Timekeeper::instance()->getMonotonicClockOffset() + getUptime();
// Retrieves the FreeRTOS tick count, which is hopefully monotonic
tbaumgartl marked this conversation as resolved Outdated
Outdated
Review

that comment is unnecessary. there is no need to justify or mention old/deleted/buggy code. maybe just mention that this retrieves the FreeRTOS uptime (which is hopefully fully monotonic)

that comment is unnecessary. there is no need to justify or mention old/deleted/buggy code. maybe just mention that this retrieves the FreeRTOS uptime (which is hopefully fully monotonic)
*time = getUptime();
return returnvalue::OK;
}
+1 -9
View File
@@ -17,13 +17,7 @@ Timekeeper* Timekeeper::instance() {
return myinstance;
}
void Timekeeper::setOffset(const timeval& offset) {
if (not monotonicClockInitialized) {
this->monotonicClockOffset = offset;
monotonicClockInitialized = true;
}
this->offset = offset;
}
void Timekeeper::setOffset(const timeval& offset) { this->offset = offset; }
timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
timeval uptime;
@@ -39,5 +33,3 @@ timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
}
TickType_t Timekeeper::getTicks() { return xTaskGetTickCount(); }
const timeval Timekeeper::getMonotonicClockOffset() const { return monotonicClockOffset; }
-6
View File
@@ -18,14 +18,9 @@ class Timekeeper {
Timekeeper();
timeval offset;
// Set when offset is initialized the first time
timeval monotonicClockOffset;
bool monotonicClockInitialized = false;
static Timekeeper* myinstance;
void setMonotonicClockOffset(const timeval& monotonicClockOffset);
public:
static Timekeeper* instance();
virtual ~Timekeeper();
@@ -39,7 +34,6 @@ class Timekeeper {
const timeval& getOffset() const;
void setOffset(const timeval& offset);
const timeval getMonotonicClockOffset() const;
};
#endif /* FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ */
-2
View File
@@ -192,8 +192,6 @@ class Clock {
static MutexIF *timeMutex;
static uint16_t leapSeconds;
static bool leapSecondsSet;
static bool monotonicClockInitialized;
static timeval monotonicClockOffset;
};
#endif /* FSFW_TIMEMANAGER_CLOCK_H_ */