2020-04-08 18:08:14 +02:00
|
|
|
#include <framework/osal/FreeRTOS/Timekeeper.h>
|
2018-07-13 15:56:37 +02:00
|
|
|
|
2020-05-29 13:07:35 +02:00
|
|
|
#include "FreeRTOSConfig.h"
|
2018-07-13 15:56:37 +02:00
|
|
|
|
2020-04-08 18:08:14 +02:00
|
|
|
Timekeeper * Timekeeper::myinstance = nullptr;
|
|
|
|
|
|
|
|
Timekeeper::Timekeeper() : offset( { 0, 0 }) {}
|
2018-07-13 15:56:37 +02:00
|
|
|
|
|
|
|
const timeval& Timekeeper::getOffset() const {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timekeeper* Timekeeper::instance() {
|
2020-04-08 18:08:14 +02:00
|
|
|
if (myinstance == nullptr) {
|
2018-07-13 15:56:37 +02:00
|
|
|
myinstance = new Timekeeper();
|
|
|
|
}
|
|
|
|
return myinstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timekeeper::setOffset(const timeval& offset) {
|
|
|
|
this->offset = offset;
|
|
|
|
}
|
|
|
|
|
2020-04-08 18:08:14 +02:00
|
|
|
Timekeeper::~Timekeeper() {}
|
2018-07-13 15:56:37 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-04-08 18:08:14 +02:00
|
|
|
|
|
|
|
TickType_t Timekeeper::getTicks() {
|
|
|
|
return xTaskGetTickCount();
|
|
|
|
}
|