Skip to content

Commit

Permalink
fixup! tests/periph_rtt: test for periph_rtc_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Aug 23, 2021
1 parent 0d58cb9 commit 84633dd
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions tests/periph_rtt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,51 @@ void cb(void *arg)
}

#ifdef MODULE_PERIPH_RTC_MEM
static const uint8_t riot_msg_offset = 1;
static const char riot_msg[] = "RIOT";
static void _set_rtc_mem(void)
{
rtc_mem_write(1, riot_msg, 4);
/* first fill the whole memory */
uint8_t size = rtc_mem_size();
while (size--) {
rtc_mem_write(size, &size, sizeof(size));
}

/* write test data */
rtc_mem_write(riot_msg_offset, riot_msg, sizeof(riot_msg) - 1);
}

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

if (memcmp(buf, riot_msg, 4)) {
if (memcmp(buf, riot_msg, sizeof(buf))) {
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");
return;
}

uint8_t size = rtc_mem_size();
while (size--) {
uint8_t data;

if (size >= riot_msg_offset &&
size < riot_msg_offset + sizeof(riot_msg)) {
continue;
}

rtc_mem_read(size, &data, 1);
if (data != size) {
puts("RTC mem content does not match");
printf("%0x2: %0x2\n", size, data);
}
}


puts("RTC mem OK");
}
#else
static inline void _set_rtc_mem(void) {}
Expand Down

0 comments on commit 84633dd

Please sign in to comment.