Skip to content

perf(main): write dshot NVIC priorities only on actual change#11

Open
dakejahl wants to merge 1 commit into
mainfrom
perf/nvic-priority-on-change
Open

perf(main): write dshot NVIC priorities only on actual change#11
dakejahl wants to merge 1 commit into
mainfrom
perf/nvic-priority-on-change

Conversation

@dakejahl

@dakejahl dakejahl commented Jun 22, 2026

Copy link
Copy Markdown

Summary

Write the DShot input / commutation NVIC priorities only when the desired priority scheme actually changes, instead of re-applying it on every main-loop pass.

Problem

Every main-loop iteration unconditionally called NVIC_SetPriority() for several interrupts based on dshot_telemetry && commutation_interval > threshold. That condition rarely changes, so the loop kept rewriting the same priority values.

Solution

Track the current scheme in input_priority_is_high (initialised to 0xFF so the first pass always applies it) and call NVIC_SetPriority() only on a transition. Identical resulting priorities, fewer register writes per loop. The flag is a static local scoped to the priority block rather than a file-scope global, so it also drops off the MCU_G031 / NEED_INPUT_READY targets that compile the block out.

@dakejahl dakejahl added risk:2 Low — isolated, verified, easy to reason about reviewed labels Jun 22, 2026
The dshot telemetry priority swap wrote three or four NVIC registers
on every main loop iteration even though the scheme flips rarely.
Track the current scheme in input_priority_is_high and skip the writes
when nothing changed. The 0xFF boot sentinel forces the first pass to
write, preserving the old boot behavior exactly.

input_priority_is_high is a static local scoped to the priority block
rather than a file global, so it also disappears on the MCU_G031 and
NEED_INPUT_READY targets that compile the block out.
@dakejahl dakejahl force-pushed the perf/nvic-priority-on-change branch from 4510bb0 to 8d15084 Compare June 22, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewed risk:2 Low — isolated, verified, easy to reason about

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant