unix: Add zephyr_ble variant with soft timer and machine.Timer#33
Draft
andrewleech wants to merge 1 commit intoreview/unix-soft-timerfrom
Draft
unix: Add zephyr_ble variant with soft timer and machine.Timer#33andrewleech wants to merge 1 commit intoreview/unix-soft-timerfrom
andrewleech wants to merge 1 commit intoreview/unix-soft-timerfrom
Conversation
Add a new Unix variant that provides pthread-based soft timer infrastructure and machine.Timer. The timer thread uses a condition variable for scheduling and a recursive mutex shared with the PENDSV_ENTER/EXIT macros for thread-safe access to the timer heap. SIGUSR1 is used to wake the main thread when callbacks are scheduled so that blocking syscalls (e.g. select in time.sleep) return promptly. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## review/unix-soft-timer #33 +/- ##
==========================================================
+ Coverage 98.45% 98.49% +0.03%
==========================================================
Files 175 176 +1
Lines 22635 23417 +782
==========================================================
+ Hits 22286 23064 +778
- Misses 349 353 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
zephyr_bleUnix variant with pthread-based soft timer infrastructure andmachine.Timersupport. This is the first component of Zephyr BLE Unix port integration -- the BLE defines are present but commented out pending the Zephyr BLE unix port implementation.The timer backend uses a dedicated pthread that sleeps on a condition variable and calls
soft_timer_handler()when timers expire. A recursive mutex shared withMICROPY_PY_PENDSV_ENTER/EXITprovides thread-safe access to the timer heap.SIGUSR1interrupts the main thread's blocking syscalls (viaMICROPY_SCHED_HOOK_SCHEDULED) so scheduled callbacks are processed promptly duringtime.sleep()and similar.Testing
Built and tested on Linux x86_64.
machine_soft_timer.pytest passes. Periodic and one-shot timer modes verified with correct tick counts across multiple runs. Standard variant test suite confirms no regressions from the conditional changes tomain.candgccollect.c.machine_timer.py(which testshard=Truecallbacks) segfaults because hard callbacks execute directly in the timer thread, which cannot safely call into the MicroPython VM. This is an inherent limitation of the pthread approach and matches the expected behavior -- hard callbacks require ISR-level execution on the main thread.Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the description above.