-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ncp-spi] improve callback implementation, change code style format #2734
Conversation
src/ncp/ncp_spi.hpp
Outdated
{ | ||
kLength = 5, // SPI header length | ||
kFlagReset = (1 << 7), | ||
kFlagCrc = (1 << 6), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Not currently. I will remove it.
src/ncp/ncp_spi.hpp
Outdated
static void SetFlagByte(uint8_t *aFrame, uint8_t aFlags) { aFrame[kIndexFlagByte] = aFlags; } | ||
static uint8_t GetFlagByte(const uint8_t *aFrame) { return aFrame[kIndexFlagByte]; } | ||
|
||
static bool IsFlagValid(const uint8_t *aFrame) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these methods take a "frame". How about having a frame class that has non-static methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
In new pushed commit, added |
src/ncp/ncp_spi.cpp
Outdated
{ | ||
uint16_t rxDataLen = inputFrame.GetHeaderDataLen(); | ||
|
||
if ((rxDataLen > 0) && (rxDataLen <= transDataLen) && (rxDataLen <= outputFrame.GetHeaderAcceptLen())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is a little cryptic. Could you explain it with a comment.
This commit makes the following changes in `NcpSpi` class: - It adds a new class `SpiFrame` which provides helper methods to parse and update the header fields in the header of an SPI frame. - It simplifies/enhances the `SpiTransactionComplete()` callback implementation by combining the parsing of input/output frame headers with the rx/tx frame processing. - It adds a check for correct pattern bits in a received frame flag byte (frames with incorrect pattern bits are ignored). - Code format is changed to follow the "pretty" style. - Fixes a rare issue with a possible incorrect accept length on the first SPI transaction after NCP reset.
Verified/tested this change on a device with SPI interface (to wpantund). |
…s/COM-4614 to master * commit '769b0a5e74602c75600bfc218cbcff8a969bd164': (38 commits) [efr32] add BRD4304A (MGM12P) support and board-specific hal-config.h (openthread#2763) [mle] enhance the route table log message (openthread#2780) [posix] skip calling RadioReceiveDone with OT_ERROR_ABORT (openthread#2779) [docker] dockerfiles for openthread sim and wpantund (openthread#2760) [lowpan] use BigEndian::ReadUint16() (openthread#2774) [docs] updating Doxygen tags for ble module (openthread#2777) [toranj] add test-case for child table and child recovery (openthread#2776) [mesh-forwarder] do not log dropping of received beacon frames (openthread#2773) [string] adding ot::String<size> class (openthread#2764) [ncp-spi] improve callback implementation, change code style format (openthread#2734) [network-diagnostic] REED should omit ChildTable TLV request (openthread#2772) [data-poll] only allow data polling when rx-off-when-idle (openthread#2770) [mle] implement MLE Data Request retransmissions (openthread#2766) [mesh-forwarder] do not treat CCA failures the same as no-ack (openthread#2765) [nrf52840] fix cc310 with mbedtls 2.9.0 (openthread#2756) [mbedtls] do not treat visual studio build warnings as errors (openthread#2756) [mbedtls] remove v2.6.1 (openthread#2756) [scan-build] define KEY_EXCHANGE_ECDHE_ECDSA_ENABLED to avoid warnings (openthread#2756) [mbedtls] update cc2650 sha256_alt to new mbedtls API (openthread#2756) [mbedtls] update nrf52840 sha256_alt to new mbedtls APIs (openthread#2756) ...
This commit makes the following changes in
NcpSpi
class:NcpSpi::Header
which provide helpermethods to parse and update the fields in the header of an SPI
frame.
SpiTransactionComplete()
callbackimplementation by combining the parsing of input/output frame
headers with the rx/tx frame processing.
flag byte (frames with incorrect pattern bits are ignored).