From 4276e93dc9ed6227189a6fabb654b557d62647e0 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 14 Apr 2024 20:19:39 +0200 Subject: [PATCH 1/2] cpu/msp430/periph_timer: fix timer_query_freqs() `timer_query_freqs()` should return 0 when index is out of range according to the doc. This changes the code to live up to the spec. (cherry picked from commit 5adf1f1a28ba990e5b115608024f70930a6e821a) --- cpu/msp430/periph/timer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpu/msp430/periph/timer.c b/cpu/msp430/periph/timer.c index 0f0015acdedf..4e4ee2667a2e 100644 --- a/cpu/msp430/periph/timer.c +++ b/cpu/msp430/periph/timer.c @@ -188,6 +188,10 @@ uint32_t timer_query_freqs(tim_t dev, uword_t index) assume((clock_source == TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK) || (clock_source == TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK)); + if (index > TXID_DIV_MAX) { + return 0; + } + uint32_t clock_freq; switch (clock_source) { default: From 11fe9b8597fb0d9c43eedbe8981d3a90937a8a57 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 14 Apr 2024 20:22:38 +0200 Subject: [PATCH 2/2] tests/periph/timer: also test for idx out of range Also test that `timer_query_freqs()` for an index out of range does return 0, as stated by the doc. (cherry picked from commit 189bb29f76b50100e28be4752499bf2a156233c6) --- tests/periph/timer/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/periph/timer/main.c b/tests/periph/timer/main.c index 132677dc90c7..0071119a2840 100644 --- a/tests/periph/timer/main.c +++ b/tests/periph/timer/main.c @@ -249,6 +249,8 @@ static void print_supported_frequencies(tim_t dev) " %u: %" PRIu32 "\n", (unsigned)(end - 1), timer_query_freqs(dev, end - 1)); } + + expect(timer_query_freqs(dev, end) == 0); } int main(void)