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

drivers/periph/rtt: introduce RTT_MIN_OFFSET

This commit is contained in:
Francisco Molina 2020-06-11 09:30:25 +02:00
parent 52bcdff113
commit 8d329942df
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
2 changed files with 21 additions and 7 deletions

View File

@ -61,6 +61,24 @@ extern "C" {
#define RTT_MAX_VALUE
#endif
/**
* @def RTT_MIN_OFFSET
*
* @brief The minimum offset to correctly set an rtt callback.
*
* If the callback is taking into account rtt_get_counter() then the rtt
* might advance right between the call to rtt_get_counter() and
* rtt_set_alarm(). If that happens with val==1, the alarm would be
* set to the current time, which would then underflow. To avoid this,
* the alarm should be set at least two ticks in the future.
*
* This value can vary depending on the platform.
*
*/
#ifndef RTT_MIN_OFFSET
#define RTT_MIN_OFFSET (2U)
#endif
#ifndef RTT_FREQUENCY
/* Allow mock-RTT for unit tests */
#ifdef MOCK_RTT_FREQUENCY

View File

@ -26,10 +26,6 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
#ifndef RTT_MIN_VALUE
#define RTT_MIN_VALUE (2U)
#endif
static void _ztimer_periph_rtt_callback(void *arg)
{
ztimer_handler((ztimer_clock_t *)arg);
@ -37,17 +33,17 @@ static void _ztimer_periph_rtt_callback(void *arg)
static void _ztimer_periph_rtt_set(ztimer_clock_t *clock, uint32_t val)
{
if (val < RTT_MIN_VALUE) {
if (val < RTT_MIN_OFFSET) {
/* the rtt might advance right between the call to rtt_get_counter()
* and rtt_set_alarm(). If that happens with val==1, we'd set an alarm
* to the current time, which would then underflow. To avoid this, we
* set the alarm at least two ticks in the future. TODO: confirm this
* is sufficient, or conceive logic to lower this value.
*
* @note RTT_MIN_VALUE defaults to 2, but some platforms might have
* @note RTT_MIN_OFFSET defaults to 2, but some platforms might have
* different values.
*/
val = RTT_MIN_VALUE;
val = RTT_MIN_OFFSET;
}
unsigned state = irq_disable();