mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/atmega_common: RTC: get rid of isr_flag
This commit is contained in:
parent
2d706b3295
commit
5ea85ca433
@ -27,7 +27,6 @@
|
||||
static struct tm tm_now __attribute__((section(".noinit")));
|
||||
static struct tm tm_alarm __attribute__((section(".noinit")));
|
||||
|
||||
static bool isr_flag;
|
||||
static rtc_alarm_cb_t alarm_cb;
|
||||
static void *alarm_cb_arg;
|
||||
|
||||
@ -36,8 +35,6 @@ ISR(TIMER2_OVF_vect)
|
||||
{
|
||||
avr8_enter_isr();
|
||||
|
||||
isr_flag = !isr_flag;
|
||||
|
||||
if (++tm_now.tm_sec > 59) {
|
||||
rtc_tm_normalize(&tm_now);
|
||||
}
|
||||
@ -89,15 +86,19 @@ int rtc_set_time(struct tm *time)
|
||||
|
||||
int rtc_get_time(struct tm *time)
|
||||
{
|
||||
bool tmp = isr_flag;
|
||||
uint8_t before;
|
||||
|
||||
*time = tm_now;
|
||||
/* loop in case of overflow */
|
||||
do {
|
||||
before = TCNT2;
|
||||
|
||||
/* prevent compiler from reordering memory access to tm_now,
|
||||
* including moving it out of the loop
|
||||
*/
|
||||
__asm__ volatile ("" : : : "memory");
|
||||
|
||||
/* check if interrupt happened while
|
||||
reading the time struct */
|
||||
if (isr_flag != tmp) {
|
||||
*time = tm_now;
|
||||
}
|
||||
} while (before > TCNT2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user