[radio] add radio coex control api (#4158)

This commit is contained in:
Zhanglong Xia
2019-09-16 23:12:37 -07:00
committed by Jonathan Hui
parent 87ef3b1d51
commit c0ef327664
14 changed files with 217 additions and 49 deletions
@@ -128,12 +128,12 @@
#define CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER 1
/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
*
* Define to 1 if you want to enable radio coexistence metrics implemented in platform.
* Define to 1 if you want to enable radio coexistence implemented in platform.
*
*/
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE 1
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE 1
#endif
#endif // OPENTHREAD_CORE_POSIX_CONFIG_H_
+20 -1
View File
@@ -147,6 +147,10 @@ static uint16_t sShortAddressMatchTable[POSIX_MAX_SRC_MATCH_ENTRIES];
static otExtAddress sExtAddressMatchTable[POSIX_MAX_SRC_MATCH_ENTRIES];
static bool sSrcMatchEnabled = false;
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
static bool sRadioCoexEnabled = true;
#endif
static bool findShortAddress(uint16_t aShortAddress)
{
uint8_t i;
@@ -1093,7 +1097,22 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
return POSIX_RECEIVE_SENSITIVITY;
}
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled)
{
assert(aInstance != NULL);
sRadioCoexEnabled = aEnabled;
return OT_ERROR_NONE;
}
bool otPlatRadioIsCoexEnabled(otInstance *aInstance)
{
assert(aInstance != NULL);
return sRadioCoexEnabled;
}
otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics)
{
otError error = OT_ERROR_NONE;
+28
View File
@@ -739,9 +739,37 @@ uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance);
*/
uint32_t otPlatRadioGetPreferredChannelMask(otInstance *aInstance);
/**
* Enable the radio coex.
*
* This function is used when feature OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aEnabled TRUE to enable the radio coex, FALSE otherwise.
*
* @retval OT_ERROR_NONE Successfully enabled.
* @retval OT_ERROR_FAILED The radio coex could not be enabled.
*
*/
otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled);
/**
* Check whether radio coex is enabled or not.
*
* This function is used when feature OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @returns TRUE if the radio coex is enabled, FALSE otherwise.
*
*/
bool otPlatRadioIsCoexEnabled(otInstance *aInstance);
/**
* Get the radio coexistence metrics.
*
* This function is used when feature OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE is enabled.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[out] aCoexMetrics A pointer to the coexistence metrics structure.
*
+48 -29
View File
@@ -105,7 +105,7 @@ const struct Command Interpreter::sCommands[] = {
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
{"coaps", &Interpreter::ProcessCoapSecure},
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
{"coex", &Interpreter::ProcessCoexMetrics},
#endif
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
@@ -786,43 +786,62 @@ void Interpreter::ProcessCoapSecure(int argc, char *argv[])
#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
void Interpreter::ProcessCoexMetrics(int argc, char *argv[])
{
OT_UNUSED_VARIABLE(argc);
OT_UNUSED_VARIABLE(argv);
otError error = OT_ERROR_NONE;
otRadioCoexMetrics metrics;
otError error = otPlatRadioGetCoexMetrics(mInstance, &metrics);
if (argc == 0)
{
mServer->OutputFormat("%s\r\n", otPlatRadioIsCoexEnabled(mInstance) ? "Enabled" : "Disabled");
}
else if (strcmp(argv[0], "enable") == 0)
{
error = otPlatRadioSetCoexEnabled(mInstance, true);
}
else if (strcmp(argv[0], "disable") == 0)
{
error = otPlatRadioSetCoexEnabled(mInstance, false);
}
else if (strcmp(argv[0], "metrics") == 0)
{
otRadioCoexMetrics metrics;
SuccessOrExit(error);
SuccessOrExit(error = otPlatRadioGetCoexMetrics(mInstance, &metrics));
mServer->OutputFormat("Stopped: %s\r\n", metrics.mStopped ? "true" : "false");
mServer->OutputFormat("Grant Glitch: %u\r\n", metrics.mNumGrantGlitch);
mServer->OutputFormat("Transmit metrics\r\n");
mServer->OutputFormat(" Request: %u\r\n", metrics.mNumTxRequest);
mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumTxGrantImmediate);
mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumTxGrantWait);
mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumTxGrantWaitActivated);
mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumTxGrantWaitTimeout);
mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n", metrics.mNumTxGrantDeactivatedDuringRequest);
mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumTxDelayedGrant);
mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgTxRequestToGrantTime);
mServer->OutputFormat("Receive metrics\r\n");
mServer->OutputFormat(" Request: %u\r\n", metrics.mNumRxRequest);
mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumRxGrantImmediate);
mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumRxGrantWait);
mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumRxGrantWaitActivated);
mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumRxGrantWaitTimeout);
mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n", metrics.mNumRxGrantDeactivatedDuringRequest);
mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumRxDelayedGrant);
mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgRxRequestToGrantTime);
mServer->OutputFormat(" Grant None: %u\r\n", metrics.mNumRxGrantNone);
mServer->OutputFormat("Stopped: %s\r\n", metrics.mStopped ? "true" : "false");
mServer->OutputFormat("Grant Glitch: %u\r\n", metrics.mNumGrantGlitch);
mServer->OutputFormat("Transmit metrics\r\n");
mServer->OutputFormat(" Request: %u\r\n", metrics.mNumTxRequest);
mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumTxGrantImmediate);
mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumTxGrantWait);
mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumTxGrantWaitActivated);
mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumTxGrantWaitTimeout);
mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n",
metrics.mNumTxGrantDeactivatedDuringRequest);
mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumTxDelayedGrant);
mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgTxRequestToGrantTime);
mServer->OutputFormat("Receive metrics\r\n");
mServer->OutputFormat(" Request: %u\r\n", metrics.mNumRxRequest);
mServer->OutputFormat(" Grant Immediate: %u\r\n", metrics.mNumRxGrantImmediate);
mServer->OutputFormat(" Grant Wait: %u\r\n", metrics.mNumRxGrantWait);
mServer->OutputFormat(" Grant Wait Activated: %u\r\n", metrics.mNumRxGrantWaitActivated);
mServer->OutputFormat(" Grant Wait Timeout: %u\r\n", metrics.mNumRxGrantWaitTimeout);
mServer->OutputFormat(" Grant Deactivated During Request: %u\r\n",
metrics.mNumRxGrantDeactivatedDuringRequest);
mServer->OutputFormat(" Delayed Grant: %u\r\n", metrics.mNumRxDelayedGrant);
mServer->OutputFormat(" Average Request To Grant Time: %u\r\n", metrics.mAvgRxRequestToGrantTime);
mServer->OutputFormat(" Grant None: %u\r\n", metrics.mNumRxGrantNone);
}
else
{
ExitNow(error = OT_ERROR_INVALID_ARGS);
}
exit:
AppendResult(error);
}
#endif // OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#endif // OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
#if OPENTHREAD_FTD
void Interpreter::ProcessContextIdReuseDelay(int argc, char *argv[])
+1 -1
View File
@@ -208,7 +208,7 @@ private:
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
void ProcessCoapSecure(int argc, char *argv[]);
#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
void ProcessCoexMetrics(int argc, char *argv[]);
#endif
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
@@ -436,4 +436,9 @@
"OPENTHREAD_CONFIG_INFORM_PREVIOUS_PARENT_ON_REATTACH was replaced by OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH."
#endif
#ifdef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#error \
"OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE was replaced by OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE."
#endif
#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_
+4 -4
View File
@@ -98,13 +98,13 @@
#endif
/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
*
* Define to 1 if you want to enable radio coexistence metrics implemented in platform.
* Define to 1 if you want to enable radio coexistence implemented in platform.
*
*/
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE 0
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE 0
#endif
#endif // CONFIG_PLATFORM_H_
+23 -2
View File
@@ -1801,6 +1801,10 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_CAPS>(void)
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_SLAAC));
#endif
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_RADIO_COEX));
#endif
#if OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE
SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_PEEK_POKE));
#endif
@@ -2193,7 +2197,24 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_CHAN_PREFERRED>(v
return EncodeChannelMask(otPlatRadioGetPreferredChannelMask(mInstance));
}
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_RADIO_COEX_ENABLE>(void)
{
bool enabled;
otError error = OT_ERROR_NONE;
SuccessOrExit(error = mDecoder.ReadBool(enabled));
error = otPlatRadioSetCoexEnabled(mInstance, enabled);
exit:
return error;
}
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_RADIO_COEX_ENABLE>(void)
{
return mEncoder.WriteBool(otPlatRadioIsCoexEnabled(mInstance));
}
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_RADIO_COEX_METRICS>(void)
{
otRadioCoexMetrics coexMetrics;
@@ -2201,7 +2222,7 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_RADIO_COEX_METRICS>(v
if (error != OT_ERROR_NONE)
{
error = mEncoder.OverwriteWithLastStatusError(SPINEL_STATUS_INVALID_COMMAND_FOR_PROP);
error = mEncoder.OverwriteWithLastStatusError(ThreadErrorToSpinelStatus(error));
ExitNow();
}
+9 -1
View File
@@ -140,10 +140,13 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
case SPINEL_PROP_PHY_CHAN_PREFERRED:
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_PHY_CHAN_PREFERRED>;
break;
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
case SPINEL_PROP_RADIO_COEX_METRICS:
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_RADIO_COEX_METRICS>;
break;
case SPINEL_PROP_RADIO_COEX_ENABLE:
handler = &NcpBase::HandlePropertyGet<SPINEL_PROP_RADIO_COEX_ENABLE>;
break;
#endif
// --------------------------------------------------------------------------
@@ -717,6 +720,11 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey)
case SPINEL_PROP_MAC_SCAN_PERIOD:
handler = &NcpBase::HandlePropertySet<SPINEL_PROP_MAC_SCAN_PERIOD>;
break;
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
case SPINEL_PROP_RADIO_COEX_ENABLE:
handler = &NcpBase::HandlePropertySet<SPINEL_PROP_RADIO_COEX_ENABLE>;
break;
#endif
// --------------------------------------------------------------------------
// MTD (or FTD) Properties (Set Handler)
+8
View File
@@ -1411,6 +1411,10 @@ const char *spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
ret = "RADIO_COEX_METRICS";
break;
case SPINEL_PROP_RADIO_COEX_ENABLE:
ret = "RADIO_COEX_ENABLE";
break;
case SPINEL_PROP_MAC_SCAN_STATE:
ret = "MAC_SCAN_STATE";
break;
@@ -2576,6 +2580,10 @@ const char *spinel_capability_to_cstr(unsigned int capability)
ret = "SLAAC";
break;
case SPINEL_CAP_RADIO_COEX:
ret = "RADIO_COEX";
break;
case SPINEL_CAP_ERROR_RATE_TRACKING:
ret = "ERROR_RATE_TRACKING";
break;
+12
View File
@@ -1054,6 +1054,7 @@ enum
SPINEL_CAP_CHILD_SUPERVISION = (SPINEL_CAP_OPENTHREAD__BEGIN + 8),
SPINEL_CAP_POSIX_APP = (SPINEL_CAP_OPENTHREAD__BEGIN + 9),
SPINEL_CAP_SLAAC = (SPINEL_CAP_OPENTHREAD__BEGIN + 10),
SPINEL_CAP_RADIO_COEX = (SPINEL_CAP_OPENTHREAD__BEGIN + 11),
SPINEL_CAP_OPENTHREAD__END = 640,
SPINEL_CAP_THREAD__BEGIN = 1024,
@@ -1629,6 +1630,8 @@ typedef enum
/// All coex metrics related counters.
/** Format: t(LLLLLLLL)t(LLLLLLLLL)bL (Read-only)
*
* Required capability: SPINEL_CAP_RADIO_COEX
*
* The contents include two structures and two common variables, first structure corresponds to
* all transmit related coex counters, second structure provides the receive related counters.
@@ -1664,6 +1667,15 @@ typedef enum
*/
SPINEL_PROP_RADIO_COEX_METRICS = SPINEL_PROP_PHY_EXT__BEGIN + 12,
/// Radio Coex Enable
/** Format: `b`
*
* Required capability: SPINEL_CAP_RADIO_COEX
*
* Indicates if radio coex is enabled or disabled. Set to true to enable radio coex.
*/
SPINEL_PROP_RADIO_COEX_ENABLE = SPINEL_PROP_PHY_EXT__BEGIN + 13,
SPINEL_PROP_PHY_EXT__END = 0x1300,
SPINEL_PROP_MAC__BEGIN = 0x30,
@@ -63,12 +63,12 @@
#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1
/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
*
* Define to 1 if you want to enable radio coexistence metrics implemented in platform.
* Define to 1 if you want to enable radio coexistence implemented in platform.
*
*/
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE 1
#ifndef OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE 1
#endif
#endif // OPENTHREAD_CORE_POSIX_CONFIG_H_
+28 -2
View File
@@ -892,7 +892,21 @@ int8_t RadioSpinel::GetRssi(void)
return rssi;
}
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
otError RadioSpinel::SetCoexEnabled(bool aEnabled)
{
return Set(SPINEL_PROP_RADIO_COEX_ENABLE, SPINEL_DATATYPE_BOOL_S, aEnabled);
}
bool RadioSpinel::IsCoexEnabled(void)
{
bool enabled;
otError error = Get(SPINEL_PROP_RADIO_COEX_ENABLE, SPINEL_DATATYPE_BOOL_S, &enabled);
LogIfFail("Get Coex State failed", error);
return enabled;
}
otError RadioSpinel::GetCoexMetrics(otRadioCoexMetrics &aCoexMetrics)
{
otError error;
@@ -1670,7 +1684,19 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
return sRadioSpinel.GetReceiveSensitivity();
}
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled)
{
OT_UNUSED_VARIABLE(aInstance);
return sRadioSpinel.SetCoexEnabled(aEnabled);
}
bool otPlatRadioIsCoexEnabled(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
return sRadioSpinel.IsCoexEnabled();
}
otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics)
{
OT_UNUSED_VARIABLE(aInstance);
+23 -1
View File
@@ -197,7 +197,29 @@ public:
*/
int8_t GetReceiveSensitivity(void) const { return mRxSensitivity; }
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_METRICS_ENABLE
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
/**
* Enable the radio coex.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aEnabled TRUE to enable the radio coex, FALSE otherwise.
*
* @retval OT_ERROR_NONE Successfully enabled.
* @retval OT_ERROR_FAILED The radio coex could not be enabled.
*
*/
otError SetCoexEnabled(bool aEnabled);
/**
* Check whether radio coex is enabled or not.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @returns TRUE if the radio coex is enabled, FALSE otherwise.
*
*/
bool IsCoexEnabled(void);
/**
* This method retrieves the radio coexistence metrics.
*