Skip to content

stm32: Support static soft timer instances. #7143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

dpgeorge
Copy link
Member

This adds support for making static (ie not on the Python GC heap) soft timers. This can be useful for a board to define some custom background handler, or eventually for BLE/network processing to use instead of systick slots; it will be more efficient using soft timer for this.

The main issue with using the existing code for static soft timers is that it would combine heap allocated and statically allocated soft_timer_entry_t instances in the same pairing heap data structure. This would prevent the GC from tracing some of the heap allocated entries (because the GC won't follow pointers outside the heap).

This PR makes it so that soft timer entries are explicitly marked, instead of relying on implicit marking by having the root of the pairing heap in the root pointer section. This PR also deletes only the heap-allocated soft timers from the pairing heap on soft reset, leaving the statically allocated ones.

An alternative to this approach would be to have two separate pairing heaps, one for static and one for heap allocated entries, but for execution efficiency it's better to just have a single pairing heap.

@dpgeorge dpgeorge force-pushed the stm32-static-soft-timer branch from a454c8f to 209872f Compare April 22, 2021 01:08
@dpgeorge dpgeorge force-pushed the stm32-static-soft-timer branch 2 times, most recently from 04c2743 to 6093e71 Compare April 29, 2021 06:24
Signed-off-by: Damien George <damien@micropython.org>
This adds support for making static (ie not on the Python GC heap) soft
timers.  This can be useful for a board to define a custom background
handler, or eventually for BLE/network processing to use instead of systick
slots; it will be more efficient using soft timer for this.

The main issue with using the existing code for static soft timers is that
it would combine heap allocated and statically allocated soft_timer_entry_t
instances in the same pairing-heap data structure.  This would prevent the
GC from tracing some of the heap allocated entries (because the GC won't
follow pointers outside the heap).

This commit makes it so that soft timer entries are explicitly marked,
instead of relying on implicit marking by having the root of the pairing
heap in the root pointer section.  Also, on soft reset only the heap-
allocated soft timers are deleted from the pairing heap, leaving the
statically allocated ones.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the stm32-static-soft-timer branch from 6093e71 to 647fa63 Compare April 29, 2021 06:55
@dpgeorge dpgeorge merged commit 647fa63 into micropython:master Apr 29, 2021
@dpgeorge dpgeorge deleted the stm32-static-soft-timer branch April 29, 2021 07:15
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant