Skip to content
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

Merged
merged 1 commit into from
Jun 11, 2018

Conversation

abtink
Copy link
Member

@abtink abtink commented May 23, 2018

This commit makes the following changes in NcpSpi class:

  • It adds a new class NcpSpi::Header which provide helper
    methods to parse and update the 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.

{
kLength = 5, // SPI header length
kFlagReset = (1 << 7),
kFlagCrc = (1 << 6),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Member Author

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.

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)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@abtink
Copy link
Member Author

abtink commented May 29, 2018

In new pushed commit, added SpiFrame class.

{
uint16_t rxDataLen = inputFrame.GetHeaderDataLen();

if ((rxDataLen > 0) && (rxDataLen <= transDataLen) && (rxDataLen <= outputFrame.GetHeaderAcceptLen()))
Copy link
Contributor

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.
@abtink
Copy link
Member Author

abtink commented Jun 9, 2018

Verified/tested this change on a device with SPI interface (to wpantund).

@jwhui jwhui merged commit 90b160c into openthread:master Jun 11, 2018
@abtink abtink deleted the pr/ncp-spi-update branch August 22, 2019 05:55
zhanglongxia pushed a commit to zhanglongxia/openthread that referenced this pull request Nov 11, 2019
…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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants