1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +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 <string.h>
#include "irq.h"
#include "periph/rtc.h"
#include "periph/rtt.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)
{
uint32_t tmp, prev = rtc_now;
uint32_t now, tmp;
unsigned state = irq_disable();
/* repeat calculation if an alarm triggered in between */
do {
uint32_t now = rtt_get_counter();
tmp = _rtc_now(now);
now = rtt_get_counter();
tmp = _rtc_now(now);
*ms = (SUBSECONDS(now - last_alarm) * MS_PER_SEC) / RTT_SECOND;
} while (prev != rtc_now);
*ms = (SUBSECONDS(now - last_alarm) * MS_PER_SEC)
/ RTT_SECOND;
irq_restore(state);
rtc_localtime(tmp, time);
return 0;
@ -155,15 +156,14 @@ int rtc_get_time_ms(struct tm *time, uint16_t *ms)
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 */
do {
uint32_t now = rtt_get_counter();
uint32_t tmp = _rtc_now(now);
now = rtt_get_counter();
tmp = _rtc_now(now);
rtc_localtime(tmp, time);
} while (prev != rtc_now);
irq_restore(state);
rtc_localtime(tmp, time);
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 = cb;
/* RTT interrupt is disabled here */
rtc_now = _rtc_now(now);
_update_alarm(now);