Skip to content

Commit

Permalink
stm32/softtimer: Add soft_timer_reinsert() helper function.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dpgeorge committed Jun 23, 2021
1 parent b3a34dd commit 60f1f76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions ports/stm32/softtimer.c
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions ports/stm32/softtimer.h
Expand Up @@ -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

0 comments on commit 60f1f76

Please sign in to comment.