Skip to content

Serialize sensor measurements with BLE sessions - #76

Merged
MacNite merged 2 commits into
claude/blissful-turing-8edvzofrom
codex/fix-microphone-shutdown-during-measurement-cycle
Sep 8, 2026
Merged

Serialize sensor measurements with BLE sessions#76
MacNite merged 2 commits into
claude/blissful-turing-8edvzofrom
codex/fix-microphone-shutdown-during-measurement-cycle

Conversation

@MacNite

@MacNite MacNite commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent audio sessions from starting inside a long-running sensor measurement cycle that can reconfigure/stop the PDM and power off the microphone rail.
  • Ensure the sensor rail is not silently turned off by a different caller when another user enabled it, avoiding latent ownership bugs and mid-session power loss.

Description

  • Add a session gate semaphore session_gate and APIs link_measurement_begin() / link_measurement_end() to serialise an entire powered measurement cycle against BLE sessions so a session either starts before a cycle or waits for it to finish.
  • Keep GATT callbacks non-blocking by making link_claim() non-blocking (returns busy when the gate is unavailable) and transferring long work to session threads; move audio rail enable + mic_stream_start() out of the GATT write callback into the audio capture thread.
  • Make the sensor rail refcounted and mutex-protected (sensor_rail_users with sensor_rail_lock) so each successful power_sensor_rail_enable() increments an owner count and the hardware is disabled only when the last matching power_sensor_rail_disable() runs.
  • Update documentation/comments: clarify mic.h to state that the session gate guarantees exclusivity between the one-shot measurement path and streaming PDM capture, and ensure the main measurement loop now holds the session gate for the full cycle.

Testing

  • git diff --check and repository integrity checks were executed and reported no issues.
  • The Zephyr/west --sysbuild images were not built because west was unavailable in the execution environment, so the three configured build profiles and the firmware size delta could not be measured.
  • Hardware behavioural validation (repeated 30-second recordings including START while a measurement cycle is running) was not run here and remains required to confirm the microphone-power and PDM exclusivity fixes on target hardware.

Codex Task

@MacNite
MacNite merged commit 6ef6029 into claude/blissful-turing-8edvzo Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant