stm32/softtimer: Add soft_timer_reinsert() helper function.

And call mp_pairheap_init_node() in soft_timer_static_init() so that
reinsert can be called after static_init.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-05-19 16:54:43 +10:00
parent b3a34dde36
commit 60f1f76984
2 changed files with 8 additions and 0 deletions

View File

@ -122,6 +122,7 @@ void soft_timer_gc_mark_all(void) {
}
void soft_timer_static_init(soft_timer_entry_t *entry, uint16_t mode, uint32_t delta_ms, void (*cb)(soft_timer_entry_t *)) {
mp_pairheap_init_node(soft_timer_lt, &entry->pairheap);
entry->flags = 0;
entry->mode = mode;
entry->delta_ms = delta_ms;

View File

@ -56,4 +56,11 @@ void soft_timer_static_init(soft_timer_entry_t *entry, uint16_t mode, uint32_t d
void soft_timer_insert(soft_timer_entry_t *entry, uint32_t initial_delta_ms);
void soft_timer_remove(soft_timer_entry_t *entry);
// The timer will be reinserted into the heap so that it is called after initial_delta_ms milliseconds.
// After that, if it's periodic, it will continue to be called every entry->delta_ms milliseconds.
static inline void soft_timer_reinsert(soft_timer_entry_t *entry, uint32_t initial_delta_ms) {
soft_timer_remove(entry);
soft_timer_insert(entry, initial_delta_ms);
}
#endif // MICROPY_INCLUDED_STM32_SOFTTIMER_H