Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejbaczmanski committed Jul 18, 2024
1 parent ca90e69 commit 4baa4a4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 24 deletions.
11 changes: 11 additions & 0 deletions include/openthread/platform/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,17 @@ otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint1
*/
extern void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyScanMaxRssi);

/**
* The radio driver calls this method to notify OpenThread that the energy scan is complete.
*
* Is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aEnergyScanMaxRssi The maximum RSSI encountered on the scanned channel.
*
*/
extern void otPlatRadioBusLatencyUpdated(otInstance *aInstance);

/**
* Enable/Disable source address match feature.
*
Expand Down
8 changes: 0 additions & 8 deletions include/openthread/thread_ftd.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,14 +953,6 @@ void otThreadGetNextHopAndPathCost(otInstance *aInstance,
uint16_t *aNextHopRloc16,
uint8_t *aPathCost);

/**
* Calculates and updates value of CSL Frame Request Ahead, based on bus speed, bus latency and
* `OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US`.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
void otThreadUpdateFrameRequestAhead(otInstance *aInstance);

/**
* @}
Expand Down
8 changes: 0 additions & 8 deletions src/core/api/thread_ftd_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,4 @@ void otThreadGetNextHopAndPathCost(otInstance *aInstance,
(aPathCost != nullptr) ? *aPathCost : pathcost);
}

#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
void otThreadUpdateFrameRequestAhead(otInstance *aInstance)
{
AsCoreType(aInstance).Get<CslTxScheduler>().UpdateFrameRequestAhead();
}

#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE

#endif // OPENTHREAD_FTD
12 changes: 12 additions & 0 deletions src/core/radio/radio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ class Radio : public InstanceLocator, private NonCopyable
*/
void HandleEnergyScanDone(int8_t aMaxRssi);


/**
* This callback method handles "Energy Scan Done" event from radio platform.
*
* Is used when radio provides OT_RADIO_CAPS_ENERGY_SCAN capability. It is called from
* `otPlatRadioEnergyScanDone()`.
*
*
*/
void HandleBusLatencyUpdated(void);


#if OPENTHREAD_CONFIG_DIAG_ENABLE
/**
* This callback method handles a "Receive Done" event from radio platform when diagnostics mode is enabled.
Expand Down
7 changes: 7 additions & 0 deletions src/core/radio/radio_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ void Radio::Callbacks::HandleTransmitDone(Mac::TxFrame &aFrame, Mac::RxFrame *aA

void Radio::Callbacks::HandleEnergyScanDone(int8_t aMaxRssi) { Get<Mac::SubMac>().HandleEnergyScanDone(aMaxRssi); }

void Radio::Callbacks::HandleBusLatencyUpdated(void)
{
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
Get<CslTxScheduler>().UpdateFrameRequestAhead();
#endif
}

#if OPENTHREAD_CONFIG_DIAG_ENABLE
void Radio::Callbacks::HandleDiagsReceiveDone(Mac::RxFrame *aFrame, Error aError)
{
Expand Down
13 changes: 13 additions & 0 deletions src/core/radio/radio_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ extern "C" void otPlatRadioEnergyScanDone(otInstance *aInstance, int8_t aEnergyS
return;
}

extern "C" void otPlatRadioBusLatencyUpdated(otInstance *aInstance)
{
Instance &instance = AsCoreType(aInstance);

VerifyOrExit(instance.IsInitialized());
instance.Get<Radio::Callbacks>().HandleBusLatencyUpdated();

exit:
return;
}

#if OPENTHREAD_CONFIG_DIAG_ENABLE
extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError)
{
Expand Down Expand Up @@ -153,6 +164,8 @@ extern "C" void otPlatRadioTxDone(otInstance *, otRadioFrame *, otRadioFrame *,

extern "C" void otPlatRadioEnergyScanDone(otInstance *, int8_t) {}

extern "C" void otPlatRadioBusLatencyUpdated(otInstance *) {}

#if OPENTHREAD_CONFIG_DIAG_ENABLE
extern "C" void otPlatDiagRadioReceiveDone(otInstance *, otRadioFrame *, otError) {}

Expand Down
7 changes: 3 additions & 4 deletions src/lib/spinel/radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,12 +1946,11 @@ uint32_t RadioSpinel::GetBusLatency(void) const { return mBusLatency; }
void RadioSpinel::SetBusLatency(uint32_t aBusLatency)
{
mBusLatency = aBusLatency;
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
if (IsEnabled())

if (IsEnabled() && mCallbacks.mBusLatencyUpdated != nullptr)
{
otThreadUpdateFrameRequestAhead(mInstance);
mCallbacks.mBusLatencyUpdated(mInstance);
}
#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
}

void RadioSpinel::HandleRcpUnexpectedReset(spinel_status_t aStatus)
Expand Down
9 changes: 9 additions & 0 deletions src/lib/spinel/radio_spinel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ struct RadioSpinelCallbacks
*/
void (*mEnergyScanDone)(otInstance *aInstance, int8_t aMaxRssi);

/**
* This callback notifies user of `RadioSpinel` that energy scan is complete.
*
* @param[in] aInstance The OpenThread instance structure.
* @param[in] aMaxRssi Maximum RSSI seen on the channel, or `SubMac::kInvalidRssiValue` if failed.
*
*/
void (*mBusLatencyUpdated)(otInstance *aInstance);

/**
* This callback notifies user of `RadioSpinel` that the transmission has started.
*
Expand Down
9 changes: 5 additions & 4 deletions src/posix/platform/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ void Radio::Init(const char *aUrl)
callbacks.mDiagReceiveDone = otPlatDiagRadioReceiveDone;
callbacks.mDiagTransmitDone = otPlatDiagRadioTransmitDone;
#endif // OPENTHREAD_CONFIG_DIAG_ENABLE
callbacks.mEnergyScanDone = otPlatRadioEnergyScanDone;
callbacks.mReceiveDone = otPlatRadioReceiveDone;
callbacks.mTransmitDone = otPlatRadioTxDone;
callbacks.mTxStarted = otPlatRadioTxStarted;
callbacks.mEnergyScanDone = otPlatRadioEnergyScanDone;
callbacks.mBusLatencyUpdated = otPlatRadioBusLatencyUpdated;
callbacks.mReceiveDone = otPlatRadioReceiveDone;
callbacks.mTransmitDone = otPlatRadioTxDone;
callbacks.mTxStarted = otPlatRadioTxStarted;

resetRadio = !mRadioUrl.HasParam("no-reset");
skipCompatibilityCheck = mRadioUrl.HasParam("skip-rcp-compatibility-check");
Expand Down

0 comments on commit 4baa4a4

Please sign in to comment.