SPI Engine: fix off-by-one sleep time #1429
Merged
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.
Fixes error seen in #1389
Somewhat recently, during #1200, while fixing a related bug, I altered the documentation to reflect what was then the behavior of the SPI Engine for the Sleep instruction: it slept for
t
prescaler ticks.What I didn't realize back then was that the intended behavior, as seen on the first SPI Engine commit, is to sleep for
t+1
ticks, and that there had been a regression in the meantime.To illustrate, I've made some simple tests, which call the sleep instruction with a parameter of t=4. Expected behavior is for it to sleep for
t+1
ticks, as seen on first commit and as has been documented in the old wiki.This is with the current main (counts only
t
ticks):This is how it was before #1200
(before I changed the doc), it counts each tick as double the duration - that was the bug being solved, but is not relevant to the current PR. At this point, there had already been a regression (counts only
t
ticks):This is the behavior on the first commit for the SPI Engine (counts the correct number of
t+1
ticks):PR Type
PR Checklist