1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #13922 from kaspar030/ztimer_rtt_maxval_fix

ztimer: periph_rtt: ensure RTT_MAX_VALUE is honored
This commit is contained in:
Koen Zandberg 2020-04-23 18:42:00 +02:00 committed by GitHub
commit 5e5ed8233d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@
*
* @}
*/
#include "assert.h"
#include "periph/rtt.h"
#include "ztimer/periph_rtt.h"
@ -50,7 +51,16 @@ static void _ztimer_periph_rtt_set(ztimer_clock_t *clock, uint32_t val)
}
unsigned state = irq_disable();
rtt_set_alarm(rtt_get_counter() + val, _ztimer_periph_rtt_callback, clock);
/* ensure RTT_MAX_VALUE is (2^n - 1) */
static_assert((RTT_MAX_VALUE == UINT32_MAX) ||
!((RTT_MAX_VALUE + 1) & (RTT_MAX_VALUE)),
"RTT_MAX_VALUE needs to be (2^n) - 1");
rtt_set_alarm(
(rtt_get_counter() + val) & RTT_MAX_VALUE, _ztimer_periph_rtt_callback,
clock);
irq_restore(state);
}