Skip to content

Commit

Permalink
[spinel] create spinel interface based on the radio url protocol (ope…
Browse files Browse the repository at this point in the history
…nthread#9393)

The posix platform is able to support the HDLC, SPI and vendor spinel
interfaces, but the spinel interface type can't be changed
dynamically. It is inconvenient to use different spinel interfaces for
Thread stack in Android. This commit enables the posix platform to
support the HDLC, SPI and vendor interface at the same time, and the
final spinel interface type is determined by the radio url protocol.

Some other changes:
1. Not use CRTP style for the radio spinel.
2. Deprecate the OT_POSIX_CONFIG_RCP_BUS and
   OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL.
  • Loading branch information
zhanglongxia authored Oct 10, 2023
1 parent 2fe0770 commit 7568e31
Show file tree
Hide file tree
Showing 31 changed files with 823 additions and 679 deletions.
1 change: 1 addition & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ endmacro()

ot_removed_option(OT_MTD_NETDIAG "- Use OT_NETDIAG_CLIENT instead - note that server function is always supported")
ot_removed_option(OT_EXCLUDE_TCPLP_LIB "- Use OT_TCP instead, OT_EXCLUDE_TCPLP_LIB is deprecated")
ot_removed_option(OT_POSIX_CONFIG_RCP_BUS "- Use OT_POSIX_RCP_HDLC_BUS, OT_POSIX_RCP_SPI_BUS or OT_POSIX_RCP_VENDOR_BUS instead, OT_POSIX_CONFIG_RCP_BUS is deprecated")
4 changes: 2 additions & 2 deletions script/check-posix-build-cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ main()

if [[ $OSTYPE != "darwin"* ]]; then
reset_source
build -DOT_RCP_RESTORATION_MAX_COUNT=2 -DOT_POSIX_CONFIG_RCP_BUS=SPI "$@"
build -DOT_RCP_RESTORATION_MAX_COUNT=2 -DOT_POSIX_RCP_SPI_BUS=ON "$@"
fi

reset_source
build -DOT_POSIX_CONFIG_RCP_BUS=VENDOR "$@"
build -DOT_POSIX_RCP_VENDOR_BUS=ON "$@"
}

main "$@"
25 changes: 16 additions & 9 deletions src/lib/hdlc/hdlc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,23 @@ otError Encoder::EndFrame(void)
return error;
}

Decoder::Decoder(Spinel::FrameWritePointer &aFrameWritePointer, FrameHandler aFrameHandler, void *aContext)
Decoder::Decoder(void)
: mState(kStateNoSync)
, mWritePointer(aFrameWritePointer)
, mFrameHandler(aFrameHandler)
, mContext(aContext)
, mWritePointer(nullptr)
, mFrameHandler(nullptr)
, mContext(nullptr)
, mFcs(0)
, mDecodedLength(0)
{
}

void Decoder::Init(Spinel::FrameWritePointer &aFrameWritePointer, FrameHandler aFrameHandler, void *aContext)
{
mWritePointer = &aFrameWritePointer;
mFrameHandler = aFrameHandler;
mContext = aContext;
}

void Decoder::Reset(void)
{
mState = kStateNoSync;
Expand Down Expand Up @@ -254,7 +261,7 @@ void Decoder::Decode(const uint8_t *aData, uint16_t aLength)
)
{
// Remove the FCS from the frame.
mWritePointer.UndoLastWrites(kFcsSize);
mWritePointer->UndoLastWrites(kFcsSize);
error = OT_ERROR_NONE;
}

Expand All @@ -266,10 +273,10 @@ void Decoder::Decode(const uint8_t *aData, uint16_t aLength)
break;

default:
if (mWritePointer.CanWrite(sizeof(uint8_t)))
if (mWritePointer->CanWrite(sizeof(uint8_t)))
{
mFcs = UpdateFcs(mFcs, byte);
IgnoreError(mWritePointer.WriteByte(byte));
IgnoreError(mWritePointer->WriteByte(byte));
mDecodedLength++;
}
else
Expand All @@ -284,11 +291,11 @@ void Decoder::Decode(const uint8_t *aData, uint16_t aLength)
break;

case kStateEscaped:
if (mWritePointer.CanWrite(sizeof(uint8_t)))
if (mWritePointer->CanWrite(sizeof(uint8_t)))
{
byte ^= 0x20;
mFcs = UpdateFcs(mFcs, byte);
IgnoreError(mWritePointer.WriteByte(byte));
IgnoreError(mWritePointer->WriteByte(byte));
mDecodedLength++;
mState = kStateSync;
}
Expand Down
10 changes: 8 additions & 2 deletions src/lib/hdlc/hdlc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ class Decoder
*/
typedef void (*FrameHandler)(void *aContext, otError aError);

/**
* Initializes the object.
*
*/
Decoder(void);

/**
* Initializes the decoder.
*
Expand All @@ -148,7 +154,7 @@ class Decoder
* @param[in] aContext A pointer to arbitrary context information.
*
*/
Decoder(Spinel::FrameWritePointer &aFrameWritePointer, FrameHandler aFrameHandler, void *aContext);
void Init(Spinel::FrameWritePointer &aFrameWritePointer, FrameHandler aFrameHandler, void *aContext);

/**
* Feeds a block of data into the decoder.
Expand Down Expand Up @@ -179,7 +185,7 @@ class Decoder
};

State mState;
Spinel::FrameWritePointer &mWritePointer;
Spinel::FrameWritePointer *mWritePointer;
FrameHandler mFrameHandler;
void *mContext;
uint16_t mFcs;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/spinel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ declare_args() {

spinel_sources = [
"openthread-spinel-config.h",
"multi_frame_buffer.hpp",
"radio_spinel.cpp",
"radio_spinel.hpp",
"radio_spinel_impl.hpp",
"spi_frame.hpp",
"spinel.c",
"spinel_buffer.cpp",
Expand Down
1 change: 1 addition & 0 deletions src/lib/spinel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(COMMON_INCLUDES
)

set(COMMON_SOURCES
radio_spinel.cpp
spinel.c
spinel_buffer.cpp
spinel_decoder.cpp
Expand Down
12 changes: 12 additions & 0 deletions src/lib/spinel/openthread-spinel-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@
#ifndef OPENTHREAD_SPINEL_CONFIG_ABORT_ON_UNEXPECTED_RCP_RESET_ENABLE
#define OPENTHREAD_SPINEL_CONFIG_ABORT_ON_UNEXPECTED_RCP_RESET_ENABLE 0
#endif

/**
* @def OPENTHREAD_SPINEL_CONFIG_RCP_TIME_SYNC_INTERVAL
*
* This setting configures the interval (in units of microseconds) for host-rcp
* time sync. The host will recalculate the time offset between host and RCP
* every interval.
*
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_RCP_TIME_SYNC_INTERVAL
#define OPENTHREAD_SPINEL_CONFIG_RCP_TIME_SYNC_INTERVAL (60 * 1000 * 1000)
#endif
#endif // OPENTHREAD_SPINEL_CONFIG_H_
Loading

0 comments on commit 7568e31

Please sign in to comment.