Skip to content

Commit

Permalink
fixup! fixup! cpu/native: implement periph_rtc_ms
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Mar 3, 2023
1 parent 18a65bd commit e1de748
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cpu/native/periph/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#define ENABLE_DEBUG 0
#include "debug.h"

/**
* @brief Time source of the native RTC
*/
#ifndef NATIVE_RTC_SOURCE
#define NATIVE_RTC_SOURCE CLOCK_REALTIME
#endif

static int _native_rtc_initialized = 0;
static int _native_rtc_powered = 0;

Expand Down Expand Up @@ -141,10 +148,15 @@ int rtc_set_time(struct tm *ttime)
warnx("rtc_set_time: out of time_t range");
return -1;
}

struct timespec tv;

_native_syscall_enter();
_native_rtc_offset = tnew - time(NULL);
clock_gettime(NATIVE_RTC_SOURCE, &tv);
_native_syscall_leave();

_native_rtc_offset = tnew - tv.tv_sec;

if (_native_rtc_alarm_callback) {
rtc_set_alarm(&_native_rtc_alarm, _native_rtc_alarm_callback,
_native_rtc_timer.arg);
Expand All @@ -167,7 +179,7 @@ int rtc_get_time_ms(struct tm *ttime, uint16_t *ms)
}

_native_syscall_enter();
clock_gettime(CLOCK_REALTIME, &tv);
clock_gettime(NATIVE_RTC_SOURCE, &tv);
tv.tv_sec += _native_rtc_offset;

if (ms) {
Expand Down

0 comments on commit e1de748

Please sign in to comment.