Skip to content

Commit adf4e73

Browse files
ankunsaescolar
authored andcommitted
net: openthread: support Kconfig IEEE802154_SELECTIVE_TXCHANNEL
For transmit_message if the transmission is timed and underlying driver supports `IEEE802154_HW_SELECTIVE_TXCHANNEL` then use the selective txchannel feature for transmission. This does not change the current `channel` at the moment of call, the driver will transmit the message on the channel selected through `net_pkt_set_ieee802154_txchannel` then (after receiving an ACK if requested) it will return to the original channel. When Kconfig option IEEE802154_SELECTIVE_TXCHANNEL is turned on, the timed transmissions scheduled some time ahead on different channel will not abort ongoing reception until the exact moment of transmission comes. Signed-off-by: Andrzej Kuroś <[email protected]>
1 parent 30c449d commit adf4e73

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

modules/openthread/platform/radio.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,20 @@ void platformRadioInit(void)
377377
radio_api->configure(radio_dev, IEEE802154_CONFIG_EVENT_HANDLER, &cfg);
378378
}
379379

380+
static void radio_set_channel(uint16_t ch)
381+
{
382+
channel = ch;
383+
radio_api->set_channel(radio_dev, ch);
384+
}
385+
380386
void transmit_message(struct k_work *tx_job)
381387
{
382388
int tx_err;
383389

384390
ARG_UNUSED(tx_job);
385391

392+
enum ieee802154_hw_caps radio_caps = radio_api->get_capabilities(radio_dev);
393+
386394
/*
387395
* The payload is already in tx_payload->data,
388396
* but we need to set the length field
@@ -392,10 +400,7 @@ void transmit_message(struct k_work *tx_job)
392400
*/
393401
tx_payload->len = sTransmitFrame.mLength - FCS_SIZE;
394402

395-
channel = sTransmitFrame.mChannel;
396-
397-
radio_api->set_channel(radio_dev, channel);
398-
radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel));
403+
radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(sTransmitFrame.mChannel));
399404

400405
#if defined(CONFIG_OPENTHREAD_TIME_SYNC)
401406
if (sTransmitFrame.mInfo.mTxInfo.mIeInfo->mTimeIeOffset != 0) {
@@ -413,17 +418,27 @@ void transmit_message(struct k_work *tx_job)
413418
sTransmitFrame.mInfo.mTxInfo.mIsSecurityProcessed);
414419
net_pkt_set_ieee802154_mac_hdr_rdy(tx_pkt, sTransmitFrame.mInfo.mTxInfo.mIsHeaderUpdated);
415420

416-
if ((radio_api->get_capabilities(radio_dev) & IEEE802154_HW_TXTIME) &&
421+
if ((radio_caps & IEEE802154_HW_TXTIME) &&
417422
(sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) {
418423
#if defined(CONFIG_NET_PKT_TXTIME)
419424
uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime +
420425
sTransmitFrame.mInfo.mTxInfo.mTxDelay;
421426
net_pkt_set_timestamp_ns(tx_pkt, convert_32bit_us_wrapped_to_64bit_ns(tx_at));
427+
#endif
428+
#if defined(CONFIG_IEEE802154_SELECTIVE_TXCHANNEL)
429+
if (radio_caps & IEEE802154_HW_SELECTIVE_TXCHANNEL) {
430+
net_pkt_set_ieee802154_txchannel(tx_pkt, sTransmitFrame.mChannel);
431+
} else {
432+
radio_set_channel(sTransmitFrame.mChannel);
433+
}
434+
#else
435+
radio_set_channel(sTransmitFrame.mChannel);
422436
#endif
423437
tx_err =
424438
radio_api->tx(radio_dev, IEEE802154_TX_MODE_TXTIME_CCA, tx_pkt, tx_payload);
425439
} else if (sTransmitFrame.mInfo.mTxInfo.mCsmaCaEnabled) {
426-
if (radio_api->get_capabilities(radio_dev) & IEEE802154_HW_CSMA) {
440+
radio_set_channel(sTransmitFrame.mChannel);
441+
if (radio_caps & IEEE802154_HW_CSMA) {
427442
tx_err = radio_api->tx(radio_dev, IEEE802154_TX_MODE_CSMA_CA, tx_pkt,
428443
tx_payload);
429444
} else {
@@ -434,6 +449,7 @@ void transmit_message(struct k_work *tx_job)
434449
}
435450
}
436451
} else {
452+
radio_set_channel(sTransmitFrame.mChannel);
437453
tx_err = radio_api->tx(radio_dev, IEEE802154_TX_MODE_DIRECT, tx_pkt, tx_payload);
438454
}
439455

0 commit comments

Comments
 (0)