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

Merge pull request #17385 from fjmolinas/pr_ztimer_set_now

sys/ztimer: ztimer_set() return the now value
This commit is contained in:
Kaspar Schleiser 2021-12-13 13:06:27 +01:00 committed by GitHub
commit efa24b3f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -381,8 +381,11 @@ void ztimer_handler(ztimer_clock_t *clock);
* @param[in] clock ztimer clock to operate on
* @param[in] timer timer entry to set
* @param[in] val timer target (relative ticks from now)
*
* @return The value of @ref ztimer_now() that @p timer was set against
* (`now() + @p val = absolute trigger time`).
*/
void ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val);
uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val);
/**
* @brief Check if a timer is currently active

View File

@ -40,7 +40,7 @@ static void _add_entry_to_list(ztimer_clock_t *clock, ztimer_base_t *entry);
static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry);
static void _ztimer_update(ztimer_clock_t *clock);
static void _ztimer_print(const ztimer_clock_t *clock);
static void _ztimer_update_head_offset(ztimer_clock_t *clock);
static uint32_t _ztimer_update_head_offset(ztimer_clock_t *clock);
#ifdef MODULE_ZTIMER_EXTEND
static inline uint32_t _min_u32(uint32_t a, uint32_t b)
@ -82,14 +82,15 @@ void ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer)
irq_restore(state);
}
void ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
{
DEBUG("ztimer_set(): %p: set %p at %" PRIu32 " offset %" PRIu32 "\n",
(void *)clock, (void *)timer, clock->ops->now(clock), val);
unsigned state = irq_disable();
_ztimer_update_head_offset(clock);
uint32_t now = _ztimer_update_head_offset(clock);
if (_is_set(clock, timer)) {
_del_entry_from_list(clock, &timer->base);
}
@ -115,6 +116,7 @@ void ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
}
irq_restore(state);
return now;
}
static void _add_entry_to_list(ztimer_clock_t *clock, ztimer_base_t *entry)
@ -187,7 +189,7 @@ ztimer_now_t _ztimer_now_extend(ztimer_clock_t *clock)
}
#endif /* MODULE_ZTIMER_EXTEND */
static void _ztimer_update_head_offset(ztimer_clock_t *clock)
static uint32_t _ztimer_update_head_offset(ztimer_clock_t *clock)
{
uint32_t old_base = clock->list.offset;
uint32_t now = ztimer_now(clock);
@ -227,6 +229,7 @@ static void _ztimer_update_head_offset(ztimer_clock_t *clock)
}
clock->list.offset = now;
return now;
}
static void _del_entry_from_list(ztimer_clock_t *clock, ztimer_base_t *entry)