perf(dshot): decode the frame in a single pass into one packed word#9
Open
dakejahl wants to merge 1 commit into
Open
perf(dshot): decode the frame in a single pass into one packed word#9dakejahl wants to merge 1 commit into
dakejahl wants to merge 1 commit into
Conversation
computeDshotDMA unpacked the 16 pulses into a 16-entry int array and then walked it three more times to assemble the CRC nibbles and the 11-bit value. Pack the pulses into one uint16_t as they are measured (bit 15-i is pulse i) and derive everything with shifts and masks: checkCRC = frame & 0xF, calcCRC = ((frame>>4)^(frame>>8)^(frame>>12)) & 0xF, value = frame >> 5, telemetry request = frame & 0x10. The inverted-CRC bidirectional case (~checkCRC) & 0xF equals the old ~checkCRC + 16 for all nibble values. Bit-for-bit equivalent to the old decode and frees the 64 byte dpulse array. While here, drop a redundant signaltimeout = 0 inside the CRC-match branch: the reset at the top of the valid-frametime block already runs on every path that reaches it, so the inner store was dead.
2aae2e0 to
2b58907
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
Decode the DShot frame in a single pass, packing the 16 pulse bits into one
uint16_tinstead of a 16-entry global array, and derive the CRC, throttle value and telemetry bit with shifts and masks.Problem
The decoder wrote each of the 16 decoded bits into a global
int dpulse[16](64 bytes of RAM) and then recombined them with long per-bit shift expressions to form the check/calculated CRC, the 11-bit value, and the telemetry flag.Solution
Pack the bits directly into a local
uint16_t frameas they are decoded, then compute everything with masks/shifts on that word. Functionally identical — verified bit-for-bit, including thedshot_telemetryCRC inversion (~x + 16and~x & 0xFare equal for a 4-bit value) — and it removes the 64-byte global. Also drops a redundantsignaltimeout = 0in the CRC-match branch: the reset at the top of the valid-frametime block already runs on every path that reaches it, so the inner one was dead (behavior unchanged).