perf(main): write dshot NVIC priorities only on actual change#11
Open
dakejahl wants to merge 1 commit into
Open
perf(main): write dshot NVIC priorities only on actual change#11dakejahl wants to merge 1 commit into
dakejahl wants to merge 1 commit into
Conversation
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.
4510bb0 to
8d15084
Compare
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
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 ondshot_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 callNVIC_SetPriority()only on a transition. Identical resulting priorities, fewer register writes per loop. The flag is astaticlocal scoped to the priority block rather than a file-scope global, so it also drops off theMCU_G031/NEED_INPUT_READYtargets that compile the block out.