stm32/systick: Make periodic systick callbacks use a cyclic func table.

Instead of checking each callback (currently storage and dma) explicitly
for each SysTick IRQ, use a simple circular function table indexed by the
lower bits of the millisecond tick counter.  This allows callbacks to be
easily enabled/disabled at runtime, and scales well to a large number of
callbacks.
This commit is contained in:
Damien George
2019-02-03 23:00:44 +11:00
parent 5fbda53d3c
commit 1bcf4afb10
7 changed files with 88 additions and 86 deletions

View File

@@ -26,6 +26,22 @@
#ifndef MICROPY_INCLUDED_STM32_SYSTICK_H
#define MICROPY_INCLUDED_STM32_SYSTICK_H
#define SYSTICK_DISPATCH_NUM_SLOTS (2)
#define SYSTICK_DISPATCH_DMA (0)
#define SYSTICK_DISPATCH_STORAGE (1)
typedef void (*systick_dispatch_t)(uint32_t);
extern systick_dispatch_t systick_dispatch_table[SYSTICK_DISPATCH_NUM_SLOTS];
static inline void systick_enable_dispatch(size_t slot, systick_dispatch_t f) {
systick_dispatch_table[slot] = f;
}
static inline void systick_disable_dispatch(size_t slot) {
systick_dispatch_table[slot] = NULL;
}
void systick_wait_at_least(uint32_t stc, uint32_t delay_ms);
bool systick_has_passed(uint32_t stc, uint32_t delay_ms);