Skip to content

unix: Add zephyr_ble variant with soft timer and machine.Timer#33

Draft
andrewleech wants to merge 1 commit intoreview/unix-soft-timerfrom
worktree-agent-a8bac144
Draft

unix: Add zephyr_ble variant with soft timer and machine.Timer#33
andrewleech wants to merge 1 commit intoreview/unix-soft-timerfrom
worktree-agent-a8bac144

Conversation

@andrewleech
Copy link
Copy Markdown
Owner

Summary

Adds a zephyr_ble Unix variant with pthread-based soft timer infrastructure and machine.Timer support. 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 with MICROPY_PY_PENDSV_ENTER/EXIT provides thread-safe access to the timer heap. SIGUSR1 interrupts the main thread's blocking syscalls (via MICROPY_SCHED_HOOK_SCHEDULED) so scheduled callbacks are processed promptly during time.sleep() and similar.

Testing

Built and tested on Linux x86_64. machine_soft_timer.py test 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 to main.c and gccollect.c.

machine_timer.py (which tests hard=True callbacks) 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.

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-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 26, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.49%. Comparing base (e4920d6) to head (5bdc38c).
⚠️ Report is 52 commits behind head on review/unix-soft-timer.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

Code size report:

Reference:  esp32/boards/SEEED_XIAO_ESP32C6: Add new XIAO board definition. [2dc2e30]
Comparison: unix: Add zephyr_ble variant with soft timer and machine.Timer support. [merge of 5bdc38c]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants