feat(openthread): modification of uart and spi spinel based on openthread 41ef807

This commit is contained in:
Xu Si Yu
2023-11-22 19:15:55 +08:00
committed by zwx
parent 6221119c2f
commit 7e469f1330
12 changed files with 404 additions and 157 deletions

View File

@@ -14,18 +14,12 @@
namespace esp {
namespace openthread {
class SpiSpinelInterface {
class SpiSpinelInterface : public ot::Spinel::SpinelInterface {
public:
/**
* @brief This constructor of object.
*
* @param[in] callback Callback on frame received
* @param[in] callback_context Callback context
* @param[in] frame_buffer A reference to a `RxFrameBuffer` object.
*
*/
SpiSpinelInterface(ot::Spinel::SpinelInterface::ReceiveFrameCallback callback, void *callback_context,
ot::Spinel::SpinelInterface::RxFrameBuffer &frame_buffer);
SpiSpinelInterface();
/**
* @brief This destructor of the object.
@@ -34,24 +28,26 @@ public:
~SpiSpinelInterface(void);
/**
* @brief This method initializes the spinel interface.
* 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] aCallback Callback on frame received
* @param[in] aCallbackContext Callback context
* @param[in] aFrameBuffer A reference to a `RxFrameBuffer` object.
*
* @retval OT_ERROR_NONE The interface is initialized successfully
* @retval OT_ERROR_ALREADY The interface is already initialized.
* @retval OT_ERROR_FAILED Failed to initialize the interface.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if already initialized
* - ESP_ERR_NO_MEM if allocation has failed
* - ESP_FAIL on failure
*/
esp_err_t Init(const esp_openthread_spi_host_config_t &spi_config);
otError Init(ReceiveFrameCallback aCallback, void *aCallbackContext, RxFrameBuffer &aFrameBuffer);
/**
* @brief This method deinitializes the HDLC interface.
* Deinitializes the interface to the RCP.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure
*/
esp_err_t Deinit(void);
void Deinit(void);
/**
* @brief This method encodes and sends a spinel frame to Radio Co-processor (RCP) over the socket.
@@ -80,20 +76,42 @@ public:
otError WaitForFrame(uint64_t timeout_us);
/**
* This method performs spi processing to the RCP.
* Updates the file descriptor sets with file descriptors used by the radio driver.
*
* @param[in] mainloop The mainloop context
* @param[in,out] aMainloopContext A pointer to the mainloop context.
*
*/
void Process(const void *mainloop);
void UpdateFdSet(void *aMainloopContext);
/**
* This methods updates the mainloop context.
* Performs radio driver processing.
*
* @param[inout] mainloop The mainloop context.
* @param[in] aMainloopContext A pointer to the mainloop context.
*
*/
void Update(void *mainloop);
void Process(const void *aMainloopContext);
/**
* Returns the bus speed between the host and the radio.
*
* @returns Bus speed in bits/second.
*
*/
uint32_t GetBusSpeed(void) const;
/**
* This method is called when RCP failure detected and resets internal states of the interface.
*
*/
otError HardwareReset(void);
/**
* Returns the RCP interface metrics.
*
* @returns The RCP interface metrics.
*
*/
const otRcpInterfaceMetrics *GetRcpInterfaceMetrics(void) const { return &mInterfaceMetrics; }
/**
* This methods registers the callback for RCP failure.
@@ -111,10 +129,33 @@ public:
otError ResetConnection(void) { return OT_ERROR_NONE; }
/**
* This method is called when RCP failure detected and resets internal states of the interface.
* @brief This method enable the spinel interface.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if already initialized
* - ESP_ERR_NO_MEM if allocation has failed
* - ESP_FAIL on failure
*/
otError HardwareReset(void);
esp_err_t Enable(const esp_openthread_spi_host_config_t &spi_config);
/**
* @brief This method disable the spinel interface.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure
*/
esp_err_t Disable(void);
/**
* @brief This method should be called after radio is initialized.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure
*/
esp_err_t AfterRadioInit(void);
private:
static constexpr uint8_t kSPIFrameHeaderSize = 5;
@@ -130,14 +171,16 @@ private:
int m_event_fd;
volatile uint16_t m_pending_data_len;
ot::Spinel::SpinelInterface::ReceiveFrameCallback m_receiver_frame_callback;
ReceiveFrameCallback m_receiver_frame_callback;
void *m_receiver_frame_context;
ot::Spinel::SpinelInterface::RxFrameBuffer &m_receive_frame_buffer;
RxFrameBuffer *m_receive_frame_buffer;
bool m_has_pending_device_frame;
spi_device_handle_t m_device;
esp_openthread_rcp_failure_handler mRcpFailureHandler;
otRcpInterfaceMetrics mInterfaceMetrics;
};
} // namespace openthread