diff --git a/src/lib/spinel/radio_spinel.hpp b/src/lib/spinel/radio_spinel.hpp index 0d35de7d4..73dedfb80 100644 --- a/src/lib/spinel/radio_spinel.hpp +++ b/src/lib/spinel/radio_spinel.hpp @@ -742,45 +742,6 @@ public: */ otError SetChannelMaxTransmitPower(uint8_t aChannel, int8_t aPower); -private: - enum - { - kMaxSpinelFrame = SpinelInterface::kMaxFrameSize, - kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds. - kVersionStringSize = 128, ///< Max size of version string. - kCapsBufferSize = 100, ///< Max buffer size used to store `SPINEL_PROP_CAPS` value. - kChannelMaskBufferSize = 32, ///< Max buffer size used to store `SPINEL_PROP_PHY_CHAN_SUPPORTED` value. - }; - - enum State - { - kStateDisabled, ///< Radio is disabled. - kStateSleep, ///< Radio is sleep. - kStateReceive, ///< Radio is in receive mode. - kStateTransmitting, ///< Frame passed to radio for transmission, waiting for done event from radio. - kStateTransmitDone, ///< Radio indicated frame transmission is done. - }; - - typedef otError (RadioSpinel::*ResponseHandler)(const uint8_t *aBuffer, uint16_t aLength); - - static void HandleReceivedFrame(void *aContext); - - otError CheckSpinelVersion(void); - otError CheckRadioCapabilities(void); - otError CheckRcpApiVersion(bool aSupportsRcpApiVersion); - - /** - * This method triggers a state transfer of the state machine. - * - */ - void ProcessRadioStateMachine(void); - - /** - * This method processes the frame queue. - * - */ - void ProcessFrameQueue(void); - /** * This method tries to retrieve a spinel property from OpenThread transceiver. * @@ -857,6 +818,56 @@ private: */ otError Remove(spinel_prop_key_t aKey, const char *aFormat, ...); + /** + * This method tries to reset the co-processor. + * + * @prarm[in] aResetType The reset type, SPINEL_RESET_PLATFORM or SPINEL_RESET_STACK. + * + * @retval OT_ERROR_NONE Successfully removed item from the property. + * @retval OT_ERROR_BUSY Failed due to another operation is on going. + * + */ + otError SendReset(uint8_t aResetType); + +private: + enum + { + kMaxSpinelFrame = SpinelInterface::kMaxFrameSize, + kMaxWaitTime = 2000, ///< Max time to wait for response in milliseconds. + kVersionStringSize = 128, ///< Max size of version string. + kCapsBufferSize = 100, ///< Max buffer size used to store `SPINEL_PROP_CAPS` value. + kChannelMaskBufferSize = 32, ///< Max buffer size used to store `SPINEL_PROP_PHY_CHAN_SUPPORTED` value. + }; + + enum State + { + kStateDisabled, ///< Radio is disabled. + kStateSleep, ///< Radio is sleep. + kStateReceive, ///< Radio is in receive mode. + kStateTransmitting, ///< Frame passed to radio for transmission, waiting for done event from radio. + kStateTransmitDone, ///< Radio indicated frame transmission is done. + }; + + typedef otError (RadioSpinel::*ResponseHandler)(const uint8_t *aBuffer, uint16_t aLength); + + static void HandleReceivedFrame(void *aContext); + + otError CheckSpinelVersion(void); + otError CheckRadioCapabilities(void); + otError CheckRcpApiVersion(bool aSupportsRcpApiVersion); + + /** + * This method triggers a state transfer of the state machine. + * + */ + void ProcessRadioStateMachine(void); + + /** + * This method processes the frame queue. + * + */ + void ProcessFrameQueue(void); + spinel_tid_t GetNextTid(void); void FreeTid(spinel_tid_t tid) { mCmdTidsInUse &= ~(1 << tid); } @@ -878,12 +889,11 @@ private: const char * aFormat, va_list aArgs); otError WaitResponse(void); - otError SendReset(void); - otError SendCommand(uint32_t command, - spinel_prop_key_t key, - spinel_tid_t tid, - const char * pack_format, - va_list args); + otError SendCommand(uint32_t aCommand, + spinel_prop_key_t aKey, + spinel_tid_t aTid, + const char * aFormat, + va_list aArgs); otError ParseRadioFrame(otRadioFrame &aFrame, const uint8_t *aBuffer, uint16_t aLength, spinel_ssize_t &aUnpacked); otError ThreadDatasetHandler(const uint8_t *aBuffer, uint16_t aLength); diff --git a/src/lib/spinel/radio_spinel_impl.hpp b/src/lib/spinel/radio_spinel_impl.hpp index 7a7f78d66..2f673116f 100644 --- a/src/lib/spinel/radio_spinel_impl.hpp +++ b/src/lib/spinel/radio_spinel_impl.hpp @@ -48,6 +48,7 @@ #include "common/settings.hpp" #include "lib/platform/exit_code.h" #include "lib/spinel/radio_spinel.hpp" +#include "lib/spinel/spinel.h" #include "lib/spinel/spinel_decoder.hpp" #include "meshcop/dataset.hpp" #include "meshcop/meshcop_tlvs.hpp" @@ -233,7 +234,7 @@ void RadioSpinel::Init(bool aResetRadio, if (aResetRadio) { - SuccessOrExit(error = SendReset()); + SuccessOrExit(error = SendReset(SPINEL_RESET_STACK)); SuccessOrDie(mSpinelInterface.ResetConnection()); } @@ -1703,15 +1704,15 @@ spinel_tid_t RadioSpinel::GetNextTid(void) } template -otError RadioSpinel::SendReset(void) +otError RadioSpinel::SendReset(uint8_t aResetType) { otError error = OT_ERROR_NONE; uint8_t buffer[kMaxSpinelFrame]; spinel_ssize_t packed; // Pack the header, command and key - packed = - spinel_datatype_pack(buffer, sizeof(buffer), "Ci", SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_RESET); + packed = spinel_datatype_pack(buffer, sizeof(buffer), SPINEL_DATATYPE_COMMAND_S SPINEL_DATATYPE_UINT8_S, + SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_CMD_RESET, aResetType); VerifyOrExit(packed > 0 && static_cast(packed) <= sizeof(buffer), error = OT_ERROR_NO_BUFS); @@ -2256,7 +2257,7 @@ void RadioSpinel::RecoverFromRcpFailure(void) if (mResetRadioOnStartup) { - SuccessOrDie(SendReset()); + SuccessOrDie(SendReset(SPINEL_RESET_STACK)); SuccessOrDie(mSpinelInterface.ResetConnection()); } diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 973ee52bc..845349b9f 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -4728,6 +4728,9 @@ enum SPINEL_PROP_VENDOR__BEGIN = 0x3C00, SPINEL_PROP_VENDOR__END = 0x4000, + SPINEL_PROP_VENDOR_ESP__BEGIN = (SPINEL_PROP_VENDOR__BEGIN + 0), + SPINEL_PROP_VENDOR_ESP__END = (SPINEL_PROP_VENDOR__BEGIN + 128), + SPINEL_PROP_DEBUG__BEGIN = 0x4000, /// Testing platform assert