summaryrefslogtreecommitdiff
path: root/shared/runtime/softtimer.c
AgeCommit message (Collapse)Author
2024-05-31rp2: Refactor to not use pico-sdk alarm pool functions for sleeping.Angus Gratton
The best_effort_wfe_or_timeout() and sleep_us() pico-sdk functions use the pico-sdk alarm pool internally, and that has a bug. Some usages inside pico-sdk (notably multicore_lockout_start_blocking()) will still end up calling best_effort_wfe_or_timeout(), although usually with "end_of_time" as the timeout value so it should avoid any alarm pool race conditions. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-11-29shared/runtime/softtimer: Generalise soft_timer to work without SysTick.Damien George
If a port defines MICROPY_SOFT_TIMER_TICKS_MS then soft_timer assumes a SysTick back end, and provides a soft_timer_next variable that sets when the next call to soft_timer_handler() should occur. Otherwise, a port should provide soft_timer_get_ms() and soft_timer_schedule_at_ms() with appropriate semantics (see comments). Existing users of soft_timer should continue to work as they did. Signed-off-by: Damien George <damien@micropython.org>
2023-04-27all: Fix spelling mistakes based on codespell check.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-02-17shared/runtime/softtimer: Fix ticks range when computing ticks diff.Jim Mussared
The previous computation incorrectly assumed that the uint32_t ticks counter MICROPY_SOFT_TIMER_TICKS_MS was in the range [0,0x80000000) where its actually [0,0xffffffff]. This means the diff calculation can be simplified compared to the original implementation copied from utime_mphal.c, which has to deal with a ticks range constrained by the small int range. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-16shared/runtime/softtimer: Use consistently the same clock source.robert-hh
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.
2022-07-19shared/runtime/softtimer: Remove obsolete #include statement.robert-hh
2022-07-19shared/runtime/softtimer: Move softtimer.[ch] to shared/runtime.robert-hh
And change the include lock to the naming scheme of that place. This comes from ports/stm32/softtimer.[ch].