1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

rtt_rtc: fix rtc_now access

This commit is contained in:
Benjamin Valentin 2021-07-26 23:35:00 +02:00 committed by Benjamin Valentin
parent 6178325b5b
commit eecc166180

View File

@ -26,6 +26,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "irq.h"
#include "periph/rtc.h" #include "periph/rtc.h"
#include "periph/rtt.h" #include "periph/rtt.h"
#include "timex.h" #include "timex.h"
@ -138,16 +139,16 @@ int rtc_set_time(struct tm *time)
int rtc_get_time_ms(struct tm *time, uint16_t *ms) int rtc_get_time_ms(struct tm *time, uint16_t *ms)
{ {
uint32_t tmp, prev = rtc_now; uint32_t now, tmp;
unsigned state = irq_disable();
/* repeat calculation if an alarm triggered in between */ now = rtt_get_counter();
do { tmp = _rtc_now(now);
uint32_t now = rtt_get_counter();
tmp = _rtc_now(now);
*ms = (SUBSECONDS(now - last_alarm) * MS_PER_SEC) / RTT_SECOND; *ms = (SUBSECONDS(now - last_alarm) * MS_PER_SEC)
} while (prev != rtc_now); / RTT_SECOND;
irq_restore(state);
rtc_localtime(tmp, time); rtc_localtime(tmp, time);
return 0; return 0;
@ -155,15 +156,14 @@ int rtc_get_time_ms(struct tm *time, uint16_t *ms)
int rtc_get_time(struct tm *time) int rtc_get_time(struct tm *time)
{ {
uint32_t prev = rtc_now; uint32_t now, tmp;
unsigned state = irq_disable();
/* repeat calculation if an alarm triggered in between */ now = rtt_get_counter();
do { tmp = _rtc_now(now);
uint32_t now = rtt_get_counter();
uint32_t tmp = _rtc_now(now);
rtc_localtime(tmp, time); irq_restore(state);
} while (prev != rtc_now); rtc_localtime(tmp, time);
return 0; return 0;
} }
@ -186,6 +186,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
alarm_cb_arg = arg; alarm_cb_arg = arg;
alarm_cb = cb; alarm_cb = cb;
/* RTT interrupt is disabled here */
rtc_now = _rtc_now(now); rtc_now = _rtc_now(now);
_update_alarm(now); _update_alarm(now);