fsfw/src/fsfw/osal/freertos/Clock.cpp

43 lines
937 B
C++
Raw Normal View History

2021-07-14 00:54:39 +02:00
#include "fsfw/timemanager/Clock.h"
2018-07-13 15:56:37 +02:00
2021-07-14 00:54:39 +02:00
#include <cstdlib>
#include <ctime>
2018-07-13 15:56:37 +02:00
2022-02-02 10:29:30 +01:00
#include "FreeRTOS.h"
#include "fsfw/globalfunctions/timevalOperations.h"
#include "fsfw/osal/freertos/Timekeeper.h"
#include "task.h"
// TODO sanitize input?
// TODO much of this code can be reused for tick-only systems
2018-07-13 15:56:37 +02:00
ReturnValue_t Clock::setClock(const timeval* time) {
2022-02-02 10:29:30 +01:00
timeval uptime = getUptime();
2018-07-13 15:56:37 +02:00
2022-02-02 10:29:30 +01:00
timeval offset = *time - uptime;
2018-07-13 15:56:37 +02:00
2022-02-02 10:29:30 +01:00
Timekeeper::instance()->setOffset(offset);
2018-07-13 15:56:37 +02:00
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2018-07-13 15:56:37 +02:00
}
ReturnValue_t Clock::getClock_timeval(timeval* time) {
2022-02-02 10:29:30 +01:00
timeval uptime = getUptime();
2018-07-13 15:56:37 +02:00
2022-02-02 10:29:30 +01:00
timeval offset = Timekeeper::instance()->getOffset();
2018-07-13 15:56:37 +02:00
2022-02-02 10:29:30 +01:00
*time = offset + uptime;
2018-07-13 15:56:37 +02:00
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
2018-07-13 15:56:37 +02:00
}
timeval Clock::getUptime() {
2022-02-02 10:29:30 +01:00
TickType_t ticksSinceStart = xTaskGetTickCount();
return Timekeeper::ticksToTimeval(ticksSinceStart);
2018-07-13 15:56:37 +02:00
}
2022-02-02 10:29:30 +01:00
// uint32_t Clock::getUptimeSeconds() {
2020-12-14 11:17:22 +01:00
// timeval uptime = getUptime();
// return uptime.tv_sec;
2022-02-02 10:29:30 +01:00
// }