Add option for Radio layer to support retries and CSMA backoff logic. (#896)

* Add option for Radio layer to support tries and CSMA backoff logic.
This commit is contained in:
Nick Banks
2016-10-27 19:39:04 -07:00
committed by Jonathan Hui
parent c10aea1e18
commit 7edada12e4
4 changed files with 41 additions and 13 deletions
+2
View File
@@ -131,6 +131,8 @@ otLwfRadioInit(
pFilter->otRadioCapabilities = kRadioCapsEnergyScan;
if ((pFilter->MiniportCapabilities.RadioCapabilities & OT_RADIO_CAP_ACK_TIMEOUT) != 0)
pFilter->otRadioCapabilities |= kRadioCapsAckTimeout;
if ((pFilter->MiniportCapabilities.RadioCapabilities & OT_RADIO_CAP_MAC_RETRY_AND_COLLISION_AVOIDANCE) != 0)
pFilter->otRadioCapabilities |= kRadioCapsTransmitRetries;
pFilter->otPhyState = kStateDisabled;
pFilter->otCurrentListenChannel = 0xFF;
+4 -3
View File
@@ -87,9 +87,10 @@ enum
typedef enum otRadioCaps
{
kRadioCapsNone = 0, ///< None
kRadioCapsAckTimeout = 1, ///< Radio supports AckTime event
kRadioCapsEnergyScan = 2, ///< Radio supports Enegery Scans
kRadioCapsNone = 0, ///< None
kRadioCapsAckTimeout = 1, ///< Radio supports AckTime event
kRadioCapsEnergyScan = 2, ///< Radio supports Enegery Scans
kRadioCapsTransmitRetries = 4, ///< Radio supports transmission retry logic with collission avoidance
} otRadioCaps;
/**
+26 -10
View File
@@ -80,18 +80,27 @@ static_assert(kMinBackoffSum > 0, "The min backoff value should be greater than
void Mac::StartCsmaBackoff(void)
{
uint32_t backoffExponent = kMinBE + mTransmitAttempts + mCsmaAttempts;
uint32_t backoff;
if (backoffExponent > kMaxBE)
if (RadioSupportsRetriesAndCsmaBackoff())
{
backoffExponent = kMaxBE;
// If the radio supports the retry and back off logic, immediately schedule the send,
// and the radio will take care of everything.
mBackoffTimer.Start(0);
}
else
{
uint32_t backoffExponent = kMinBE + mTransmitAttempts + mCsmaAttempts;
uint32_t backoff;
backoff = kMinBackoff + (kUnitBackoffPeriod * kPhyUsPerSymbol * (1 << backoffExponent)) / 1000;
backoff = (otPlatRandomGet() % backoff);
if (backoffExponent > kMaxBE)
{
backoffExponent = kMaxBE;
}
mBackoffTimer.Start(backoff);
backoff = kMinBackoff + (kUnitBackoffPeriod * kPhyUsPerSymbol * (1 << backoffExponent)) / 1000;
backoff = (otPlatRandomGet() % backoff);
mBackoffTimer.Start(backoff);
}
}
Mac::Mac(ThreadNetif &aThreadNetif):
@@ -788,7 +797,8 @@ void Mac::TransmitDoneTask(bool aRxPending, ThreadError aError)
mCounters.mTxTotal++;
if (aError == kThreadError_ChannelAccessFailure &&
if (!RadioSupportsRetriesAndCsmaBackoff() &&
aError == kThreadError_ChannelAccessFailure &&
mCsmaAttempts < kMaxCSMABackoffs)
{
mCsmaAttempts++;
@@ -904,7 +914,8 @@ void Mac::SentFrame(ThreadError aError)
case kThreadError_NoAck:
otDumpDebgMac("NO ACK", sendFrame.GetHeader(), 16);
if (mTransmitAttempts < kMaxFrameAttempts)
if (!RadioSupportsRetriesAndCsmaBackoff() &&
mTransmitAttempts < kMaxFrameAttempts)
{
mTransmitAttempts++;
StartCsmaBackoff();
@@ -1376,6 +1387,11 @@ void Mac::SetPromiscuous(bool aPromiscuous)
}
}
bool Mac::RadioSupportsRetriesAndCsmaBackoff(void)
{
return (otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsTransmitRetries) != 0;
}
Whitelist &Mac::GetWhitelist(void)
{
return mWhitelist;
+9
View File
@@ -545,6 +545,15 @@ public:
*/
void ClearSrcMatchEntries();
/**
* This function indicates whether or not transmit retries and CSMA backoff logic is supported by the radio layer.
*
* @retval true Retries and CSMA are supported by the radio.
* @retval false Retries and CSMA are not supported by the radio.
*
*/
bool RadioSupportsRetriesAndCsmaBackoff(void);
private:
enum ScanType
{