[low-power] add RCP support for CSL (#5456)

This commit is contained in:
Jintao Lin
2020-09-14 21:20:14 -07:00
committed by GitHub
parent 31c7208ac8
commit 8c90ade062
23 changed files with 323 additions and 35 deletions
+26
View File
@@ -98,3 +98,29 @@ jobs:
- name: Codecov - name: Codecov
run: | run: |
bash <(curl -s https://codecov.io/bash) -x "${{ matrix.compiler.gcov }}" -Z bash <(curl -s https://codecov.io/bash) -x "${{ matrix.compiler.gcov }}" -Z
expects:
runs-on: ubuntu-18.04
env:
COVERAGE: 1
THREAD_VERSION: 1.2
VIRTUAL_TIME: 0
steps:
- uses: actions/checkout@v2
- name: Bootstrap
run: |
sudo apt-get --no-install-recommends install -y expect ninja-build
- name: Run RCP Mode
run: |
OT_OPTIONS=-DOT_READLINE=OFF NODE_MODE=rcp ./script/test build expect
- name: Keep-1-2-only
run: |
./script/test tar posix 1.2-bbr
./script/test tar simulation 1.2-bbr
- name: Keep POSIX Only
run: |
./script/test tar simulation 1.2
- name: Codecov
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
@@ -150,6 +150,16 @@
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif
/** /**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
* *
@@ -172,6 +172,16 @@
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif
/** /**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
* *
@@ -172,6 +172,16 @@
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif
/** /**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
* *
@@ -117,6 +117,16 @@
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE #ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
#endif
#endif // OPENTHREAD_RADIO #endif // OPENTHREAD_RADIO
/** /**
+12
View File
@@ -125,6 +125,7 @@ enum
OT_RADIO_CAPS_CSMA_BACKOFF = 1 << 3, ///< Radio supports CSMA backoff for frame transmission (but no retry). OT_RADIO_CAPS_CSMA_BACKOFF = 1 << 3, ///< Radio supports CSMA backoff for frame transmission (but no retry).
OT_RADIO_CAPS_SLEEP_TO_TX = 1 << 4, ///< Radio supports direct transition from sleep to TX with CSMA. OT_RADIO_CAPS_SLEEP_TO_TX = 1 << 4, ///< Radio supports direct transition from sleep to TX with CSMA.
OT_RADIO_CAPS_TRANSMIT_SEC = 1 << 5, ///< Radio supports tx security. OT_RADIO_CAPS_TRANSMIT_SEC = 1 << 5, ///< Radio supports tx security.
OT_RADIO_CAPS_TRANSMIT_TIMING = 1 << 6, ///< Radio supports tx at specific time.
}; };
#define OT_PANID_BROADCAST 0xffff ///< IEEE 802.15.4 Broadcast PAN ID #define OT_PANID_BROADCAST 0xffff ///< IEEE 802.15.4 Broadcast PAN ID
@@ -516,6 +517,17 @@ void otPlatRadioSetMacFrameCounter(otInstance *aInstance, uint32_t aMacFrameCoun
*/ */
uint64_t otPlatRadioGetNow(otInstance *aInstance); uint64_t otPlatRadioGetNow(otInstance *aInstance);
/**
* Get the bus speed in bits/second between the host and the radio chip.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The bus speed in bits/second between the host and the radio chip.
* Return 0 when the MAC and above layer and Radio layer resides on the same chip.
*
*/
uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance);
/** /**
* @} * @}
* *
+7 -3
View File
@@ -233,12 +233,16 @@ do_expect()
{ {
local ot_command local ot_command
local rcp_command= local rcp_command=
local mtd_command=
local test_patterns local test_patterns
if [[ ${NODE_MODE} == rcp ]]; then if [[ ${NODE_MODE} == rcp ]]; then
ot_command="${OT_CLI_PATH}" ot_command="${OT_CLI_PATH}"
rcp_command="${RADIO_DEVICE}" rcp_command="${RADIO_DEVICE}"
if [[ ${OT_NATIVE_IP} == 1 ]]; then if [[ ${THREAD_VERSION} == "1.2" ]]; then
mtd_command="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}/examples/apps/cli/ot-cli-mtd"
test_patterns=(-name 'v1_2-*.exp')
elif [[ ${OT_NATIVE_IP} == 1 ]]; then
test_patterns=(-name 'tun-*.exp') test_patterns=(-name 'tun-*.exp')
else else
test_patterns=(-name 'posix-*.exp' -o -name 'cli-*.exp') test_patterns=(-name 'posix-*.exp' -o -name 'cli-*.exp')
@@ -254,9 +258,9 @@ do_expect()
mkdir tmp mkdir tmp
{ {
if [[ ${OT_NATIVE_IP} == 1 ]]; then if [[ ${OT_NATIVE_IP} == 1 ]]; then
OT_COMMAND="${ot_command}" RCP_COMMAND="${rcp_command}" sudo -E expect -df "${script}" 2>"${log_file}" OT_COMMAND="${ot_command}" RCP_COMMAND="${rcp_command}" MTD_COMMAND="${mtd_command}" sudo -E expect -df "${script}" 2>"${log_file}"
else else
OT_COMMAND="${ot_command}" RCP_COMMAND="${rcp_command}" expect -df "${script}" 2>"${log_file}" OT_COMMAND="${ot_command}" RCP_COMMAND="${rcp_command}" MTD_COMMAND="${mtd_command}" expect -df "${script}" 2>"${log_file}"
fi fi
} || { } || {
local exit_code=$? local exit_code=$?
+21 -1
View File
@@ -139,6 +139,16 @@
#define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 4 #define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 4
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US
*
* Define how many microseconds ahead should MAC deliver CSL frame to SubMac.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US
#define OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US 2000
#endif
/** /**
* @def OPENTHREAD_CONFIG_MAC_FILTER_ENABLE * @def OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
* *
@@ -295,6 +305,16 @@
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 0 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 0
#endif #endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE 0
#endif
/** /**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE
* *
@@ -312,7 +332,7 @@
* *
*/ */
#define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE \ #define OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE \
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) && OPENTHREAD_FTD (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) && (OPENTHREAD_FTD || OPENTHREAD_RADIO)
/** /**
* @def OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE * @def OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
@@ -506,8 +506,8 @@
#if (OPENTHREAD_CONFIG_THREAD_VERSION < OT_THREAD_VERSION_1_2) #if (OPENTHREAD_CONFIG_THREAD_VERSION < OT_THREAD_VERSION_1_2)
#error "Thread 1.2 or higher version is required for OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE" #error "Thread 1.2 or higher version is required for OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE"
#endif #endif
#if (!OPENTHREAD_FTD) #if (!OPENTHREAD_FTD && !OPENTHREAD_RADIO)
#error "FTD is required for OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE" #error "FTD or RADIO is required for OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE"
#endif #endif
#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE #endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
+40 -10
View File
@@ -105,9 +105,13 @@ otRadioCaps SubMac::GetCaps(void) const
caps |= OT_RADIO_CAPS_TRANSMIT_SEC; caps |= OT_RADIO_CAPS_TRANSMIT_SEC;
#endif #endif
#if OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
caps |= OT_RADIO_CAPS_TRANSMIT_TIMING;
#endif
#else #else
caps = OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF | OT_RADIO_CAPS_TRANSMIT_RETRIES | caps = OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_CSMA_BACKOFF | OT_RADIO_CAPS_TRANSMIT_RETRIES |
OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_TRANSMIT_SEC; OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_TRANSMIT_SEC | OT_RADIO_CAPS_TRANSMIT_TIMING;
#endif #endif
return caps; return caps;
@@ -341,18 +345,26 @@ void SubMac::StartCsmaBackoff(void)
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE #if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
if (mTransmitFrame.mInfo.mTxInfo.mPeriod != 0) if (mTransmitFrame.mInfo.mTxInfo.mPeriod != 0)
{ {
uint32_t phaseNow = (otPlatTimeGet() / kUsPerTenSymbols) % mTransmitFrame.mInfo.mTxInfo.mPeriod;
uint32_t phaseDesired = mTransmitFrame.mInfo.mTxInfo.mPhase;
SetState(kStateCslTransmit); SetState(kStateCslTransmit);
if (phaseNow < phaseDesired) if (ShouldHandleTransmitTargetTime())
{ {
mTimer.Start((phaseDesired - phaseNow) * kUsPerTenSymbols); uint32_t phaseNow =
} (otPlatRadioGetNow(&GetInstance()) / kUsPerTenSymbols) % mTransmitFrame.mInfo.mTxInfo.mPeriod;
else if (phaseNow > phaseDesired) uint32_t phaseDesired = mTransmitFrame.mInfo.mTxInfo.mPhase;
{
mTimer.Start((phaseDesired + mTransmitFrame.mInfo.mTxInfo.mPeriod - phaseNow) * kUsPerTenSymbols); if (phaseNow < phaseDesired)
{
mTimer.Start((phaseDesired - phaseNow) * kUsPerTenSymbols);
}
else if (phaseNow > phaseDesired)
{
mTimer.Start((phaseDesired + mTransmitFrame.mInfo.mTxInfo.mPeriod - phaseNow) * kUsPerTenSymbols);
}
else
{
BeginTransmit();
}
} }
else else
{ {
@@ -759,6 +771,24 @@ exit:
return swEnergyScan; return swEnergyScan;
} }
bool SubMac::ShouldHandleTransmitTargetTime(void) const
{
bool swTxDelay = true;
VerifyOrExit(!RadioSupportsTransmitTiming(), swTxDelay = false);
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE
VerifyOrExit(Get<LinkRaw>().IsEnabled(), OT_NOOP);
#endif
#if OPENTHREAD_CONFIG_LINK_RAW_ENABLE || OPENTHREAD_RADIO
swTxDelay = OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE;
#endif
exit:
return swTxDelay;
}
void SubMac::SetState(State aState) void SubMac::SetState(State aState)
{ {
if (mState != aState) if (mState != aState)
+2
View File
@@ -549,12 +549,14 @@ private:
bool RadioSupportsRetries(void) const { return ((mRadioCaps & OT_RADIO_CAPS_TRANSMIT_RETRIES) != 0); } bool RadioSupportsRetries(void) const { return ((mRadioCaps & OT_RADIO_CAPS_TRANSMIT_RETRIES) != 0); }
bool RadioSupportsAckTimeout(void) const { return ((mRadioCaps & OT_RADIO_CAPS_ACK_TIMEOUT) != 0); } bool RadioSupportsAckTimeout(void) const { return ((mRadioCaps & OT_RADIO_CAPS_ACK_TIMEOUT) != 0); }
bool RadioSupportsEnergyScan(void) const { return ((mRadioCaps & OT_RADIO_CAPS_ENERGY_SCAN) != 0); } bool RadioSupportsEnergyScan(void) const { return ((mRadioCaps & OT_RADIO_CAPS_ENERGY_SCAN) != 0); }
bool RadioSupportsTransmitTiming(void) const { return ((mRadioCaps & OT_RADIO_CAPS_TRANSMIT_TIMING) != 0); }
bool ShouldHandleTransmitSecurity(void) const; bool ShouldHandleTransmitSecurity(void) const;
bool ShouldHandleCsmaBackOff(void) const; bool ShouldHandleCsmaBackOff(void) const;
bool ShouldHandleAckTimeout(void) const; bool ShouldHandleAckTimeout(void) const;
bool ShouldHandleRetries(void) const; bool ShouldHandleRetries(void) const;
bool ShouldHandleEnergyScan(void) const; bool ShouldHandleEnergyScan(void) const;
bool ShouldHandleTransmitTargetTime(void) const;
void ProcessTransmitSecurity(void); void ProcessTransmitSecurity(void);
void UpdateFrameCounter(uint32_t aFrameCounter); void UpdateFrameCounter(uint32_t aFrameCounter);
+7
View File
@@ -158,3 +158,10 @@ OT_TOOL_WEAK uint64_t otPlatRadioGetNow(otInstance *aInstance)
return UINT64_MAX; return UINT64_MAX;
} }
OT_TOOL_WEAK uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
return 0;
}
+15 -4
View File
@@ -66,6 +66,18 @@ CslTxScheduler::CslTxScheduler(Instance &aInstance)
, mFrameContext() , mFrameContext()
, mCallbacks(aInstance) , mCallbacks(aInstance)
{ {
InitFrameRequestAhead();
}
void CslTxScheduler::InitFrameRequestAhead(void)
{
uint32_t busSpeedHz = otPlatRadioGetBusSpeed(&GetInstance());
// longest frame on bus is 127 bytes with some metadata, use 150 bytes for bus Tx time estimation
uint32_t busTxTimeUs = ((busSpeedHz == 0) ? 0 : (150 * 8 * 1000000 + busSpeedHz - 1) / busSpeedHz);
// Use ceiling to get next closest integer
mCslFrameRequestAhead =
(OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs + kUsPerTenSymbols - 1) / kUsPerTenSymbols;
} }
void CslTxScheduler::Update(void) void CslTxScheduler::Update(void)
@@ -144,15 +156,14 @@ uint32_t CslTxScheduler::GetNextCslTransmissionDelay(const Child &aChild, uint64
uint32_t delay; uint32_t delay;
uint16_t period_offset = (aRadioNow / kUsPerTenSymbols) % aChild.GetCslPeriod(); uint16_t period_offset = (aRadioNow / kUsPerTenSymbols) % aChild.GetCslPeriod();
if (aChild.GetCslPhase() > period_offset + kCslFrameRequestAheadThreshold) if (aChild.GetCslPhase() > period_offset + mCslFrameRequestAhead)
{ {
delay = static_cast<uint16_t>(aChild.GetCslPhase() - period_offset - kCslFrameRequestAheadThreshold) * delay = static_cast<uint16_t>(aChild.GetCslPhase() - period_offset - mCslFrameRequestAhead) * kUsPerTenSymbols;
kUsPerTenSymbols;
} }
else else
{ {
delay = static_cast<uint16_t>(aChild.GetCslPeriod() + aChild.GetCslPhase() - period_offset - delay = static_cast<uint16_t>(aChild.GetCslPeriod() + aChild.GetCslPhase() - period_offset -
kCslFrameRequestAheadThreshold) * mCslFrameRequestAhead) *
kUsPerTenSymbols; kUsPerTenSymbols;
} }
+3 -2
View File
@@ -65,8 +65,7 @@ class CslTxScheduler : public InstanceLocator
public: public:
enum enum
{ {
kMaxCslTriggeredTxAttempts = OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS, kMaxCslTriggeredTxAttempts = OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS,
kCslFrameRequestAheadThreshold = 2000 / kUsPerTenSymbols,
}; };
/** /**
@@ -187,6 +186,7 @@ public:
void Clear(void); void Clear(void);
private: private:
void InitFrameRequestAhead(void);
void RescheduleCslTx(void); void RescheduleCslTx(void);
uint32_t GetNextCslTransmissionDelay(const Child &aChild, uint64_t aRadioNow); uint32_t GetNextCslTransmissionDelay(const Child &aChild, uint64_t aRadioNow);
@@ -197,6 +197,7 @@ private:
void HandleSentFrame(const Mac::TxFrame &aFrame, otError aError, Child &aChild); void HandleSentFrame(const Mac::TxFrame &aFrame, otError aError, Child &aChild);
uint32_t mCslFrameRequestAhead;
Child * mCslTxChild; Child * mCslTxChild;
Message * mCslTxMessage; Message * mCslTxMessage;
Callbacks::FrameContext mFrameContext; Callbacks::FrameContext mFrameContext;
+8
View File
@@ -669,6 +669,14 @@ public:
*/ */
uint64_t GetNow(void); uint64_t GetNow(void);
/**
* This method returns the bus speed between the host and the radio.
*
* @returns bus speed in bits/second.
*
*/
uint32_t GetBusSpeed(void) const;
private: private:
enum enum
{ {
+28 -12
View File
@@ -304,6 +304,9 @@ template <typename InterfaceType, typename ProcessContextType>
otError RadioSpinel<InterfaceType, ProcessContextType>::CheckRadioCapabilities(void) otError RadioSpinel<InterfaceType, ProcessContextType>::CheckRadioCapabilities(void)
{ {
const otRadioCaps kRequiredRadioCaps = const otRadioCaps kRequiredRadioCaps =
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
OT_RADIO_CAPS_TRANSMIT_SEC | OT_RADIO_CAPS_TRANSMIT_TIMING |
#endif
OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF; OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF;
otError error = OT_ERROR_NONE; otError error = OT_ERROR_NONE;
@@ -317,10 +320,14 @@ otError RadioSpinel<InterfaceType, ProcessContextType>::CheckRadioCapabilities(v
if ((mRadioCaps & kRequiredRadioCaps) != kRequiredRadioCaps) if ((mRadioCaps & kRequiredRadioCaps) != kRequiredRadioCaps)
{ {
otLogCritPlat("RCP does not support required capabilities: ack-timeout:%s, tx-retries:%s, CSMA-backoff:%s", otRadioCaps missingCaps = (mRadioCaps & kRequiredRadioCaps) ^ kRequiredRadioCaps;
(mRadioCaps & OT_RADIO_CAPS_ACK_TIMEOUT) ? "yes" : "no",
(mRadioCaps & OT_RADIO_CAPS_TRANSMIT_RETRIES) ? "yes" : "no", otLogCritPlat("RCP is missing required capabilities: %s%s%s%s%s",
(mRadioCaps & OT_RADIO_CAPS_CSMA_BACKOFF) ? "yes" : "no"); (missingCaps & OT_RADIO_CAPS_ACK_TIMEOUT) ? "ack-timeout " : "",
(missingCaps & OT_RADIO_CAPS_TRANSMIT_RETRIES) ? "tx-retries " : "",
(missingCaps & OT_RADIO_CAPS_CSMA_BACKOFF) ? "CSMA-backoff " : "",
(missingCaps & OT_RADIO_CAPS_TRANSMIT_SEC) ? "tx-security " : "",
(missingCaps & OT_RADIO_CAPS_TRANSMIT_TIMING) ? "tx-timing " : "");
DieNow(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE); DieNow(OT_EXIT_RADIO_SPINEL_INCOMPATIBLE);
} }
@@ -1555,17 +1562,20 @@ otError RadioSpinel<InterfaceType, ProcessContextType>::Transmit(otRadioFrame &a
otPlatRadioTxStarted(mInstance, mTransmitFrame); otPlatRadioTxStarted(mInstance, mTransmitFrame);
error = Request(true, SPINEL_CMD_PROP_VALUE_SET, SPINEL_PROP_STREAM_RAW, error = Request(true, SPINEL_CMD_PROP_VALUE_SET, SPINEL_PROP_STREAM_RAW,
SPINEL_DATATYPE_DATA_WLEN_S // Frame data SPINEL_DATATYPE_DATA_WLEN_S // Frame data
SPINEL_DATATYPE_UINT8_S // Channel SPINEL_DATATYPE_UINT8_S // Channel
SPINEL_DATATYPE_UINT8_S // MaxCsmaBackoffs SPINEL_DATATYPE_UINT8_S // MaxCsmaBackoffs
SPINEL_DATATYPE_UINT8_S // MaxFrameRetries SPINEL_DATATYPE_UINT8_S // MaxFrameRetries
SPINEL_DATATYPE_BOOL_S // CsmaCaEnabled SPINEL_DATATYPE_BOOL_S // CsmaCaEnabled
SPINEL_DATATYPE_BOOL_S // IsARetx SPINEL_DATATYPE_BOOL_S // IsARetx
SPINEL_DATATYPE_BOOL_S, // SkipAes SPINEL_DATATYPE_BOOL_S // SkipAes
SPINEL_DATATYPE_UINT16_S // Period
SPINEL_DATATYPE_UINT16_S, // Phase
mTransmitFrame->mPsdu, mTransmitFrame->mLength, mTransmitFrame->mChannel, mTransmitFrame->mPsdu, mTransmitFrame->mLength, mTransmitFrame->mChannel,
mTransmitFrame->mInfo.mTxInfo.mMaxCsmaBackoffs, mTransmitFrame->mInfo.mTxInfo.mMaxFrameRetries, mTransmitFrame->mInfo.mTxInfo.mMaxCsmaBackoffs, mTransmitFrame->mInfo.mTxInfo.mMaxFrameRetries,
mTransmitFrame->mInfo.mTxInfo.mCsmaCaEnabled, mTransmitFrame->mInfo.mTxInfo.mIsARetx, mTransmitFrame->mInfo.mTxInfo.mCsmaCaEnabled, mTransmitFrame->mInfo.mTxInfo.mIsARetx,
mTransmitFrame->mInfo.mTxInfo.mIsSecurityProcessed); mTransmitFrame->mInfo.mTxInfo.mIsSecurityProcessed, mTransmitFrame->mInfo.mTxInfo.mPeriod,
mTransmitFrame->mInfo.mTxInfo.mPhase);
if (error == OT_ERROR_NONE) if (error == OT_ERROR_NONE)
{ {
@@ -1806,5 +1816,11 @@ uint64_t RadioSpinel<InterfaceType, ProcessContextType>::GetNow(void)
return mIsTimeSynced ? (otPlatTimeGet() + static_cast<uint64_t>(mRadioTimeOffset)) : UINT64_MAX; return mIsTimeSynced ? (otPlatTimeGet() + static_cast<uint64_t>(mRadioTimeOffset)) : UINT64_MAX;
} }
template <typename InterfaceType, typename ProcessContextType>
uint32_t RadioSpinel<InterfaceType, ProcessContextType>::GetBusSpeed(void) const
{
return mSpinelInterface.GetBusSpeed();
}
} // namespace Spinel } // namespace Spinel
} // namespace ot } // namespace ot
+4
View File
@@ -398,6 +398,8 @@ otError NcpBase::DecodeStreamRawTxRequest(otRadioFrame &aFrame)
aFrame.mInfo.mTxInfo.mCsmaCaEnabled = true; aFrame.mInfo.mTxInfo.mCsmaCaEnabled = true;
aFrame.mInfo.mTxInfo.mIsARetx = false; aFrame.mInfo.mTxInfo.mIsARetx = false;
aFrame.mInfo.mTxInfo.mIsSecurityProcessed = false; aFrame.mInfo.mTxInfo.mIsSecurityProcessed = false;
aFrame.mInfo.mTxInfo.mPeriod = 0;
aFrame.mInfo.mTxInfo.mPhase = 0;
// All the next parameters are optional. Note that even if the // All the next parameters are optional. Note that even if the
// decoder fails to parse any of optional parameters we still want to // decoder fails to parse any of optional parameters we still want to
@@ -409,6 +411,8 @@ otError NcpBase::DecodeStreamRawTxRequest(otRadioFrame &aFrame)
SuccessOrExit(mDecoder.ReadBool(csmaEnable)); SuccessOrExit(mDecoder.ReadBool(csmaEnable));
SuccessOrExit(mDecoder.ReadBool(isARetx)); SuccessOrExit(mDecoder.ReadBool(isARetx));
SuccessOrExit(mDecoder.ReadBool(isSecurityProcessed)); SuccessOrExit(mDecoder.ReadBool(isSecurityProcessed));
SuccessOrExit(mDecoder.ReadUint16(aFrame.mInfo.mTxInfo.mPeriod));
SuccessOrExit(mDecoder.ReadUint16(aFrame.mInfo.mTxInfo.mPhase));
aFrame.mInfo.mTxInfo.mCsmaCaEnabled = csmaEnable; aFrame.mInfo.mTxInfo.mCsmaCaEnabled = csmaEnable;
aFrame.mInfo.mTxInfo.mIsARetx = isARetx; aFrame.mInfo.mTxInfo.mIsARetx = isARetx;
aFrame.mInfo.mTxInfo.mIsSecurityProcessed = isSecurityProcessed; aFrame.mInfo.mTxInfo.mIsSecurityProcessed = isSecurityProcessed;
+3
View File
@@ -134,6 +134,7 @@ HdlcInterface::HdlcInterface(SpinelInterface::ReceiveFrameCallback aCallback,
, mReceiveFrameContext(aCallbackContext) , mReceiveFrameContext(aCallbackContext)
, mReceiveFrameBuffer(aFrameBuffer) , mReceiveFrameBuffer(aFrameBuffer)
, mSockFd(-1) , mSockFd(-1)
, mBaudRate(0)
, mHdlcDecoder(aFrameBuffer, HandleHdlcFrame, this) , mHdlcDecoder(aFrameBuffer, HandleHdlcFrame, this)
{ {
} }
@@ -563,6 +564,8 @@ int HdlcInterface::OpenFile(const RadioUrl &aRadioUrl)
break; break;
} }
mBaudRate = baudrate;
if (aRadioUrl.GetValue("uart-flow-control") != nullptr) if (aRadioUrl.GetValue("uart-flow-control") != nullptr)
{ {
tios.c_cflag |= CRTSCTS; tios.c_cflag |= CRTSCTS;
+10 -1
View File
@@ -148,6 +148,14 @@ public:
void Process(const VirtualTimeEvent &aEvent) { Decode(aEvent.mData, aEvent.mDataLength); } void Process(const VirtualTimeEvent &aEvent) { Decode(aEvent.mData, aEvent.mDataLength); }
#endif #endif
/**
* This method returns the bus speed between the host and the radio.
*
* @returns Bus speed in bits/second.
*
*/
uint32_t GetBusSpeed(void) const { return mBaudRate; }
private: private:
/** /**
* This method instructs `HdlcInterface` to read and decode data from radio over the socket. * This method instructs `HdlcInterface` to read and decode data from radio over the socket.
@@ -198,7 +206,7 @@ private:
static void HandleHdlcFrame(void *aContext, otError aError); static void HandleHdlcFrame(void *aContext, otError aError);
void HandleHdlcFrame(otError aError); void HandleHdlcFrame(otError aError);
static int OpenFile(const RadioUrl &aRadioUrl); int OpenFile(const RadioUrl &aRadioUrl);
#if OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE #if OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
static int ForkPty(const char *aCommand, const char *aRadioUrl); static int ForkPty(const char *aCommand, const char *aRadioUrl);
#endif #endif
@@ -214,6 +222,7 @@ private:
Spinel::SpinelInterface::RxFrameBuffer & mReceiveFrameBuffer; Spinel::SpinelInterface::RxFrameBuffer & mReceiveFrameBuffer;
int mSockFd; int mSockFd;
uint32_t mBaudRate;
Hdlc::Decoder mHdlcDecoder; Hdlc::Decoder mHdlcDecoder;
// Non-copyable, intentionally not implemented. // Non-copyable, intentionally not implemented.
+6
View File
@@ -508,3 +508,9 @@ uint64_t otPlatRadioGetNow(otInstance *aInstance)
OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aInstance);
return sRadioSpinel.GetNow(); return sRadioSpinel.GetNow();
} }
uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
return sRadioSpinel.GetBusSpeed();
}
+8
View File
@@ -138,6 +138,14 @@ public:
*/ */
void Process(const RadioProcessContext &aContext); void Process(const RadioProcessContext &aContext);
/**
* This method returns the bus speed between the host and the radio.
*
* @returns Bus speed in bits/second.
*
*/
uint32_t GetBusSpeed(void) const { return ((mSpiDevFd >= 0) ? mSpiSpeedHz : 0); }
private: private:
int SetupGpioHandle(int aFd, uint8_t aLine, uint32_t aHandleFlags, const char *aLabel); int SetupGpioHandle(int aFd, uint8_t aLine, uint32_t aHandleFlags, const char *aLabel);
int SetupGpioEvent(int aFd, uint8_t aLine, uint32_t aHandleFlags, uint32_t aEventFlags, const char *aLabel); int SetupGpioEvent(int aFd, uint8_t aLine, uint32_t aHandleFlags, uint32_t aEventFlags, const char *aLabel);
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/expect -f
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
source "tests/scripts/expect/_common.exp"
set node_1 [spawn_node 1]
set spawn_id $node_1
send "panid 0xface\n"
expect "Done"
send "ifconfig up\n"
expect "Done"
send "thread start\n"
expect "Done"
wait_for "state" "leader"
expect "Done"
send "ipaddr\n"
expect -re {(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4})}
set addr $expect_out(1,string)
expect "Done"
spawn $env(MTD_COMMAND) "2"
set node_2 $spawn_id
expect_after {
timeout { exit 1 }
}
send "panid 0xface\n"
expect "Done"
send "mode s\n"
expect "Done"
send "csl period 5000\n"
expect "Done"
send "ifconfig up\n"
expect "Done"
send "thread start\n"
expect "Done"
wait_for "state" "child"
expect "Done"
send "ping $addr\n"
expect "16 bytes from $addr: icmp_seq=1"
dispose
set spawn_id $node_1
dispose
@@ -462,4 +462,12 @@
* *
*/ */
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 1 #define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 1
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
*
* Define to 1 to enable software transmission target time logic.
*
*/
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE 1
#endif // OPENTHREAD_RADIO #endif // OPENTHREAD_RADIO