Skip to content

Commit

Permalink
tests/periph_rtc: test for periph_rtc_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Aug 19, 2021
1 parent a82eb28 commit eb05241
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions tests/periph_rtc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include ../Makefile.tests_common

FEATURES_REQUIRED += periph_rtc
FEATURES_OPTIONAL += periph_rtc_ms
FEATURES_OPTIONAL += periph_rtc_mem

DISABLE_MODULE += periph_init_rtc

Expand Down
47 changes: 39 additions & 8 deletions tests/periph_rtc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

#include <stdio.h>
#include <time.h>
#include <string.h>

#include "mutex.h"
#include "periph_conf.h"
#include "periph/rtc.h"
#include "periph/rtc_mem.h"
#include "xtimer.h"

#define PERIOD (2U)
Expand Down Expand Up @@ -69,6 +71,32 @@ static void cb(void *arg)
mutex_unlock(arg);
}

#ifdef MODULE_PERIPH_RTC_MEM
static const char riot_msg[] = "RIOT";
static void _set_rtc_mem(void)
{
rtc_mem_write(1, riot_msg, 4);
}

static void _get_rtc_mem(void)
{
char buf[4];
rtc_mem_read(1, buf, 4);

if (memcmp(buf, riot_msg, 4)) {
puts("RTC mem content does not match");
for (unsigned i = 0; i < sizeof(buf); ++i) {
printf("%02x - %02x\n", riot_msg[i], buf[i]);
}
} else {
puts("RTC mem OK");
}
}
#else
static inline void _set_rtc_mem(void) {}
static inline void _get_rtc_mem(void) {}
#endif

int main(void)
{
struct tm time = {
Expand All @@ -88,6 +116,9 @@ int main(void)

rtc_init();

_set_rtc_mem();
_get_rtc_mem();

/* set RTC */
print_time(" Setting clock to ", &time);
rtc_set_time(&time);
Expand Down Expand Up @@ -149,17 +180,17 @@ int main(void)
puts("");

/* loop over a few alarm cycles */
while (1) {
do {
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);
}
}
struct tm time;
rtc_get_alarm(&time);
inc_secs(&time, PERIOD);
rtc_set_alarm(&time, cb, &rtc_mtx);
} while (++cnt < REPEAT);

_get_rtc_mem();

return 0;
}

0 comments on commit eb05241

Please sign in to comment.