Skip to content

Commit acea8ac

Browse files
[low-power] enhance mCslFrameRequestAheadUs calculation for RCP
Implement `otPlatRadioGetBusLatency` and `otPlatRadioSetBusLatency` APIs, add optional latency arguments to ot-daemon and `rcp latency` CLI commands. Add APIs to update frame request ahead from runtime, which recalculate `mCslFrameRequestAheadUs` value. Changes allow setting a bus latency while starting a new session between host and RCP device. This way, one host can be connected to different devices and vice versa, ensuring that the latency will be added to `mCslFrameRequestAheadUs` calculations and CSL tx requests will not be sent too late. Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
1 parent 78ecafb commit acea8ac

File tree

12 files changed

+169
-15
lines changed

12 files changed

+169
-15
lines changed

include/openthread/instance.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
* @note This number versions both OpenThread platform and user APIs.
5454
*
5555
*/
56-
#define OPENTHREAD_API_VERSION (427)
56+
#define OPENTHREAD_API_VERSION (428)
5757

5858
/**
5959
* @addtogroup api-instance

include/openthread/platform/radio.h

+11
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,17 @@ uint64_t otPlatRadioGetNow(otInstance *aInstance);
757757
*/
758758
uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance);
759759

760+
/**
761+
* Get the bus latency in microseconds between the host and the radio chip.
762+
*
763+
* @param[in] aInstance A pointer to an OpenThread instance.
764+
*
765+
* @returns The bus latency in microseconds between the host and the radio chip.
766+
* Return 0 when the MAC and above layer and Radio layer resides on the same chip.
767+
*
768+
*/
769+
uint32_t otPlatRadioGetBusLatency(otInstance *aInstance);
770+
760771
/**
761772
* @}
762773
*

include/openthread/thread_ftd.h

+9
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,15 @@ void otThreadGetNextHopAndPathCost(otInstance *aInstance,
953953
uint16_t *aNextHopRloc16,
954954
uint8_t *aPathCost);
955955

956+
/**
957+
* Calculates and updates value of CSL Frame Request Ahead, based on bus speed, bus latency and
958+
* `OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US`.
959+
*
960+
* @param[in] aInstance A pointer to an OpenThread instance.
961+
*
962+
*/
963+
void otThreadUpdateFrameRequestAhead(otInstance *aInstance);
964+
956965
/**
957966
* @}
958967
*

src/cli/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,25 @@ OPENTHREAD/20191113-00825-g82053cc9d-dirty; SIMULATION; Jun 4 2020 17:53:16
32183218
Done
32193219
```
32203220
3221+
### rcp latency
3222+
3223+
Get the bus latency in microseconds between the host and the radio chip.
3224+
3225+
```bash
3226+
> rcp latency
3227+
0
3228+
Done
3229+
```
3230+
3231+
### rcp latency \<latency\>
3232+
3233+
Set the bus latency in microseconds between the host and the radio chip.
3234+
3235+
```bash
3236+
> rcp latency 1000
3237+
Done
3238+
```
3239+
32213240
### releaserouterid \<routerid\>
32223241
32233242
Release a Router ID that has been allocated by the device in the Leader role.

src/core/api/thread_ftd_api.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,12 @@ void otThreadGetNextHopAndPathCost(otInstance *aInstance,
428428
(aPathCost != nullptr) ? *aPathCost : pathcost);
429429
}
430430

431+
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
432+
void otThreadUpdateFrameRequestAhead(otInstance *aInstance)
433+
{
434+
AsCoreType(aInstance).Get<CslTxScheduler>().UpdateFrameRequestAhead();
435+
}
436+
437+
#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
438+
431439
#endif // OPENTHREAD_FTD

src/core/radio/radio_platform.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ OT_TOOL_WEAK uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
250250
return 0;
251251
}
252252

253+
OT_TOOL_WEAK uint32_t otPlatRadioGetBusLatency(otInstance *aInstance)
254+
{
255+
OT_UNUSED_VARIABLE(aInstance);
256+
257+
return 0;
258+
}
259+
253260
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
254261
OT_TOOL_WEAK otError otPlatRadioResetCsl(otInstance *aInstance)
255262
{

src/core/thread/csl_tx_scheduler.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "common/locator_getters.hpp"
3434
#include "common/log.hpp"
35+
#include "common/num_utils.hpp"
3536
#include "common/time.hpp"
3637
#include "mac/mac.hpp"
3738

@@ -68,16 +69,20 @@ CslTxScheduler::CslTxScheduler(Instance &aInstance)
6869
, mFrameContext()
6970
, mCallbacks(aInstance)
7071
{
71-
InitFrameRequestAhead();
72+
UpdateFrameRequestAhead();
7273
}
7374

74-
void CslTxScheduler::InitFrameRequestAhead(void)
75+
void CslTxScheduler::UpdateFrameRequestAhead(void)
7576
{
7677
uint32_t busSpeedHz = otPlatRadioGetBusSpeed(&GetInstance());
78+
uint32_t busLatency = otPlatRadioGetBusLatency(&GetInstance());
79+
7780
// longest frame on bus is 127 bytes with some metadata, use 150 bytes for bus Tx time estimation
7881
uint32_t busTxTimeUs = ((busSpeedHz == 0) ? 0 : (150 * 8 * 1000000 + busSpeedHz - 1) / busSpeedHz);
7982

80-
mCslFrameRequestAheadUs = OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs;
83+
mCslFrameRequestAheadUs = OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs + busLatency;
84+
LogInfo("Bus TX Time: %lu usec, Latency: %lu usec. Calculated CSL Frame Request Ahead: %lu usec",
85+
ToUlong(busTxTimeUs), ToUlong(busLatency), ToUlong(mCslFrameRequestAheadUs));
8186
}
8287

8388
void CslTxScheduler::Update(void)

src/core/thread/csl_tx_scheduler.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,17 @@ class CslTxScheduler : public InstanceLocator, private NonCopyable
231231
*/
232232
void Clear(void);
233233

234+
/**
235+
* Updates the value of `mCslFrameRequestAheadUs`, based on bus speed, bus latency
236+
* and `OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US`.
237+
*
238+
*/
239+
void UpdateFrameRequestAhead(void);
240+
234241
private:
235242
// Guard time in usec to add when checking delay while preparing the CSL frame for tx.
236243
static constexpr uint32_t kFramePreparationGuardInterval = 1500;
237244

238-
void InitFrameRequestAhead(void);
239245
void RescheduleCslTx(void);
240246

241247
uint32_t GetNextCslTransmissionDelay(const Child &aChild, uint32_t &aDelayFromLastRx, uint32_t aAheadUs) const;

src/lib/spinel/radio_spinel.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <stdlib.h>
4040

4141
#include <openthread/logging.h>
42+
#include <openthread/thread_ftd.h>
4243
#include <openthread/platform/diag.h>
4344
#include <openthread/platform/time.h>
4445

@@ -78,6 +79,7 @@ RadioSpinel::RadioSpinel(void)
7879
, mPanId(0xffff)
7980
, mChannel(0)
8081
, mRxSensitivity(0)
82+
, mBusLatency(0)
8183
, mState(kStateDisabled)
8284
, mIsPromiscuous(false)
8385
, mRxOnWhenIdle(true)
@@ -1774,6 +1776,45 @@ void RadioSpinel::GetDiagOutputCallback(otPlatDiagOutputCallback &aCallback, voi
17741776
aContext = mOutputContext;
17751777
}
17761778

1779+
otError RadioSpinel::PlatDiagProcess(uint8_t aArgsLength, char *aArgs[])
1780+
{
1781+
otError error = OT_ERROR_NONE;
1782+
char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE] = {'\0'};
1783+
char *cur = cmd;
1784+
char *end = cmd + sizeof(cmd);
1785+
1786+
if (strcmp(aArgs[0], "buslatency") == 0)
1787+
{
1788+
if (aArgsLength == 2)
1789+
{
1790+
uint32_t latency;
1791+
char *endptr;
1792+
1793+
latency = (uint32_t)strtoul(aArgs[1], &endptr, 0);
1794+
VerifyOrExit(*endptr == '\0', error = OT_ERROR_INVALID_ARGS);
1795+
1796+
SetBusLatency(latency);
1797+
ExitNow();
1798+
}
1799+
else
1800+
{
1801+
uint32_t latency = GetBusLatency();
1802+
PlatDiagOutput("%lu\n", ToUlong(latency));
1803+
ExitNow();
1804+
}
1805+
}
1806+
1807+
for (uint8_t index = 0; (index < aArgsLength) && (cur < end); index++)
1808+
{
1809+
cur += snprintf(cur, static_cast<size_t>(end - cur), "%s ", aArgs[index]);
1810+
}
1811+
1812+
SuccessOrExit(error = PlatDiagProcess(cmd));
1813+
1814+
exit:
1815+
return error;
1816+
}
1817+
17771818
otError RadioSpinel::PlatDiagProcess(const char *aString)
17781819
{
17791820
return Set(SPINEL_PROP_NEST_STREAM_MFG, SPINEL_DATATYPE_UTF8_S, aString);
@@ -1903,6 +1944,19 @@ uint64_t RadioSpinel::GetNow(void) { return (mIsTimeSynced) ? (otPlatTimeGet() +
19031944

19041945
uint32_t RadioSpinel::GetBusSpeed(void) const { return GetSpinelDriver().GetSpinelInterface()->GetBusSpeed(); }
19051946

1947+
uint32_t RadioSpinel::GetBusLatency(void) const { return mBusLatency; }
1948+
1949+
void RadioSpinel::SetBusLatency(uint32_t aBusLatency)
1950+
{
1951+
mBusLatency = aBusLatency;
1952+
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
1953+
if (IsEnabled())
1954+
{
1955+
otThreadUpdateFrameRequestAhead(mInstance);
1956+
}
1957+
#endif // OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
1958+
}
1959+
19061960
void RadioSpinel::HandleRcpUnexpectedReset(spinel_status_t aStatus)
19071961
{
19081962
OT_UNUSED_VARIABLE(aStatus);

src/lib/spinel/radio_spinel.hpp

+30
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,18 @@ class RadioSpinel : private Logger
680680
*/
681681
bool IsDiagEnabled(void) const { return mDiagMode; }
682682

683+
/**
684+
* Processes platform diagnostics commands.
685+
*
686+
* @param[in] aString A null-terminated input string.
687+
*
688+
* @retval OT_ERROR_NONE Succeeded.
689+
* @retval OT_ERROR_BUSY Failed due to another operation is on going.
690+
* @retval OT_ERROR_RESPONSE_TIMEOUT Failed due to no response received from the transceiver.
691+
*
692+
*/
693+
otError PlatDiagProcess(uint8_t aArgsLength, char *aArgs[]);
694+
683695
/**
684696
* Processes platform diagnostics commands.
685697
*
@@ -857,6 +869,22 @@ class RadioSpinel : private Logger
857869
*/
858870
uint32_t GetBusSpeed(void) const;
859871

872+
/**
873+
* Returns the bus latency between the host and the radio.
874+
*
875+
* @returns Bus latency in microseconds.
876+
*
877+
*/
878+
uint32_t GetBusLatency(void) const;
879+
880+
/**
881+
* Sets the bus latency between the host and the radio.
882+
*
883+
* @param[in] aBusLatency Bus latency in microseconds.
884+
*
885+
*/
886+
void SetBusLatency(uint32_t aBusLatency);
887+
860888
/**
861889
* Returns the co-processor sw version string.
862890
*
@@ -1254,6 +1282,8 @@ class RadioSpinel : private Logger
12541282
static otExtAddress sIeeeEui64;
12551283
static otRadioCaps sRadioCaps;
12561284

1285+
uint32_t mBusLatency;
1286+
12571287
State mState;
12581288
bool mIsPromiscuous : 1; ///< Promiscuous mode.
12591289
bool mRxOnWhenIdle : 1; ///< RxOnWhenIdle mode.

src/posix/platform/radio.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ void Radio::ProcessRadioUrl(const RadioUrl &aRadioUrl)
130130
SuccessOrDie(otPlatRadioSetRegion(gInstance, regionCode));
131131
}
132132

133+
if (aRadioUrl.HasParam("bus-latency"))
134+
{
135+
uint32_t busLatency;
136+
SuccessOrDie(aRadioUrl.ParseUint32("bus-latency", busLatency));
137+
mRadioSpinel.SetBusLatency(busLatency);
138+
}
139+
133140
ProcessMaxPowerTable(aRadioUrl);
134141

135142
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
@@ -548,11 +555,7 @@ void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback
548555

549556
otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
550557
{
551-
// deliver the platform specific diags commands to radio only ncp.
552558
OT_UNUSED_VARIABLE(aInstance);
553-
char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE] = {'\0'};
554-
char *cur = cmd;
555-
char *end = cmd + sizeof(cmd);
556559

557560
#if OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE
558561
if (strcmp(aArgs[0], "rcpcaps") == 0)
@@ -561,12 +564,7 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
561564
}
562565
#endif
563566

564-
for (uint8_t index = 0; (index < aArgsLength) && (cur < end); index++)
565-
{
566-
cur += snprintf(cur, static_cast<size_t>(end - cur), "%s ", aArgs[index]);
567-
}
568-
569-
return GetRadioSpinel().PlatDiagProcess(cmd);
567+
return GetRadioSpinel().PlatDiagProcess(aArgsLength, aArgs);
570568
}
571569

572570
void otPlatDiagModeSet(bool aMode)
@@ -900,6 +898,12 @@ uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
900898
return GetRadioSpinel().GetBusSpeed();
901899
}
902900

901+
uint32_t otPlatRadioGetBusLatency(otInstance *aInstance)
902+
{
903+
OT_UNUSED_VARIABLE(aInstance);
904+
return GetRadioSpinel().GetBusLatency();
905+
}
906+
903907
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
904908
uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance)
905909
{

src/posix/platform/radio_url.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const char *otSysGetRadioUrlHelpString(void)
121121
" fem-lnagain[=dbm] Set the Rx LNA gain in dBm of the external FEM.\n"
122122
" no-reset Do not send Spinel reset command to RCP on initialization.\n"
123123
" skip-rcp-compatibility-check Skip checking RCP API version and capabilities during initialization.\n"
124+
" bus-latency[=usec] Communication latency in usec, default is 0.\n"
124125
#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
125126
" iid Set the Spinel Interface ID for this process. Valid values are 0-3.\n"
126127
" iid-list List of IIDs a host can subscribe to receive spinel frames other than \n"

0 commit comments

Comments
 (0)