Optimize MCP2515Class::endPacket() by up to 2x #49
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.
Optimize MCP2515Class::endPacket()
Use LOAD TX BUFFER instruction to set TXBn* registers sequentially, as well
as to write into the TX data registers.
This is done with a single CS pull, and requires sending N+6 bytes over SPI.
The old code was doing N+5 writeRegister() calls, each doing 1 CS pull and
sending 3 bytes.
Use the 1-byte RTS SPI instruction instead of WRITEing to TXBnCTRL.
This reduces the number of bytes sent over SPI by 2.
For N = 8,
(2.8x reduction)
(6.5x reduction)
We still do at least 3 CS pulls and send at least 10 bytes over SPI for the
condition of the while(...TXBnCTRL...) loop, to clear TXnIF and to check for
errors.
That means for N = 8, in the case when we do zero iterations of the while loop,
we end up sending 25 bytes over SPI instead of 52, which is >2x reduction.