mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-20 23:17:35 -04:00
When setting datetime from timestamp (manually, not from network), SRTC is set in order to retain the RTC datetime between resets. RTC handling was refactored in order to get rid of unnecesary conversions and third-party code mixed with proprietary code within a single file.
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
#include <time/time_syscalls.hpp>
|
|
#include <bsp/rtc/rtc.hpp>
|
|
#include <mutex.hpp>
|
|
#include <errno.h>
|
|
#include <cstring>
|
|
|
|
namespace utils::internal::syscalls
|
|
{
|
|
namespace
|
|
{
|
|
cpp_freertos::MutexRecursive g_time_lock;
|
|
cpp_freertos::MutexRecursive g_env_lock;
|
|
} // namespace
|
|
|
|
int gettimeofday(int &_errno_, struct timeval *tp, void *tzp)
|
|
{
|
|
if (!tp) {
|
|
_errno_ = EINVAL;
|
|
return -1;
|
|
}
|
|
time_t curtime;
|
|
auto err = bsp::rtc::getCurrentTimestamp(&curtime);
|
|
if (err != bsp::rtc::ErrorCode::OK) {
|
|
_errno_ = EIO;
|
|
return -1;
|
|
}
|
|
tp->tv_sec = curtime;
|
|
tp->tv_usec = 0;
|
|
return 0;
|
|
}
|
|
void tz_lock()
|
|
{
|
|
g_time_lock.Lock();
|
|
}
|
|
void tz_unlock()
|
|
{
|
|
g_time_lock.Unlock();
|
|
}
|
|
|
|
void env_lock(int &_errno_)
|
|
{
|
|
if (!g_env_lock.Lock()) {
|
|
_errno_ = ENXIO;
|
|
}
|
|
}
|
|
void env_unlock(int &_errno_)
|
|
{
|
|
if (!g_env_lock.Unlock()) {
|
|
_errno_ = ENXIO;
|
|
}
|
|
}
|
|
} // namespace utils::internal::syscalls
|