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

ztimer/periph_rtc: add start() and stop() ops

This commit is contained in:
Juergen Fitschen 2022-02-04 18:04:23 +01:00 committed by Jue
parent 5818e5e452
commit d22e078118
2 changed files with 30 additions and 0 deletions

View File

@ -243,6 +243,13 @@ config MODULE_ZTIMER_ONDEMAND_TIMER
Turn off the underlying Timer peripheral if related ztimer clocks
have no users.
config MODULE_ZTIMER_ONDEMAND_RTC
bool "Run RTC only on demand"
depends on MODULE_ZTIMER_PERIPH_RTC
help
Turn off the underlying RTC peripheral if related ztimer clocks
have no users.
endif # MODULE_ZTIMER_ONDEMAND
config MODULE_ZTIMER_INIT

View File

@ -138,10 +138,28 @@ static void _ztimer_periph_rtc_cancel(ztimer_clock_t *clock)
rtc_clear_alarm();
}
#if MODULE_ZTIMER_ONDEMAND_RTC
static void _ztimer_periph_rtc_start(ztimer_clock_t *clock)
{
(void)clock;
rtc_poweron();
}
static void _ztimer_periph_rtc_stop(ztimer_clock_t *clock)
{
(void)clock;
rtc_poweroff();
}
#endif /* MODULE_ZTIMER_ONDEMAND_RTC */
static const ztimer_ops_t _ztimer_periph_rtc_ops = {
.set = _ztimer_periph_rtc_set,
.now = _ztimer_periph_rtc_now,
.cancel = _ztimer_periph_rtc_cancel,
#if MODULE_ZTIMER_ONDEMAND_RTC
.start = _ztimer_periph_rtc_start,
.stop = _ztimer_periph_rtc_stop,
#endif
};
void ztimer_periph_rtc_init(ztimer_periph_rtc_t *clock)
@ -149,5 +167,10 @@ void ztimer_periph_rtc_init(ztimer_periph_rtc_t *clock)
clock->ops = &_ztimer_periph_rtc_ops;
clock->max_value = UINT32_MAX;
rtc_init();
#if MODULE_ZTIMER_ONDEMAND_RTC
rtc_poweroff();
#else
rtc_poweron();
#endif
}