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

update spinel_hdlc.cpp to use the latest RadioSpinel API #609

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openthread
Submodule openthread updated 44 files
+1 −0 etc/cmake/options.cmake
+1 −1 include/openthread/instance.h
+1 −0 include/openthread/ping_sender.h
+2 −2 script/check-posix-build-cmake
+13 −6 src/cli/README.md
+1 −1 src/cli/README_UDP.md
+21 −6 src/cli/cli.cpp
+151 −0 src/cli/cli_udp.cpp
+63 −58 src/core/net/ip6.cpp
+2 −2 src/core/net/ip6.hpp
+64 −54 src/core/net/ip6_mpl.cpp
+5 −6 src/core/net/ip6_mpl.hpp
+17 −27 src/core/thread/mesh_forwarder_ftd.cpp
+1 −0 src/core/utils/ping_sender.cpp
+16 −9 src/lib/hdlc/hdlc.cpp
+8 −2 src/lib/hdlc/hdlc.hpp
+2 −1 src/lib/spinel/BUILD.gn
+1 −0 src/lib/spinel/CMakeLists.txt
+12 −0 src/lib/spinel/openthread-spinel-config.h
+239 −300 src/lib/spinel/radio_spinel.cpp
+52 −76 src/lib/spinel/radio_spinel.hpp
+16 −0 src/lib/spinel/radio_spinel_metrics.h
+23 −6 src/lib/spinel/spinel_interface.hpp
+8 −0 src/lib/url/url.cpp
+2 −0 src/lib/url/url.hpp
+1 −1 src/ncp/ncp_hdlc.cpp
+17 −3 src/posix/platform/CMakeLists.txt
+38 −23 src/posix/platform/hdlc_interface.cpp
+28 −14 src/posix/platform/hdlc_interface.hpp
+0 −16 src/posix/platform/include/openthread/openthread-system.h
+34 −13 src/posix/platform/openthread-posix-config.h
+139 −118 src/posix/platform/radio.cpp
+44 −7 src/posix/platform/radio.hpp
+34 −14 src/posix/platform/radio_url.cpp
+36 −26 src/posix/platform/spi_interface.cpp
+28 −13 src/posix/platform/spi_interface.hpp
+1 −0 src/posix/platform/trel.cpp
+1 −1 src/posix/platform/vendor.cmake
+23 −11 src/posix/platform/vendor_interface.hpp
+11 −20 src/posix/platform/vendor_interface_example.cpp
+1 −0 tests/scripts/expect/cli-region.exp
+92 −2 tests/toranj/cli/test-008-multicast-traffic.py
+1 −1 tests/toranj/openthread-core-toranj-config-posix.h
+4 −2 tests/unit/test_hdlc.cpp
9 changes: 6 additions & 3 deletions src/imx_rt/platform/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@

#include "ot_platform_common.h"

#include <openthread/logging.h>
#include <openthread/platform/radio.h>

#include "spinel_hdlc.hpp"
#include <lib/platform/exit_code.h>
#include <lib/spinel/radio_spinel.hpp>

static ot::Spinel::RadioSpinel<ot::RT::HdlcInterface> sRadioSpinel;
static ot::Url::Url sUrl;
static ot::RT::HdlcInterface sSpinelInterface(sUrl);
static ot::Spinel::RadioSpinel sRadioSpinel;

void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
{
Expand Down Expand Up @@ -361,8 +365,7 @@ otRadioState otPlatRadioGetState(otInstance *aInstance)

void otPlatRadioInit(void)
{
sRadioSpinel.GetSpinelInterface().Init();
sRadioSpinel.Init(true, false);
sRadioSpinel.Init(sSpinelInterface, true, false);
}

void otPlatRadioDeinit(void)
Expand Down
26 changes: 17 additions & 9 deletions src/imx_rt/platform/spinel_hdlc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,33 @@ namespace ot {

namespace RT {

HdlcInterface::HdlcInterface(ot::Spinel::SpinelInterface::ReceiveFrameCallback aCallback,
void *aCallbackContext,
ot::Spinel::SpinelInterface::RxFrameBuffer &aFrameBuffer)
: mReceiveFrameCallback(aCallback)
, mReceiveFrameContext(aCallbackContext)
, mReceiveFrameBuffer(aFrameBuffer)
HdlcInterface::HdlcInterface(const Url::Url &aRadioUrl)
: mReceiveFrameCallback(nullptr)
, mReceiveFrameContext(nullptr)
, mReceiveFrameBuffer(nullptr)
, encoderBuffer()
, mHdlcEncoder(encoderBuffer)
, mHdlcDecoder(aFrameBuffer, HandleHdlcFrame, this)
, mHdlcDecoder()
{
OT_UNUSED_VARIABLE(aRadioUrl);
}

HdlcInterface::~HdlcInterface(void)
{
}

void HdlcInterface::Init(void)
otError HdlcInterface::Init(ot::Spinel::SpinelInterface::ReceiveFrameCallback aCallback,
void *aCallbackContext,
ot::Spinel::SpinelInterface::RxFrameBuffer &aFrameBuffer)
{
mReceiveFrameCallback = aCallback;
mReceiveFrameContext = aCallbackContext;
mReceiveFrameBuffer = &aFrameBuffer;
mHdlcDecoder.Init(aFrameBuffer, HandleHdlcFrame, this);

InitUart();

return OT_ERROR_NONE;
}

void HdlcInterface::Deinit(void)
Expand Down Expand Up @@ -237,7 +245,7 @@ void HdlcInterface::HandleHdlcFrame(otError aError)
else
{
OT_PLAT_DBG_NO_FUNC("Frame will be discarded error = 0x%x", aError);
mReceiveFrameBuffer.DiscardFrame();
mReceiveFrameBuffer->DiscardFrame();
}
}

Expand Down
52 changes: 37 additions & 15 deletions src/imx_rt/platform/spinel_hdlc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "lib/hdlc/hdlc.hpp"
#include "lib/spinel/multi_frame_buffer.hpp"
#include "lib/spinel/spinel_interface.hpp"
#include "lib/url/url.hpp"

namespace ot {

Expand All @@ -47,20 +48,16 @@ typedef uint8_t HdlcSpinelContext;
* This class defines an HDLC spinel interface to the Radio Co-processor (RCP).
*
*/
class HdlcInterface
class HdlcInterface : public ot::Spinel::SpinelInterface
{
public:
/**
* This constructor initializes the object.
*
* @param[in] aCallback Callback on frame received
* @param[in] aCallbackContext Callback context
* @param[in] aFrameBuffer A reference to a `RxFrameBuffer` object.
* @param[in] aRadioUrl RadioUrl parsed from radio url.
*
*/
HdlcInterface(ot::Spinel::SpinelInterface::ReceiveFrameCallback aCallback,
void *aCallbackContext,
ot::Spinel::SpinelInterface::RxFrameBuffer &aFrameBuffer);
HdlcInterface(const Url::Url &aRadioUrl);

/**
* This destructor deinitializes the object.
Expand All @@ -71,8 +68,12 @@ class HdlcInterface
/**
* This method initializes the HDLC interface.
*
* @param[in] aCallback Callback on frame received
* @param[in] aCallbackContext Callback context
* @param[in] aFrameBuffer A reference to a `RxFrameBuffer` object.
*
*/
void Init(void);
otError Init(ReceiveFrameCallback aCallback, void *aCallbackContext, RxFrameBuffer &aFrameBuffer);

/**
* This method deinitializes the HDLC interface.
Expand Down Expand Up @@ -108,19 +109,32 @@ class HdlcInterface
otError WaitForFrame(uint64_t aTimeoutUs);

/**
* This method performs radio driver processing.
* Updates the file descriptor sets with file descriptors used by the radio driver.
*
* @param[in] aInstance The ot instance
* @param[in,out] aMainloopContext A pointer to the mainloop context containing fd_sets.
*
*/
void Process(const void *aContext);
void UpdateFdSet(void *aMainloopContext) { OT_UNUSED_VARIABLE(aMainloopContext); }

/**
* This method is called when RCP is reset to recreate the connection with it.
* Intentionally empty.
* Returns the bus speed between the host and the radio.
*
* @returns Bus speed in bits/second.
*
*/
otError ResetConnection(void) { return OT_ERROR_NONE; }
uint32_t GetBusSpeed(void) const
{
static constexpr uint32_t kDefaultSpeed = 1000000;
return kDefaultSpeed;
}

/**
* This method performs radio driver processing.
*
* @param[in] aInstance The ot instance
*
*/
void Process(const void *aContext);

/**
* This method hardware resets the RCP.
Expand All @@ -131,6 +145,14 @@ class HdlcInterface
*/
otError HardwareReset(void) { return OT_ERROR_NOT_IMPLEMENTED; }

/**
* Returns the RCP interface metrics.
*
* @returns The RCP interface metrics.
*
*/
const otRcpInterfaceMetrics *GetRcpInterfaceMetrics(void) const { return nullptr; }

private:
enum
{
Expand All @@ -144,7 +166,7 @@ class HdlcInterface

ot::Spinel::SpinelInterface::ReceiveFrameCallback mReceiveFrameCallback;
void *mReceiveFrameContext;
ot::Spinel::SpinelInterface::RxFrameBuffer &mReceiveFrameBuffer;
ot::Spinel::SpinelInterface::RxFrameBuffer *mReceiveFrameBuffer;

ot::Spinel::FrameBuffer<ot::Spinel::SpinelInterface::kMaxFrameSize> encoderBuffer;
ot::Hdlc::Encoder mHdlcEncoder;
Expand Down