From 7c3186d56e9d9b5a8976483e9b8cd8510f0811ae Mon Sep 17 00:00:00 2001 From: chudov Date: Fri, 28 Apr 2023 16:32:47 +0200 Subject: [PATCH] tests/periph_rtt: Fix for tick conversion test #15940 Signed-off-by: chudov --- tests/periph_rtt/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/periph_rtt/main.c b/tests/periph_rtt/main.c index 57fe6082925e5..546f0fabf4911 100644 --- a/tests/periph_rtt/main.c +++ b/tests/periph_rtt/main.c @@ -105,17 +105,17 @@ int main(void) puts("\nRIOT RTT low-level driver test"); puts("RTT configuration:"); - printf("RTT_MAX_VALUE: 0x%08x\n", (unsigned)RTT_MAX_VALUE); - printf("RTT_FREQUENCY: %u\n\n", (unsigned)RTT_FREQUENCY); + printf("RTT_MAX_VALUE: 0x%08lx\n", (unsigned long)RTT_MAX_VALUE); + printf("RTT_FREQUENCY: %lu\n\n", (unsigned long)RTT_FREQUENCY); - puts("Testing the tick conversion"); - for (unsigned i = 0; i < ARRAY_SIZE(_ticktest); i++) { + puts("Testing the tick conversion (with rounding if RTT_FREQUENCY is not power of 2)"); + for (uint16_t i = 0; i < ARRAY_SIZE(_ticktest); i++) { uint32_t sec = RTT_TICKS_TO_SEC(_ticktest[i]); uint32_t ticks = RTT_SEC_TO_TICKS(sec); printf("Trying to convert %" PRIu32 " to seconds and back\n", _ticktest[i]); - /* account for rounding errors... */ - if ((ticks != 0) && (ticks != _ticktest[i])) { + /* RTT_FREQUENCY is not always power of 2 so compare with rounded result */ + if ((ticks != 0) && (ticks != _ticktest[i] / RTT_FREQUENCY * RTT_FREQUENCY)) { puts("error: TICK conversion not working as expected\n"); return 1; }