fsfw/osal/FreeRTOS/Timekeeper.cpp
Robin.Mueller e0e1e64a09 various changes, stopwatch
Semaphore: Some bugfixes, some constructors added
Stopwatch: First implementation, can measure in ms(double) and
ms(normal)
2020-04-08 18:08:14 +02:00

49 lines
929 B
C++

/**
* @file Timekeeper.cpp
* @date
*/
#include <framework/osal/FreeRTOS/Timekeeper.h>
extern "C" {
#include <task.h>
}
Timekeeper * Timekeeper::myinstance = nullptr;
Timekeeper::Timekeeper() : offset( { 0, 0 }) {}
const timeval& Timekeeper::getOffset() const {
return offset;
}
Timekeeper* Timekeeper::instance() {
if (myinstance == nullptr) {
myinstance = new Timekeeper();
}
return myinstance;
}
void Timekeeper::setOffset(const timeval& offset) {
this->offset = offset;
}
Timekeeper::~Timekeeper() {}
timeval Timekeeper::ticksToTimeval(TickType_t ticks) {
timeval uptime;
uptime.tv_sec = ticks / configTICK_RATE_HZ;
//TODO explain, think about overflow
uint32_t subsecondTicks = ticks % configTICK_RATE_HZ;
uint64_t usecondTicks = subsecondTicks * 1000000;
uptime.tv_usec = usecondTicks / configTICK_RATE_HZ;
return uptime;
}
TickType_t Timekeeper::getTicks() {
return xTaskGetTickCount();
}