mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 21:27:46 +00:00
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:
@@ -131,6 +131,8 @@ otLwfRadioInit(
|
|||||||
pFilter->otRadioCapabilities = kRadioCapsEnergyScan;
|
pFilter->otRadioCapabilities = kRadioCapsEnergyScan;
|
||||||
if ((pFilter->MiniportCapabilities.RadioCapabilities & OT_RADIO_CAP_ACK_TIMEOUT) != 0)
|
if ((pFilter->MiniportCapabilities.RadioCapabilities & OT_RADIO_CAP_ACK_TIMEOUT) != 0)
|
||||||
pFilter->otRadioCapabilities |= kRadioCapsAckTimeout;
|
pFilter->otRadioCapabilities |= kRadioCapsAckTimeout;
|
||||||
|
if ((pFilter->MiniportCapabilities.RadioCapabilities & OT_RADIO_CAP_MAC_RETRY_AND_COLLISION_AVOIDANCE) != 0)
|
||||||
|
pFilter->otRadioCapabilities |= kRadioCapsTransmitRetries;
|
||||||
|
|
||||||
pFilter->otPhyState = kStateDisabled;
|
pFilter->otPhyState = kStateDisabled;
|
||||||
pFilter->otCurrentListenChannel = 0xFF;
|
pFilter->otCurrentListenChannel = 0xFF;
|
||||||
|
|||||||
@@ -87,9 +87,10 @@ enum
|
|||||||
|
|
||||||
typedef enum otRadioCaps
|
typedef enum otRadioCaps
|
||||||
{
|
{
|
||||||
kRadioCapsNone = 0, ///< None
|
kRadioCapsNone = 0, ///< None
|
||||||
kRadioCapsAckTimeout = 1, ///< Radio supports AckTime event
|
kRadioCapsAckTimeout = 1, ///< Radio supports AckTime event
|
||||||
kRadioCapsEnergyScan = 2, ///< Radio supports Enegery Scans
|
kRadioCapsEnergyScan = 2, ///< Radio supports Enegery Scans
|
||||||
|
kRadioCapsTransmitRetries = 4, ///< Radio supports transmission retry logic with collission avoidance
|
||||||
} otRadioCaps;
|
} otRadioCaps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+26
-10
@@ -80,18 +80,27 @@ static_assert(kMinBackoffSum > 0, "The min backoff value should be greater than
|
|||||||
|
|
||||||
void Mac::StartCsmaBackoff(void)
|
void Mac::StartCsmaBackoff(void)
|
||||||
{
|
{
|
||||||
uint32_t backoffExponent = kMinBE + mTransmitAttempts + mCsmaAttempts;
|
if (RadioSupportsRetriesAndCsmaBackoff())
|
||||||
uint32_t backoff;
|
|
||||||
|
|
||||||
if (backoffExponent > kMaxBE)
|
|
||||||
{
|
{
|
||||||
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;
|
if (backoffExponent > kMaxBE)
|
||||||
backoff = (otPlatRandomGet() % backoff);
|
{
|
||||||
|
backoffExponent = kMaxBE;
|
||||||
|
}
|
||||||
|
|
||||||
mBackoffTimer.Start(backoff);
|
backoff = kMinBackoff + (kUnitBackoffPeriod * kPhyUsPerSymbol * (1 << backoffExponent)) / 1000;
|
||||||
|
backoff = (otPlatRandomGet() % backoff);
|
||||||
|
|
||||||
|
mBackoffTimer.Start(backoff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mac::Mac(ThreadNetif &aThreadNetif):
|
Mac::Mac(ThreadNetif &aThreadNetif):
|
||||||
@@ -788,7 +797,8 @@ void Mac::TransmitDoneTask(bool aRxPending, ThreadError aError)
|
|||||||
|
|
||||||
mCounters.mTxTotal++;
|
mCounters.mTxTotal++;
|
||||||
|
|
||||||
if (aError == kThreadError_ChannelAccessFailure &&
|
if (!RadioSupportsRetriesAndCsmaBackoff() &&
|
||||||
|
aError == kThreadError_ChannelAccessFailure &&
|
||||||
mCsmaAttempts < kMaxCSMABackoffs)
|
mCsmaAttempts < kMaxCSMABackoffs)
|
||||||
{
|
{
|
||||||
mCsmaAttempts++;
|
mCsmaAttempts++;
|
||||||
@@ -904,7 +914,8 @@ void Mac::SentFrame(ThreadError aError)
|
|||||||
case kThreadError_NoAck:
|
case kThreadError_NoAck:
|
||||||
otDumpDebgMac("NO ACK", sendFrame.GetHeader(), 16);
|
otDumpDebgMac("NO ACK", sendFrame.GetHeader(), 16);
|
||||||
|
|
||||||
if (mTransmitAttempts < kMaxFrameAttempts)
|
if (!RadioSupportsRetriesAndCsmaBackoff() &&
|
||||||
|
mTransmitAttempts < kMaxFrameAttempts)
|
||||||
{
|
{
|
||||||
mTransmitAttempts++;
|
mTransmitAttempts++;
|
||||||
StartCsmaBackoff();
|
StartCsmaBackoff();
|
||||||
@@ -1376,6 +1387,11 @@ void Mac::SetPromiscuous(bool aPromiscuous)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Mac::RadioSupportsRetriesAndCsmaBackoff(void)
|
||||||
|
{
|
||||||
|
return (otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsTransmitRetries) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
Whitelist &Mac::GetWhitelist(void)
|
Whitelist &Mac::GetWhitelist(void)
|
||||||
{
|
{
|
||||||
return mWhitelist;
|
return mWhitelist;
|
||||||
|
|||||||
@@ -545,6 +545,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
void ClearSrcMatchEntries();
|
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:
|
private:
|
||||||
enum ScanType
|
enum ScanType
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user