[diag] deprecate otPlatDiagRadioTransmitDone() and otPlatDiagRadioReceiveDone() (#11615)

The radio platform API otPlatDiagRadioTransmitDone() and
otPlatDiagRadioReceiveDone() are the same with the API
otPlatRadioTxDone() and otPlatRadioReceiveDone(). This commit removes
the API otPlatDiagRadioTransmitDone() and otPlatDiagRadioReceiveDone()
to let the MAC layer and the diag module to use the same radio API to
send and receive 154 frames. So that the diag module could process the
ACK frame in the future.
This commit is contained in:
Zhanglong Xia
2025-07-09 08:14:18 -07:00
committed by GitHub
parent 87a919fd0a
commit 4764e6e714
9 changed files with 73 additions and 106 deletions
+3 -33
View File
@@ -612,17 +612,7 @@ static void radioReceive(otInstance *aInstance)
sState = OT_RADIO_STATE_RECEIVE;
sTxWait = false;
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone(aInstance, &sTransmitFrame, OT_ERROR_NONE);
}
else
#endif
{
otPlatRadioTxDone(aInstance, &sTransmitFrame, (isAck ? &sReceiveFrame : NULL), OT_ERROR_NONE);
}
otPlatRadioTxDone(aInstance, &sTransmitFrame, (isAck ? &sReceiveFrame : NULL), OT_ERROR_NONE);
}
else if (!isAck || sPromiscuous)
{
@@ -667,18 +657,7 @@ void radioSendMessage(otInstance *aInstance)
if (!sTxWait)
{
sState = OT_RADIO_STATE_RECEIVE;
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet())
{
otPlatDiagRadioTransmitDone(aInstance, &sTransmitFrame, OT_ERROR_NONE);
}
else
#endif
{
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
}
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
}
#else
// Wait for echo radio in virtual time mode.
@@ -885,16 +864,7 @@ exit:
if (error != OT_ERROR_ABORT)
{
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet())
{
otPlatDiagRadioReceiveDone(aInstance, error == OT_ERROR_NONE ? &sReceiveFrame : NULL, error);
}
else
#endif
{
otPlatRadioReceiveDone(aInstance, error == OT_ERROR_NONE ? &sReceiveFrame : NULL, error);
}
otPlatRadioReceiveDone(aInstance, error == OT_ERROR_NONE ? &sReceiveFrame : NULL, error);
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
*
* @note This number versions both OpenThread platform and user APIs.
*/
#define OPENTHREAD_API_VERSION (517)
#define OPENTHREAD_API_VERSION (518)
/**
* @addtogroup api-instance
+6
View File
@@ -910,6 +910,9 @@ extern void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame,
/**
* The radio driver calls this function to notify OpenThread diagnostics module of a received frame.
*
* @note This function is deprecated and will be removed in the future. It is recommended to use the function
* `otPlatRadioReceiveDone()`.
*
* Is used when diagnostics is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
@@ -982,6 +985,9 @@ extern void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, otRad
/**
* The radio driver calls this function to notify OpenThread diagnostics module that the transmission has completed.
*
* @note This function is deprecated and will be removed in the future. It is recommended to use the function
* `otPlatRadioTxDone()`.
*
* Is used when diagnostics is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
+7 -7
View File
@@ -154,7 +154,7 @@ Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
otPlatDiagModeSet(true);
Get<Radio>().SetDiagMode(true);
return kErrorNone;
}
@@ -164,7 +164,7 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgsLength);
OT_UNUSED_VARIABLE(aArgs);
otPlatDiagModeSet(false);
Get<Radio>().SetDiagMode(false);
return kErrorNone;
}
@@ -500,7 +500,7 @@ Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[])
otPlatAlarmMilliStop(&GetInstance());
SuccessOrExit(error = Get<Radio>().Receive(mChannel));
SuccessOrExit(error = Get<Radio>().SetTransmitPower(mTxPower));
otPlatDiagModeSet(true);
Get<Radio>().SetDiagMode(true);
mStats.Clear();
exit:
@@ -547,7 +547,7 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
OT_UNUSED_VARIABLE(aArgs);
otPlatAlarmMilliStop(&GetInstance());
otPlatDiagModeSet(false);
Get<Radio>().SetDiagMode(false);
Get<Radio>().SetPromiscuous(false);
Get<Mac::SubMac>().SetRxOnWhenIdle(false);
@@ -1195,11 +1195,11 @@ Error Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[])
if (aArgsLength == 0)
{
Output("diagnostics mode is %s\r\n", otPlatDiagModeGet() ? "enabled" : "disabled");
Output("diagnostics mode is %s\r\n", IsEnabled() ? "enabled" : "disabled");
ExitNow();
}
if (!otPlatDiagModeGet() && !StringMatch(aArgs[0], "start"))
if (!IsEnabled() && !StringMatch(aArgs[0], "start"))
{
Output("diagnostics mode is disabled\r\n");
ExitNow(error = kErrorInvalidState);
@@ -1249,7 +1249,7 @@ void Diags::Output(const char *aFormat, ...)
va_end(args);
}
bool Diags::IsEnabled(void) { return otPlatDiagModeGet(); }
bool Diags::IsEnabled(void) { return Get<Radio>().GetDiagMode(); }
} // namespace FactoryDiags
} // namespace ot
+25
View File
@@ -38,6 +38,7 @@
#include <openthread/radio_stats.h>
#include <openthread/platform/crypto.h>
#include <openthread/platform/diag.h>
#include <openthread/platform/radio.h>
#include "common/locator.hpp"
@@ -847,6 +848,22 @@ public:
*/
uint32_t GetBusLatency(void);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
/**
* Enables/disables the factory diagnostics mode.
*
* @param[in] aMode TRUE to enable diagnostics mode, FALSE otherwise.
*/
void SetDiagMode(bool aMode);
/**
* Gets the current diagnostic mode of the radio.
*
* @returns TRUE if factory diagnostics mode is enabled, FALSE otherwise.
*/
bool GetDiagMode(void);
#endif
private:
otInstance *GetInstancePtr(void) const { return reinterpret_cast<otInstance *>(&InstanceLocator::GetInstance()); }
@@ -1029,6 +1046,10 @@ inline uint32_t Radio::GetBusSpeed(void) { return otPlatRadioGetBusSpeed(GetInst
inline uint32_t Radio::GetBusLatency(void) { return otPlatRadioGetBusLatency(GetInstancePtr()); }
#if OPENTHREAD_CONFIG_DIAG_ENABLE
inline void Radio::SetDiagMode(bool aMode) { otPlatDiagModeSet(aMode); }
inline bool Radio::GetDiagMode(void) { return otPlatDiagModeGet(); }
#endif
#else //----------------------------------------------------------------------------------------------------------------
inline otRadioCaps Radio::GetCaps(void)
@@ -1133,6 +1154,10 @@ inline uint32_t Radio::GetBusSpeed(void) { return 0; }
inline uint32_t Radio::GetBusLatency(void) { return 0; }
#if OPENTHREAD_CONFIG_DIAG_ENABLE
inline void Radio::SetDiagMode(bool) {}
inline bool Radio::GetDiagMode(void) { return false; }
#endif
#endif // #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
} // namespace ot
+29 -9
View File
@@ -57,7 +57,16 @@ extern "C" void otPlatRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFra
}
#endif
instance.Get<Radio::Callbacks>().HandleReceiveDone(rxFrame, aError);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (instance.Get<Radio>().GetDiagMode())
{
instance.Get<Radio::Callbacks>().HandleDiagsReceiveDone(rxFrame, aError);
}
else
#endif
{
instance.Get<Radio::Callbacks>().HandleReceiveDone(rxFrame, aError);
}
exit:
return;
@@ -97,8 +106,26 @@ extern "C" void otPlatRadioTxDone(otInstance *aInstance, otRadioFrame *aFrame, o
txFrame.SetRadioType(Mac::kRadioTypeIeee802154);
#endif
instance.Get<Radio::Callbacks>().HandleTransmitDone(txFrame, ackFrame, aError);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (instance.Get<Radio>().GetDiagMode())
{
#if OPENTHREAD_RADIO
uint8_t channel = txFrame.mInfo.mTxInfo.mRxChannelAfterTxDone;
if (channel != aFrame->mChannel)
{
OT_ASSERT((otPlatRadioGetSupportedChannelMask(aInstance) & (1UL << channel)) != 0);
IgnoreError(otPlatRadioReceive(aInstance, channel));
}
#endif
instance.Get<Radio::Callbacks>().HandleDiagsTransmitDone(txFrame, aError);
}
else
#endif
{
instance.Get<Radio::Callbacks>().HandleTransmitDone(txFrame, ackFrame, aError);
}
exit:
return;
}
@@ -159,7 +186,6 @@ extern "C" void otPlatDiagRadioTransmitDone(otInstance *aInstance, otRadioFrame
AsCoreType(aInstance).Get<Radio::Callbacks>().HandleDiagsTransmitDone(txFrame, aError);
}
#endif
#else // #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
extern "C" void otPlatRadioReceiveDone(otInstance *, otRadioFrame *, otError) {}
@@ -172,12 +198,6 @@ extern "C" void otPlatRadioEnergyScanDone(otInstance *, int8_t) {}
extern "C" void otPlatRadioBusLatencyChanged(otInstance *) {}
#if OPENTHREAD_CONFIG_DIAG_ENABLE
extern "C" void otPlatDiagRadioReceiveDone(otInstance *, otRadioFrame *, otError) {}
extern "C" void otPlatDiagRadioTransmitDone(otInstance *, otRadioFrame *, otError) {}
#endif
#endif // // #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
//---------------------------------------------------------------------------------------------------------------------
+2 -24
View File
@@ -179,10 +179,6 @@ exit:
void RadioSpinel::SetCallbacks(const struct RadioSpinelCallbacks &aCallbacks)
{
#if OPENTHREAD_CONFIG_DIAG_ENABLE
assert(aCallbacks.mDiagReceiveDone != nullptr);
assert(aCallbacks.mDiagTransmitDone != nullptr);
#endif
assert(aCallbacks.mEnergyScanDone != nullptr);
assert(aCallbacks.mReceiveDone != nullptr);
assert(aCallbacks.mTransmitDone != nullptr);
@@ -756,32 +752,14 @@ void RadioSpinel::RadioReceive(void)
}
}
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet())
{
mCallbacks.mDiagReceiveDone(mInstance, &mRxRadioFrame, OT_ERROR_NONE);
}
else
#endif
{
mCallbacks.mReceiveDone(mInstance, &mRxRadioFrame, OT_ERROR_NONE);
}
mCallbacks.mReceiveDone(mInstance, &mRxRadioFrame, OT_ERROR_NONE);
exit:
return;
}
void RadioSpinel::TransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otError aError)
{
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet())
{
mCallbacks.mDiagTransmitDone(mInstance, aFrame, aError);
}
else
#endif
{
mCallbacks.mTransmitDone(mInstance, aFrame, aAckFrame, aError);
}
mCallbacks.mTransmitDone(mInstance, aFrame, aAckFrame, aError);
}
void RadioSpinel::ProcessRadioStateMachine(void)
-28
View File
@@ -107,34 +107,6 @@ struct RadioSpinelCallbacks
*/
void (*mSwitchoverDone)(otInstance *aInstance, bool aSuccess);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
/**
* This callback notifies diagnostics module using `RadioSpinel` of a received frame.
*
* This callback is used when diagnostics is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aFrame A pointer to the received frame or NULL if the receive operation failed.
* @param[in] aError OT_ERROR_NONE when successfully received a frame,
* OT_ERROR_ABORT when reception was aborted and a frame was not received,
* OT_ERROR_NO_BUFS when a frame could not be received due to lack of rx buffer space.
*/
void (*mDiagReceiveDone)(otInstance *aInstance, otRadioFrame *aFrame, Error aError);
/**
* This callback notifies diagnostics module using `RadioSpinel` that the transmission has completed.
*
* This callback is used when diagnostics is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aFrame A pointer to the frame that was transmitted.
* @param[in] aError OT_ERROR_NONE when the frame was transmitted,
* OT_ERROR_CHANNEL_ACCESS_FAILURE tx could not take place due to activity on the
* channel, OT_ERROR_ABORT when transmission was aborted for other reasons.
*/
void (*mDiagTransmitDone)(otInstance *aInstance, otRadioFrame *aFrame, Error aError);
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
/**
* This method saves the radio spinel metrics to the temporary storage.
*
-4
View File
@@ -92,10 +92,6 @@ void Radio::Init(const char *aUrl)
VerifyOrDie(mRadioUrl.GetPath() != nullptr, OT_EXIT_INVALID_ARGUMENTS);
memset(&callbacks, 0, sizeof(callbacks));
#if OPENTHREAD_CONFIG_DIAG_ENABLE
callbacks.mDiagReceiveDone = otPlatDiagRadioReceiveDone;
callbacks.mDiagTransmitDone = otPlatDiagRadioTransmitDone;
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
callbacks.mEnergyScanDone = otPlatRadioEnergyScanDone;
callbacks.mBusLatencyChanged = otPlatRadioBusLatencyChanged;
callbacks.mReceiveDone = otPlatRadioReceiveDone;