mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/periph_rtt: test for periph_rtc_mem
This commit is contained in:
parent
3fbf473a07
commit
c467f05317
@ -3,6 +3,7 @@ include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED = periph_rtt
|
||||
FEATURES_OPTIONAL += periph_rtt_set_counter
|
||||
FEATURES_OPTIONAL += periph_rtc_mem
|
||||
|
||||
DISABLE_MODULE += periph_init_rtt
|
||||
|
||||
|
@ -23,11 +23,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/rtt.h"
|
||||
#include "periph/rtc_mem.h"
|
||||
|
||||
#define TICKS_TO_WAIT (5 * RTT_FREQUENCY)
|
||||
|
||||
@ -46,6 +48,58 @@ void cb(void *arg)
|
||||
puts("Hello");
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
/* 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(riot_msg_offset, buf, sizeof(buf));
|
||||
|
||||
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]);
|
||||
}
|
||||
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("%02x: %02x\n", size, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
puts("RTC mem OK");
|
||||
}
|
||||
#else
|
||||
static inline void _set_rtc_mem(void) {}
|
||||
static inline void _get_rtc_mem(void) {}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("\nRIOT RTT low-level driver test");
|
||||
@ -71,6 +125,9 @@ int main(void)
|
||||
puts("Initializing the RTT driver");
|
||||
rtt_init();
|
||||
|
||||
_set_rtc_mem();
|
||||
_get_rtc_mem();
|
||||
|
||||
puts("This test will now display 'Hello' every 5 seconds\n");
|
||||
uint32_t now = rtt_get_counter();
|
||||
printf("RTT now: %" PRIu32 "\n", now);
|
||||
@ -103,6 +160,8 @@ int main(void)
|
||||
puts("rtt_get_alarm() PASSED");
|
||||
}
|
||||
|
||||
_get_rtc_mem();
|
||||
|
||||
puts("Done setting up the RTT, wait for many Hellos");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user