Skip to content

Commit

Permalink
Merge pull request #13035 from gschorcht/tests/periph_rtc_fix
Browse files Browse the repository at this point in the history
tests/periph_rtc: fix system locks in ISR
  • Loading branch information
benpicco committed Feb 2, 2020
2 parents 5d1bf26 + 46dbd86 commit f760625
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tests/periph_rtc/main.c
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include <time.h>

#include "mutex.h"
#include "periph_conf.h"
#include "periph/rtc.h"
#include "xtimer.h"
Expand Down Expand Up @@ -53,16 +54,7 @@ static void inc_secs(struct tm *time, unsigned val)

static void cb(void *arg)
{
(void)arg;

puts("Alarm!");

if (++cnt < REPEAT) {
struct tm time;
rtc_get_alarm(&time);
inc_secs(&time, PERIOD);
rtc_set_alarm(&time, cb, NULL);
}
mutex_unlock(arg);
}

int main(void)
Expand All @@ -76,6 +68,8 @@ int main(void)
.tm_sec = 57
};

mutex_t rtc_mtx = MUTEX_INIT_LOCKED;

puts("\nRIOT RTC low-level driver test");
printf("This test will display 'Alarm!' every %u seconds for %u times\n",
PERIOD, REPEAT);
Expand All @@ -91,12 +85,24 @@ int main(void)
/* set initial alarm */
inc_secs(&time, PERIOD);
print_time(" Setting alarm to ", &time);
rtc_set_alarm(&time, cb, NULL);
rtc_set_alarm(&time, cb, &rtc_mtx);

/* verify alarm */
rtc_get_alarm(&time);
print_time(" Alarm is set to ", &time);
puts("");

while (1) {
mutex_lock(&rtc_mtx);
puts("Alarm!");

if (++cnt < REPEAT) {
struct tm time;
rtc_get_alarm(&time);
inc_secs(&time, PERIOD);
rtc_set_alarm(&time, cb, &rtc_mtx);
}
}

return 0;
}

0 comments on commit f760625

Please sign in to comment.