shared/runtime/softtimer: Use consistently the same clock source.

Before, both uwTick and mp_hal_ticks_ms() were used as clock source.  That
assumes, that these two are synchronous and start with the same value,
which may be not the case for all ports.  If the lag between uwTick and
mp_hal_ticks_ms() is larger than the timer interval, the timer would either
rush up until the times are synchronous, or not start until uwTick wraps
over.

As suggested by @dpgeorge, MICROPY_SOFT_TIMER_TICKS_MS is now used in
softtimer.c, which has to be defined in a port's mpconfigport.h with
the variable that holds the SysTick counter.

Note that it's not possible to switch everything in softtimer.c to use
mp_hal_ticks_ms() because the logic in SysTick_Handler that schedules
soft_timer_handler() uses (eg on mimxrt) the uwTick variable directly
(named systick_ms there), and mp_hal_ticks_ms() uses a different source
timer.  Thus it is made fully configurable.
This commit is contained in:
robert-hh
2023-02-12 14:15:08 +01:00
committed by Damien George
parent 68d049ea5e
commit de1f1dd164
6 changed files with 9 additions and 9 deletions

View File

@@ -98,6 +98,7 @@
#define MICROPY_HW_SOFTSPI_MIN_DELAY (1)
#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (1000000)
#define MICROPY_PY_MACHINE_TIMER (1)
#define MICROPY_SOFT_TIMER_TICKS_MS systick_ms
#define MICROPY_PY_OS_DUPTERM (3)
#define MICROPY_PY_MACHINE_BITSTREAM (1)
#define MICROPY_PY_MACHINE_PULSE (1)

View File

@@ -43,10 +43,6 @@ uint64_t mp_hal_ticks_us_64(void);
void mp_hal_set_interrupt_char(int c);
// Define an alias fo systick_ms, because the shared softtimer.c uses
// the symbol uwTick for the systick ms counter.
#define uwTick systick_ms
#define mp_hal_delay_us_fast mp_hal_delay_us
static inline uint64_t mp_hal_ticks_ms_64(void) {