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