Skip to content

Commit f6fa9bb

Browse files
committed
[spinel] add coprocessor reset failure callback
1 parent bc54d67 commit f6fa9bb

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

src/lib/spinel/openthread-spinel-config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,13 @@
163163
#define OPENTHREAD_SPINEL_CONFIG_RCP_TX_WAIT_TIME_SECS 5
164164
#endif
165165

166+
/**
167+
* @def OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
168+
*
169+
* Enables Co-processor reset failure callback in Spinel driver
170+
*/
171+
#ifndef OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
172+
#define OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE 0
173+
#endif
174+
166175
#endif // OPENTHREAD_SPINEL_CONFIG_H_

src/lib/spinel/spinel_driver.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ SpinelDriver::SpinelDriver(void)
5252
, mSpinelVersionMajor(-1)
5353
, mSpinelVersionMinor(-1)
5454
, mIsCoprocessorReady(false)
55+
#if OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
56+
, mCoprocessorResetFailureCallback(nullptr)
57+
, mCoprocessorResetFailureContext(nullptr)
58+
#endif
5559
{
5660
memset(mVersion, 0, sizeof(mVersion));
5761

@@ -119,6 +123,15 @@ otError SpinelDriver::SendReset(uint8_t aResetType)
119123
return error;
120124
}
121125

126+
#if OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
127+
void SpinelDriver::SetCoprocessorResetFailureCallback(otSpinelDriverCoprocessorResetFailureCallback aCallback,
128+
void *aContext)
129+
{
130+
mCoprocessorResetFailureCallback = aCallback;
131+
mCoprocessorResetFailureContext = aContext;
132+
}
133+
#endif
134+
122135
void SpinelDriver::ResetCoprocessor(bool aSoftwareReset)
123136
{
124137
bool hardwareReset;
@@ -129,7 +142,8 @@ void SpinelDriver::ResetCoprocessor(bool aSoftwareReset)
129142
VerifyOrExit(!mIsCoprocessorReady, resetDone = true);
130143
#endif
131144

132-
mWaitingKey = SPINEL_PROP_LAST_STATUS;
145+
mIsCoprocessorReady = false;
146+
mWaitingKey = SPINEL_PROP_LAST_STATUS;
133147

134148
if (aSoftwareReset && (SendReset(SPINEL_RESET_STACK) == OT_ERROR_NONE) && (WaitResponse() == OT_ERROR_NONE))
135149
{
@@ -143,23 +157,20 @@ void SpinelDriver::ResetCoprocessor(bool aSoftwareReset)
143157
if (hardwareReset)
144158
{
145159
SuccessOrExit(WaitResponse());
146-
}
147-
148-
resetDone = true;
149-
150-
if (hardwareReset)
151-
{
160+
resetDone = true;
152161
LogInfo("Hardware reset co-processor successfully");
153162
}
154-
else
155-
{
156-
LogInfo("co-processor self reset successfully");
157-
}
158163

159164
exit:
160165
if (!resetDone)
161166
{
162167
LogCrit("Failed to reset co-processor!");
168+
#if OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
169+
if (mCoprocessorResetFailureCallback)
170+
{
171+
mCoprocessorResetFailureCallback(mCoprocessorResetFailureContext);
172+
}
173+
#endif
163174
DieNow(OT_EXIT_FAILURE);
164175
}
165176
}

src/lib/spinel/spinel_driver.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ class SpinelDriver : public otSpinelDriver, public Logger
215215
*/
216216
spinel_iid_t GetIid(void) { return mIid; }
217217

218+
#if OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
219+
/**
220+
* A callback type for handling Co-processor reset failure of spinel driver.
221+
*
222+
* @param[in] aContext A pointer to the user context.
223+
*/
224+
typedef void (*otSpinelDriverCoprocessorResetFailureCallback)(void *aContext);
225+
226+
/**
227+
* Registers a callback to handle Co-processor reset failure of Spinel driver.
228+
*
229+
* This function is used to register a callback to handle Co-processor reset failure.
230+
* When the Spinel driver fails to reset the Co-processor through both software and
231+
* hardware resets, the user can handle the error through the callback(such as OTA).
232+
*
233+
* @param[in] aCallback The callback.
234+
* @param[in] aContext A pointer to the user context.
235+
*/
236+
void SetCoprocessorResetFailureCallback(otSpinelDriverCoprocessorResetFailureCallback aCallback, void *aContext);
237+
#endif
238+
218239
private:
219240
static constexpr uint16_t kMaxSpinelFrame = SPINEL_FRAME_MAX_SIZE;
220241
static constexpr uint16_t kVersionStringSize = 128;
@@ -314,6 +335,11 @@ class SpinelDriver : public otSpinelDriver, public Logger
314335
char mVersion[kVersionStringSize];
315336

316337
Array<unsigned int, kCapsBufferSize> mCoprocessorCaps;
338+
339+
#if OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE
340+
otSpinelDriverCoprocessorResetFailureCallback mCoprocessorResetFailureCallback;
341+
void *mCoprocessorResetFailureContext;
342+
#endif
317343
};
318344

319345
} // namespace Spinel

0 commit comments

Comments
 (0)