Skip to content

Commit 2b197e5

Browse files
WIP
1 parent e10a925 commit 2b197e5

21 files changed

+240
-12
lines changed

include/openthread/platform/radio.h

+22
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,28 @@ uint64_t otPlatRadioGetNow(otInstance *aInstance);
737737
*/
738738
uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance);
739739

740+
/**
741+
* Get the bus latency in microseconds between the host and the radio chip.
742+
*
743+
* @param[in] aInstance A pointer to an OpenThread instance.
744+
*
745+
* @returns The bus latency in microseconds between the host and the radio chip.
746+
* Return 0 when the MAC and above layer and Radio layer resides on the same chip.
747+
*
748+
*/
749+
uint32_t otPlatRadioGetBusLatency(otInstance *aInstance);
750+
751+
/**
752+
* Set the bus latency in microseconds between the host and the radio chip.
753+
*
754+
* @note This function does not do anything when the MAC and above layer and Radio layer resides on the same chip.
755+
*
756+
* @param[in] aInstance A pointer to an OpenThread instance.
757+
* @param[in] aLatency Bus latency in microseconds.
758+
*
759+
*/
760+
void otPlatRadioSetBusLatency(otInstance *aInstance, uint32_t aLatency);
761+
740762
/**
741763
* @}
742764
*

include/openthread/thread.h

+15
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,21 @@ otError otThreadSendProactiveBackboneNotification(otInstance *aIns
11361136
*/
11371137
otError otThreadDetachGracefully(otInstance *aInstance, otDetachGracefullyCallback aCallback, void *aContext);
11381138

1139+
/**
1140+
* Notifies other nodes in the network (if any) and then stops Thread protocol operation.
1141+
*
1142+
* It sends an Address Release if it's a router, or sets its child timeout to 0 if it's a child.
1143+
*
1144+
* @param[in] aInstance A pointer to an OpenThread instance.
1145+
* @param[in] aCallback A pointer to a function that is called upon finishing detaching.
1146+
* @param[in] aContext A pointer to callback application-specific context.
1147+
*
1148+
* @retval OT_ERROR_NONE Successfully started detaching.
1149+
* @retval OT_ERROR_BUSY Detaching is already in progress.
1150+
*
1151+
*/
1152+
void otThreaUpdateCslTimeout(otInstance *aInstance);
1153+
11391154
#define OT_DURATION_STRING_SIZE 21 ///< Recommended size for string representation of `uint32_t` duration in seconds.
11401155

11411156
/**

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 betw.
3224+
3225+
```bash
3226+
> rcp latency
3227+
0
3228+
Done
3229+
```
3230+
3231+
### rcp latency \<latency\>
3232+
3233+
Set the Thread Network Key value.
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/cli/cli.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
#include "common/new.hpp"
9393
#include "common/numeric_limits.hpp"
9494
#include "common/string.hpp"
95+
#include "common/locator_getters.hpp"
96+
9597
#include "mac/channel_mask.hpp"
9698

9799
namespace ot {
@@ -5938,8 +5940,8 @@ template <> otError Interpreter::Process<Cmd("radio")>(Arg aArgs[])
59385940

59395941
template <> otError Interpreter::Process<Cmd("rcp")>(Arg aArgs[])
59405942
{
5941-
otError error = OT_ERROR_NONE;
5942-
const char *version = otPlatRadioGetVersionString(GetInstancePtr());
5943+
otError error = OT_ERROR_NONE;
5944+
const char *version = otPlatRadioGetVersionString(GetInstancePtr());
59435945

59445946
VerifyOrExit(version != otGetVersionString(), error = OT_ERROR_NOT_IMPLEMENTED);
59455947
/**
@@ -5956,7 +5958,21 @@ template <> otError Interpreter::Process<Cmd("rcp")>(Arg aArgs[])
59565958
{
59575959
OutputLine("%s", version);
59585960
}
5961+
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
5962+
else if (aArgs[0] == "latency")
5963+
{
5964+
if (aArgs[1].IsEmpty())
5965+
{
5966+
uint32_t latency = otPlatRadioGetBusLatency(GetInstancePtr());
59595967

5968+
OutputLine("%lu", ToUlong(latency));
5969+
}
5970+
else
5971+
{
5972+
error = ProcessSet(aArgs + 1, otPlatRadioSetBusLatency);
5973+
}
5974+
}
5975+
#endif
59605976
else
59615977
{
59625978
error = OT_ERROR_INVALID_ARGS;

src/core/api/thread_api.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,15 @@ otError otThreadDetachGracefully(otInstance *aInstance, otDetachGracefullyCallba
512512

513513
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
514514

515+
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
516+
517+
void otThreaUpdateCslTimeout(otInstance *aInstance)
518+
{
519+
AsCoreType(aInstance).Get<CslTxScheduler>().UpdateFrameRequestAhead();
520+
// Get<AnycastLocator>().IsInProgress();
521+
}
522+
#endif
523+
515524
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
516525
void otConvertDurationInSecondsToString(uint32_t aDuration, char *aBuffer, uint16_t aSize)
517526
{

src/core/instance/instance.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#include "thread/announce_begin_server.hpp"
106106
#include "thread/announce_sender.hpp"
107107
#include "thread/anycast_locator.hpp"
108+
#include "thread/csl_tx_scheduler.hpp"
108109
#include "thread/child_supervision.hpp"
109110
#include "thread/discover_scanner.hpp"
110111
#include "thread/dua_manager.hpp"

src/core/radio/radio_platform.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,19 @@ 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+
260+
OT_TOOL_WEAK void otPlatRadioSetBusLatency(otInstance *aInstance, uint32_t aLatency)
261+
{
262+
OT_UNUSED_VARIABLE(aInstance);
263+
OT_UNUSED_VARIABLE(aLatency);
264+
}
265+
253266
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
254267
OT_TOOL_WEAK otError otPlatRadioResetCsl(otInstance *aInstance)
255268
{

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("Declared Bus TX Time: %lu, Latency: %lu. Calculated CSL Frame Request Ahead: %lu",
85+
ToUlong(busTxTimeUs), ToUlong(busLatency), ToUlong(mCslFrameRequestAheadUs));
8186
}
8287

8388
void CslTxScheduler::Update(void)

src/core/thread/csl_tx_scheduler.hpp

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

234+
/**
235+
* Updates the value of `mCslFrameRequestAheadUs`.
236+
*
237+
*/
238+
void UpdateFrameRequestAhead(void);
239+
234240
private:
235241
// Guard time in usec to add when checking delay while preparing the CSL frame for tx.
236242
static constexpr uint32_t kFramePreparationGuardInterval = 1500;
237243

238-
void InitFrameRequestAhead(void);
239244
void RescheduleCslTx(void);
240245

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

src/lib/spinel/radio_spinel.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,10 @@ uint64_t RadioSpinel::GetNow(void) { return (mIsTimeSynced) ? (otPlatTimeGet() +
19001900

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

1903+
uint32_t RadioSpinel::GetBusLatency(void) const { return GetSpinelDriver().GetSpinelInterface()->GetBusLatency(); }
1904+
1905+
void RadioSpinel::SetBusLatency(uint32_t aLatency) { GetSpinelDriver().GetSpinelInterface()->SetBusLatency(aLatency); }
1906+
19031907
void RadioSpinel::HandleRcpUnexpectedReset(spinel_status_t aStatus)
19041908
{
19051909
OT_UNUSED_VARIABLE(aStatus);

src/lib/spinel/radio_spinel.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,22 @@ class RadioSpinel : private Logger
843843
*/
844844
uint32_t GetBusSpeed(void) const;
845845

846+
/**
847+
* Returns the bus latency between the host and the radio.
848+
*
849+
* @returns Bus latency in microseconds.
850+
*
851+
*/
852+
uint32_t GetBusLatency(void) const;
853+
854+
/**
855+
* Sets the bus latency between the host and the radio.
856+
*
857+
* @param[in] aLatency Bus latency in microseconds.
858+
*
859+
*/
860+
void SetBusLatency(uint32_t aLatency);
861+
846862
/**
847863
* Returns the co-processor sw version string.
848864
*

src/lib/spinel/spinel_interface.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ class SpinelInterface
134134
*/
135135
virtual uint32_t GetBusSpeed(void) const = 0;
136136

137+
/**
138+
* Returns the bus latency between the host and the radio.
139+
*
140+
* @returns Bus latency in microseconds.
141+
*
142+
*/
143+
virtual uint32_t GetBusLatency(void) const = 0;
144+
145+
/**
146+
* Sets the bus latency between the host and the radio.
147+
*
148+
* @param[in] aLatency Bus latency in microseconds.
149+
*
150+
*/
151+
virtual void SetBusLatency(uint32_t aLatency) = 0;
152+
137153
/**
138154
* Hardware resets the RCP.
139155
*

src/posix/platform/hdlc_interface.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ int HdlcInterface::OpenFile(const Url::Url &aRadioUrl)
466466
speed_t speed;
467467
uint8_t stopBit = 1;
468468
uint32_t baudrate = 115200;
469+
uint32_t latency = 0;
469470

470471
VerifyOrExit((rval = tcgetattr(fd, &tios)) == 0);
471472

@@ -596,6 +597,10 @@ int HdlcInterface::OpenFile(const Url::Url &aRadioUrl)
596597

597598
mBaudRate = baudrate;
598599

600+
IgnoreError(aRadioUrl.ParseUint32("uart-latency", latency));
601+
602+
mLatency = latency;
603+
599604
if (aRadioUrl.HasParam("uart-flow-control"))
600605
{
601606
tios.c_cflag |= CRTSCTS;

src/posix/platform/hdlc_interface.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ class HdlcInterface : public ot::Spinel::SpinelInterface, public Logger<HdlcInte
141141
*/
142142
uint32_t GetBusSpeed(void) const { return mBaudRate; }
143143

144+
/**
145+
* Returns the bus latency between the host and the radio.
146+
*
147+
* @returns Bus latency in microseconds.
148+
*
149+
*/
150+
uint32_t GetBusLatency(void) const { return mLatency; }
151+
152+
/**
153+
* Sets the bus latency between the host and the radio.
154+
*
155+
* @param[in] aLatency Bus latency in microseconds.
156+
*
157+
*/
158+
void SetBusLatency(uint32_t aLatency) { mLatency = aLatency; }
159+
144160
/**
145161
* Hardware resets the RCP.
146162
*
@@ -263,6 +279,7 @@ class HdlcInterface : public ot::Spinel::SpinelInterface, public Logger<HdlcInte
263279

264280
int mSockFd;
265281
uint32_t mBaudRate;
282+
uint32_t mLatency;
266283
Hdlc::Decoder mHdlcDecoder;
267284
const Url::Url &mRadioUrl;
268285

src/posix/platform/radio.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <openthread/logging.h>
3939
#include <openthread/platform/diag.h>
40+
#include <openthread/thread.h>
4041

4142
#include "common/code_utils.hpp"
4243
#include "common/new.hpp"
@@ -900,6 +901,23 @@ uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance)
900901
return GetRadioSpinel().GetBusSpeed();
901902
}
902903

904+
uint32_t otPlatRadioGetBusLatency(otInstance *aInstance)
905+
{
906+
OT_UNUSED_VARIABLE(aInstance);
907+
return GetRadioSpinel().GetBusLatency();
908+
}
909+
910+
void otPlatRadioSetBusLatency(otInstance *aInstance, uint32_t aLatency)
911+
{
912+
GetRadioSpinel().SetBusLatency(aLatency);
913+
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
914+
otThreaUpdateCslTimeout(aInstance);
915+
#else
916+
OT_UNUSED_VARIABLE(aInstance);
917+
#endif
918+
919+
}
920+
903921
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE || OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
904922
uint8_t otPlatRadioGetCslAccuracy(otInstance *aInstance)
905923
{

src/posix/platform/radio_url.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,22 @@ const char *otSysGetRadioUrlHelpString(void)
4949
"Parameters:\n" \
5050
" gpio-int-device[=gpio-device-path]\n" \
5151
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
52-
" `I̅N̅T̅` pin. If not specified, `SPI` interface will fall back to\n" \
52+
" `I̅N̅T̅` pin. If not specified, `SPI` interface will fall back to\n" \
5353
" polling, which is inefficient.\n" \
5454
" gpio-int-line[=line-offset]\n" \
55-
" The offset index of `I̅N̅T̅` pin for the associated GPIO device.\n" \
55+
" The offset index of `I̅N̅T̅` pin for the associated GPIO device.\n" \
5656
" If not specified, `SPI` interface will fall back to polling,\n" \
5757
" which is inefficient.\n" \
5858
" gpio-reset-dev[=gpio-device-path]\n" \
5959
" Specify a path to the Linux sysfs-exported GPIO device for the\n" \
60-
" `R̅E̅S̅` pin.\n" \
60+
" `R̅E̅S̅` pin.\n" \
6161
" gpio-reset-line[=line-offset]" \
62-
" The offset index of `R̅E̅S̅` pin for the associated GPIO device.\n" \
62+
" The offset index of `R̅E̅S̅` pin for the associated GPIO device.\n" \
6363
" spi-mode[=mode] Specify the SPI mode to use (0-3).\n" \
6464
" spi-speed[=hertz] Specify the SPI speed in hertz.\n" \
65-
" spi-cs-delay[=usec] Specify the delay after C̅S̅ assertion, in µsec.\n" \
66-
" spi-reset-delay[=ms] Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds.\n" \
65+
" spi-cs-delay[=usec] Specify the delay after C̅S̅ assertion, in µsec.\n" \
66+
" spi-reset-delay[=ms] Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds.\n" \
67+
" spi-latency[=usec] Specify the communication latency, in usec\n" \
6768
" spi-align-allowance[=n] Specify the maximum number of 0xFF bytes to clip from start of\n" \
6869
" MISO frame. Max value is 16.\n" \
6970
" spi-small-packet=[n] Specify the smallest packet we can receive in a single transaction.\n" \
@@ -83,6 +84,7 @@ const char *otSysGetRadioUrlHelpString(void)
8384
" uart-parity[=even|odd] Uart parity config, optional.\n" \
8485
" uart-stop[=number-of-bits] Uart stop bit, default is 1.\n" \
8586
" uart-baudrate[=baudrate] Uart baud rate, default is 115200.\n" \
87+
" uart-latency[=usec] Uart communication latency in usec, optional.\n" \
8688
" uart-flow-control Enable flow control, disabled by default.\n" \
8789
" uart-reset Reset connection after hard resetting RCP(USB CDC ACM).\n" \
8890
"\n"

0 commit comments

Comments
 (0)