1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #17125 from aabadie/pr/cpu/native_rtc_ztimer

cpu/native: migrate periph_rtc to ztimer
This commit is contained in:
Alexandre Abadie 2021-11-11 17:26:10 +01:00 committed by GitHub
commit a85853ae30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -18,7 +18,8 @@ ifeq (,$(filter stdio_%,$(USEMODULE)))
endif
ifneq (,$(filter periph_rtc,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += ztimer
USEMODULE += ztimer_msec
endif
ifneq (,$(filter eui_provider,$(USEMODULE)))

View File

@ -6,5 +6,6 @@
#
config MODULE_PERIPH_RTC
select MODULE_XTIMER if CPU_ARCH_NATIVE
select MODULE_ZTIMER if CPU_ARCH_NATIVE
select MODULE_ZTIMER_MSEC if CPU_ARCH_NATIVE
depends on HAS_PERIPH_RTC

View File

@ -29,7 +29,8 @@
#include "periph/rtc.h"
#include "cpu.h"
#include "xtimer.h"
#include "timex.h"
#include "ztimer.h"
#include "native_internal.h"
@ -44,7 +45,7 @@ static rtc_alarm_cb_t _native_rtc_alarm_callback;
static time_t _native_rtc_offset;
static xtimer_t _native_rtc_timer;
static ztimer_t _native_rtc_timer;
static void _native_rtc_cb(void *arg) {
if (_native_rtc_alarm_callback) {
@ -70,7 +71,7 @@ void rtc_init(void)
{
DEBUG("rtc_init\n");
xtimer_remove(&_native_rtc_timer);
ztimer_remove(ZTIMER_MSEC, &_native_rtc_timer);
_native_rtc_timer.callback = _native_rtc_cb;
memset(&_native_rtc_alarm, 0, sizeof(_native_rtc_alarm));
@ -108,7 +109,7 @@ void rtc_poweroff(void)
}
if (_native_rtc_alarm_callback) {
xtimer_remove(&_native_rtc_timer);
ztimer_remove(ZTIMER_MSEC, &_native_rtc_timer);
memset(&_native_rtc_alarm, 0, sizeof(_native_rtc_alarm));
_native_rtc_alarm_callback = NULL;
}
@ -202,7 +203,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
time_t tdiff_secs = mktime(&intime) - mktime(&now);
if (_native_rtc_alarm_callback) {
xtimer_remove(&_native_rtc_timer);
ztimer_remove(ZTIMER_MSEC, &_native_rtc_timer);
}
_native_rtc_alarm = *time;
@ -210,7 +211,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
_native_rtc_timer.arg = arg;
if (tdiff_secs >= 0) {
xtimer_set64(&_native_rtc_timer, tdiff_secs * US_PER_SEC);
ztimer_set(ZTIMER_MSEC, &_native_rtc_timer, tdiff_secs * MS_PER_SEC);
}
return 0;
@ -243,7 +244,7 @@ void rtc_clear_alarm(void)
warnx("rtc_clear_alarm: not powered on");
}
xtimer_remove(&_native_rtc_timer);
ztimer_remove(ZTIMER_MSEC, &_native_rtc_timer);
memset(&_native_rtc_alarm, 0, sizeof(_native_rtc_alarm));
_native_rtc_alarm_callback = NULL;
}