Skip to content

openthread: Add Kconfigs for packet TX time and carrier functions #90737

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

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions modules/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,19 @@ config OPENTHREAD_INTERFACE_EARLY_UP
Otherwise, OpenThread interface will be marked operational UP only
after the device joins a Thread network.

config OPENTHREAD_PLATFORM_PKT_TXTIME
bool
default y if NET_PKT_TXTIME
help
Enable packet TX time support. This is needed for when the application
wants to set the exact time when the packet should be sent.

config OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS
bool
default y if OPENTHREAD_DIAG && IEEE802154_CARRIER_FUNCTIONS
help
Enable support for functions such as modulated carrier and continuous carrier.

menu "OpenThread stack features"
rsource "Kconfig.features"
endmenu
Expand Down
2 changes: 1 addition & 1 deletion modules/openthread/platform/alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ K_TIMER_DEFINE(ot_us_timer, ot_timer_us_fired, NULL);

void platformAlarmInit(void)
{
#if defined(CONFIG_NET_PKT_TXTIME)
#if defined(CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME)
time_offset_us =
(int32_t)((int64_t)otPlatAlarmMicroGetNow() - (uint32_t)otPlatRadioGetNow(NULL));
time_offset_ms = time_offset_us / 1000;
Expand Down
15 changes: 9 additions & 6 deletions modules/openthread/platform/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ static uint32_t sTxPeriod = 1;
static int32_t sTxCount;
static int32_t sTxRequestedCount = 1;

#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

static otError processTransmit(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);

static otError parse_long(char *aArgs, long *aValue)
Expand Down Expand Up @@ -72,11 +75,11 @@ void otPlatDiagSetOutputCallback(otInstance *aInstance,

otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
{
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
if (strcmp(aArgs[0], "modcarrier") == 0) {
return startModCarrier(aInstance, aArgsLength - 1, aArgs + 1);
}
#endif
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

if (strcmp(aArgs[0], "transmit") == 0) {
return processTransmit(aInstance, aArgsLength - 1, aArgs + 1);
Expand Down Expand Up @@ -128,7 +131,7 @@ void otPlatDiagRadioReceived(otInstance *aInstance,
ARG_UNUSED(aError);
}

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
{
if (sTransmitMode != DIAG_TRANSMIT_MODE_IDLE &&
Expand All @@ -144,7 +147,7 @@ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable)

return platformRadioTransmitCarrier(aInstance, aEnable);
}
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

/*
* To enable gpio diag commands, in Devicetree create `openthread` node in `/options/` path
Expand Down Expand Up @@ -317,7 +320,7 @@ otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode)
* DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), diag_gpios)
*/

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)

static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
{
Expand Down Expand Up @@ -346,7 +349,7 @@ static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char
return platformRadioTransmitModulatedCarrier(aInstance, enable, data);
}

#endif
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

void otPlatDiagAlarmCallback(otInstance *aInstance)
{
Expand Down
8 changes: 4 additions & 4 deletions modules/openthread/platform/platform-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ uint16_t platformRadioChannelGet(otInstance *aInstance);
void platformRadioChannelSet(uint8_t aChannel);
#endif /* CONFIG_OPENTHREAD_DIAG */

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
/**
* Start/stop continuous carrier wave transmission.
*/
otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable);
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
/**
* Start/stop modulated carrier wave transmission.
*/
otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable,
const uint8_t *aData);
#endif
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

/**
* This function initializes the random number service used by OpenThread.
Expand Down
14 changes: 7 additions & 7 deletions modules/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void handle_radio_event(const struct device *dev, enum ieee802154_event evt,
}
}

#if defined(CONFIG_NET_PKT_TXTIME) || defined(CONFIG_OPENTHREAD_CSL_RECEIVER)
#if defined(CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME) || defined(CONFIG_OPENTHREAD_CSL_RECEIVER)
/**
* @brief Convert 32-bit (potentially wrapped) OpenThread microsecond timestamps
* to 64-bit Zephyr network subsystem nanosecond timestamps.
Expand Down Expand Up @@ -320,7 +320,7 @@ static net_time_t convert_32bit_us_wrapped_to_64bit_ns(uint32_t target_time_us_w
__ASSERT_NO_MSG(result <= INT64_MAX / NSEC_PER_USEC);
return (net_time_t)result * NSEC_PER_USEC;
}
#endif /* CONFIG_NET_PKT_TXTIME || CONFIG_OPENTHREAD_CSL_RECEIVER */
#endif /* CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME || CONFIG_OPENTHREAD_CSL_RECEIVER */

static void dataInit(void)
{
Expand Down Expand Up @@ -416,7 +416,7 @@ void transmit_message(struct k_work *tx_job)

if ((radio_caps & IEEE802154_HW_TXTIME) &&
(sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) {
#if defined(CONFIG_NET_PKT_TXTIME)
#if defined(CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME)
uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime +
sTransmitFrame.mInfo.mTxInfo.mTxDelay;
net_pkt_set_timestamp_ns(tx_pkt, convert_32bit_us_wrapped_to_64bit_ns(tx_at));
Expand Down Expand Up @@ -833,7 +833,7 @@ otError otPlatRadioReceiveAt(otInstance *aInstance, uint8_t aChannel,
}
#endif

#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
#if defined(CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS)
otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
{
if (radio_api->continuous_carrier == NULL) {
Expand Down Expand Up @@ -884,7 +884,7 @@ otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnabl
return OT_ERROR_NONE;
}

#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
#endif /* CONFIG_OPENTHREAD_PLATFORM_CARRIER_FUNCTIONS */

otRadioState otPlatRadioGetState(otInstance *aInstance)
{
Expand Down Expand Up @@ -998,7 +998,7 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
}
#endif

#if defined(CONFIG_NET_PKT_TXTIME)
#if defined(CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME)
if (radio_caps & IEEE802154_HW_TXTIME) {
caps |= OT_RADIO_CAPS_TRANSMIT_TIMING;
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ uint64_t otPlatTimeGet(void)
}
}

#if defined(CONFIG_NET_PKT_TXTIME)
#if defined(CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME)
uint64_t otPlatRadioGetNow(otInstance *aInstance)
{
ARG_UNUSED(aInstance);
Expand Down
3 changes: 3 additions & 0 deletions tests/subsys/openthread/radio_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

/* OpenThread not enabled here */
#define CONFIG_OPENTHREAD_PLATFORM_LOG_LEVEL LOG_LEVEL_DBG
#ifdef CONFIG_NET_PKT_TXTIME
#define CONFIG_OPENTHREAD_PLATFORM_PKT_TXTIME 1
#endif

#define CONFIG_OPENTHREAD_THREAD_PRIORITY 5
#define OT_WORKER_PRIORITY K_PRIO_COOP(CONFIG_OPENTHREAD_THREAD_PRIORITY)
Expand Down