Skip to content

Commit b36ed5f

Browse files
WIP
1 parent e10a925 commit b36ed5f

18 files changed

+193
-4
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

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

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

11411158
/**

src/cli/cli.cpp

+15
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 {
@@ -5940,6 +5942,7 @@ template <> otError Interpreter::Process<Cmd("rcp")>(Arg aArgs[])
59405942
{
59415943
otError error = OT_ERROR_NONE;
59425944
const char *version = otPlatRadioGetVersionString(GetInstancePtr());
5945+
const uint32_t latency = otPlatRadioGetBusLatency(GetInstancePtr());
59435946

59445947
VerifyOrExit(version != otGetVersionString(), error = OT_ERROR_NOT_IMPLEMENTED);
59455948
/**
@@ -5957,6 +5960,18 @@ template <> otError Interpreter::Process<Cmd("rcp")>(Arg aArgs[])
59575960
OutputLine("%s", version);
59585961
}
59595962

5963+
else if (aArgs[0] == "latency")
5964+
{
5965+
if (aArgs[1].IsEmpty())
5966+
{
5967+
OutputLine("%lu", latency);
5968+
}
5969+
else
5970+
{
5971+
error = ProcessSet(aArgs + 1, otPlatRadioSetBusLatency);
5972+
}
5973+
}
5974+
59605975
else
59615976
{
59625977
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
@@ -68,16 +68,21 @@ CslTxScheduler::CslTxScheduler(Instance &aInstance)
6868
, mFrameContext()
6969
, mCallbacks(aInstance)
7070
{
71-
InitFrameRequestAhead();
71+
UpdateFrameRequestAhead();
7272
}
7373

74-
void CslTxScheduler::InitFrameRequestAhead(void)
74+
void CslTxScheduler::UpdateFrameRequestAhead(void)
7575
{
7676
uint32_t busSpeedHz = otPlatRadioGetBusSpeed(&GetInstance());
77+
uint32_t busLatency = otPlatRadioGetBusLatency(&GetInstance());
78+
7779
// longest frame on bus is 127 bytes with some metadata, use 150 bytes for bus Tx time estimation
7880
uint32_t busTxTimeUs = ((busSpeedHz == 0) ? 0 : (150 * 8 * 1000000 + busSpeedHz - 1) / busSpeedHz);
7981

80-
mCslFrameRequestAheadUs = OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs;
82+
mCslFrameRequestAheadUs = OPENTHREAD_CONFIG_MAC_CSL_REQUEST_AHEAD_US + busTxTimeUs + busLatency;
83+
LogInfo("Declared Bus TX Time: %d, Latency: %d. Calculated CSL Frame Request Ahead: %d",
84+
busTxTimeUs, busLatency, mCslFrameRequestAheadUs);
85+
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+
* Returns the bus speed 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

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const char *otSysGetRadioUrlHelpString(void)
8383
" uart-parity[=even|odd] Uart parity config, optional.\n" \
8484
" uart-stop[=number-of-bits] Uart stop bit, default is 1.\n" \
8585
" uart-baudrate[=baudrate] Uart baud rate, default is 115200.\n" \
86+
" uart-latency[=usec] Uart communication latency in usec, optional.\n" \
8687
" uart-flow-control Enable flow control, disabled by default.\n" \
8788
" uart-reset Reset connection after hard resetting RCP(USB CDC ACM).\n" \
8889
"\n"

src/posix/platform/vendor_interface.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ class VendorInterface : public ot::Spinel::SpinelInterface
136136
*/
137137
uint32_t GetBusSpeed(void) const;
138138

139+
/**
140+
* Returns the bus latency between the host and the radio.
141+
*
142+
* @returns Bus speed in bits/second.
143+
*
144+
*/
145+
uint32_t GetBusLatency(void) const;
146+
147+
/**
148+
* Sets the bus latency between the host and the radio.
149+
*
150+
* @returns Bus speed in bits/second.
151+
*
152+
*/
153+
void SetBusLatency(uint32_t aLatency);
154+
139155
/**
140156
* Hardware resets the RCP.
141157
*
@@ -166,6 +182,9 @@ class VendorInterface : public ot::Spinel::SpinelInterface
166182
static const char *kInterfaceName = OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_URL_PROTOCOL_NAME;
167183
return (strncmp(aInterfaceName, kInterfaceName, strlen(kInterfaceName)) == 0);
168184
}
185+
186+
private:
187+
uint32_t mLatency;
169188
};
170189

171190
} // namespace Posix

src/posix/platform/vendor_interface_example.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class VendorInterfaceImpl
6868
static OT_DEFINE_ALIGNED_VAR(sVendorInterfaceImplRaw, sizeof(VendorInterfaceImpl), uint64_t);
6969

7070
VendorInterface::VendorInterface(const Url::Url &aRadioUrl)
71+
: mLatency(0)
7172
{
7273
new (&sVendorInterfaceImplRaw) VendorInterfaceImpl(aRadioUrl);
7374
OT_UNUSED_VARIABLE(sVendorInterfaceImplRaw);
@@ -93,6 +94,10 @@ void VendorInterface::Deinit(void)
9394

9495
uint32_t VendorInterface::GetBusSpeed(void) const { return 1000000; }
9596

97+
uint32_t VendorInterface::GetBusLatency(void) const { return mLatency; }
98+
99+
void VendorInterface::SetBusLatency(uint32_t aLatency) { mLatency = aLatency; }
100+
96101
otError VendorInterface::HardwareReset(void)
97102
{
98103
// TODO: Implement vendor code here.

tools/spi-hdlc-adapter/spi-hdlc-adapter.c

+1
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ static void print_help(void)
14171417
" --spi-speed[=hertz] .......... Specify the SPI speed in hertz.\n"
14181418
" --spi-cs-delay[=usec] ........ Specify the delay after C̅S̅ assertion, in µsec\n"
14191419
" --spi-reset-delay[=ms] ....... Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds\n"
1420+
" --spi-latency[=usec] ......... Specify the communication latency, in usec\n"
14201421
" --spi-align-allowance[=n] .... Specify the maximum number of 0xFF bytes to\n"
14211422
" clip from start of MISO frame. Max value is 16.\n"
14221423
" --spi-small-packet=[n] ....... Specify the smallest packet we can receive\n"

0 commit comments

Comments
 (0)