Skip to content

Commit

Permalink
Merge changes from topic "b/277286756"
Browse files Browse the repository at this point in the history
* changes:
  [spinel] fix the non-virtual destructor error (openthread#9139)
  [posix] unify the spinel interface functions (openthread#9107)
  • Loading branch information
zhanglongxia authored and Gerrit Code Review committed Jun 8, 2023
2 parents 2bbcc46 + 86ad280 commit 932b9de
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 15 deletions.
87 changes: 87 additions & 0 deletions src/lib/spinel/spinel_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,93 @@ class SpinelInterface
return (aLength >= sizeof(kSpinelResetCommand)) &&
(memcmp(aFrame, kSpinelResetCommand, sizeof(kSpinelResetCommand)) == 0);
}

/**
* Initializes the interface to the Radio Co-processor (RCP)
*
* @note This method should be called before reading and sending spinel frames to the interface.
*
* @param[in] aRadioUrl RadioUrl parsed from radio url.
*
* @retval OT_ERROR_NONE The interface is initialized successfully
* @retval OT_ERROR_ALREADY The interface is already initialized.
* @retval OT_ERROR_INVALID_ARGS The UART device or executable cannot be found or failed to open/run.
*
*/
virtual otError Init(const Url::Url &aRadioUrl) = 0;

/**
* Deinitializes the interface to the RCP.
*
*/
virtual void Deinit(void) = 0;

/**
* Encodes and sends a spinel frame to Radio Co-processor (RCP) over the socket.
*
* @param[in] aFrame A pointer to buffer containing the spinel frame to send.
* @param[in] aLength The length (number of bytes) in the frame.
*
* @retval OT_ERROR_NONE Successfully encoded and sent the spinel frame.
* @retval OT_ERROR_BUSY Failed due to another operation is on going.
* @retval OT_ERROR_NO_BUFS Insufficient buffer space available to encode the frame.
* @retval OT_ERROR_FAILED Failed to call the SPI driver to send the frame.
*
*/
virtual otError SendFrame(const uint8_t *aFrame, uint16_t aLength) = 0;

/**
* Waits for receiving part or all of spinel frame within specified interval.
*
* @param[in] aTimeout The timeout value in microseconds.
*
* @retval OT_ERROR_NONE Part or all of spinel frame is received.
* @retval OT_ERROR_RESPONSE_TIMEOUT No spinel frame is received within @p aTimeout.
*
*/
virtual otError WaitForFrame(uint64_t aTimeoutUs) = 0;

/**
* Updates the file descriptor sets with file descriptors used by the radio driver.
*
* @param[in,out] aReadFdSet A reference to the read file descriptors.
* @param[in,out] aWriteFdSet A reference to the write file descriptors.
* @param[in,out] aMaxFd A reference to the max file descriptor.
* @param[in,out] aTimeout A reference to the timeout.
*
*/
virtual void UpdateFdSet(fd_set &aReadFdSet, fd_set &aWriteFdSet, int &aMaxFd, struct timeval &aTimeout) = 0;

/**
* Performs radio driver processing.
*
* @param[in] aContext The context containing fd_sets.
*
*/
virtual void Process(const RadioProcessContext &aContext) = 0;

/**
* Returns the bus speed between the host and the radio.
*
* @returns Bus speed in bits/second.
*
*/
virtual uint32_t GetBusSpeed(void) const = 0;

/**
* Hardware resets the RCP.
*
* @retval OT_ERROR_NONE Successfully reset the RCP.
* @retval OT_ERROR_NOT_IMPLEMENT The hardware reset is not implemented.
*
*/
virtual otError HardwareReset(void) = 0;

/**
* Marks destructor virtual method.
*
*/
virtual ~SpinelInterface() = default;
};
} // namespace Spinel
} // namespace ot
Expand Down
6 changes: 1 addition & 5 deletions src/posix/platform/hdlc_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@
#include "lib/spinel/openthread-spinel-config.h"
#include "lib/spinel/spinel_interface.hpp"

#if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_UART

namespace ot {
namespace Posix {

/**
* This class defines an HDLC interface to the Radio Co-processor (RCP)
*
*/
class HdlcInterface
class HdlcInterface : public ot::Spinel::SpinelInterface
{
public:
/**
Expand Down Expand Up @@ -278,6 +276,4 @@ class HdlcInterface

} // namespace Posix
} // namespace ot

#endif // OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_UART
#endif // POSIX_APP_HDLC_INTERFACE_HPP_
5 changes: 1 addition & 4 deletions src/posix/platform/spi_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

#include <openthread/openthread-system.h>

#if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_SPI

#include "ncp/ncp_spi.hpp"

namespace ot {
Expand All @@ -53,7 +51,7 @@ namespace Posix {
* This class defines an SPI interface to the Radio Co-processor (RCP).
*
*/
class SpiInterface
class SpiInterface : public ot::Spinel::SpinelInterface
{
public:
/**
Expand Down Expand Up @@ -256,5 +254,4 @@ class SpiInterface
} // namespace Posix
} // namespace ot

#endif // OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_SPI
#endif // POSIX_APP_SPI_INTERFACE_HPP_
7 changes: 2 additions & 5 deletions src/posix/platform/vendor_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@
#include "platform-posix.h"
#include "lib/spinel/spinel_interface.hpp"

#if OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_VENDOR

namespace ot {
namespace Posix {

/**
* This class defines a vendor interface to the Radio Co-processor (RCP).
*
*/
class VendorInterface
class VendorInterface : public ot::Spinel::SpinelInterface
{
public:
/**
Expand Down Expand Up @@ -158,11 +156,10 @@ class VendorInterface
* @returns The RCP interface metrics.
*
*/
const otRcpInterfaceMetrics *GetRcpInterfaceMetrics(void);
const otRcpInterfaceMetrics *GetRcpInterfaceMetrics(void) const;
};

} // namespace Posix
} // namespace ot

#endif // OPENTHREAD_POSIX_CONFIG_RCP_BUS == OT_POSIX_RCP_BUS_VENDOR
#endif // POSIX_APP_VENDOR_INTERFACE_HPP_
2 changes: 1 addition & 1 deletion src/posix/platform/vendor_interface_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ otError VendorInterface::SendFrame(const uint8_t *aFrame, uint16_t aLength)
return OT_ERROR_NONE;
}

const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void)
const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void) const
{
// TODO: Implement vendor code here.

Expand Down

0 comments on commit 932b9de

Please sign in to comment.