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:
commit
5e5ed8233d
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user