Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[radio] use new implementation of time sync #876

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 9 additions & 29 deletions src/src/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ static otRadioFrame sTransmitFrame;
static uint8_t sTransmitPsdu[OT_RADIO_FRAME_MAX_SIZE + 1];

#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
static otExtAddress sExtAddress;
static otRadioIeInfo sTransmitIeInfo;
static otInstance *sInstance = NULL;
static otExtAddress sExtAddress;
static otInstance *sInstance = NULL;
#endif

static otRadioFrame sAckFrame;
Expand Down Expand Up @@ -172,9 +171,6 @@ static void dataInit(void)

sDefaultTxPower = OT_RADIO_POWER_INVALID;
sTransmitFrame.mPsdu = sTransmitPsdu + 1;
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
sTransmitFrame.mInfo.mTxInfo.mIeInfo = &sTransmitIeInfo;
#endif

sReceiveError = OT_ERROR_NONE;

Expand Down Expand Up @@ -534,10 +530,11 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
otMacFrameSetFrameCounter(aFrame, sMacFrameCounter++);
}

if (aFrame->mInfo.mTxInfo.mTxDelay != 0)
if (aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelay != 0)
{
if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], true, aFrame->mInfo.mTxInfo.mTxDelayBaseTime,
aFrame->mInfo.mTxInfo.mTxDelay, aFrame->mChannel))
if (!nrf_802154_transmit_raw_at(&aFrame->mPsdu[-1], true,
aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelayBaseTime,
aFrame->mInfo.mTxInfo.mTimeInfo.mDelayInfo.mTxDelay, aFrame->mChannel))
{
error = OT_ERROR_INVALID_STATE;
}
Expand Down Expand Up @@ -1220,7 +1217,7 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
void nrf_802154_tx_started(const uint8_t *aFrame)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may consider moving the whole implementation of nrf_802154_tx_started() to SubMac, and SubMac provide a function for radio driver to generate the ACK frame. This could greatly reduce platform radio APIs and the complexity of the otRadioFrame.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering wrapping all manipulations on SFD in a single callback. We probably shouldn't put it into SubMac, as this callback is probably called by a ISR.

bool processSecurity = false;
uint64_t now = otPlatTimeGet();

assert(aFrame == sTransmitPsdu);
OT_UNUSED_VARIABLE(aFrame);
Expand All @@ -1234,34 +1231,17 @@ void nrf_802154_tx_started(const uint8_t *aFrame)

// Update IE and secure transmit frame
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
if (sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0)
{
uint8_t *timeIe = sTransmitFrame.mPsdu + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset;
uint64_t time = otPlatTimeGet() + sTransmitFrame.mInfo.mTxInfo.mIeInfo->mNetworkTimeOffset;

*timeIe = sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeSyncSeq;

*(++timeIe) = (uint8_t)(time & 0xff);
for (uint8_t i = 1; i < sizeof(uint64_t); i++)
{
time = time >> 8;
*(++timeIe) = (uint8_t)(time & 0xff);
}

processSecurity = true;
}
otMacFrameUpdateTimeIe(&sTransmitFrame, now);
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE

#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
otEXPECT(otMacFrameIsSecurityEnabled(&sTransmitFrame) && otMacFrameIsKeyIdMode1(&sTransmitFrame) &&
!sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);

sTransmitFrame.mInfo.mTxInfo.mAesKey = &sCurrKey;

processSecurity = true;
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2

otEXPECT(processSecurity);
otEXPECT(!sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);
otMacFrameProcessTransmitAesCcm(&sTransmitFrame, &sExtAddress);

exit:
Expand Down
Loading