diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 6c2bd653b8..f8b15b9b86 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -527,7 +527,12 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt, .extra_cca_attempts = max_extra_cca_attempts, #endif }; - uint64_t tx_at = net_ptp_time_to_ns(net_pkt_timestamp(pkt)) / NSEC_PER_USEC; + + /* The timestamp points to the start of PHR but `nrf_802154_transmit_raw_at` + * expects a timestamp pointing to start of SHR. + */ + uint64_t tx_at = nrf_802154_timestamp_phr_to_shr_convert( + net_ptp_time_to_ns(net_pkt_timestamp(pkt)) / NSEC_PER_USEC); return nrf_802154_transmit_raw_at(payload, tx_at, &metadata); } diff --git a/include/zephyr/net/ieee802154_radio.h b/include/zephyr/net/ieee802154_radio.h index cc8ac4d20b..ae175ac8e8 100644 --- a/include/zephyr/net/ieee802154_radio.h +++ b/include/zephyr/net/ieee802154_radio.h @@ -52,7 +52,7 @@ extern "C" { */ #define IEEE802154_PHY_SYMBOLS_PER_SECOND(symbol_period) (USEC_PER_SEC / symbol_period) -/* see section 19.2.4 */ +/* in bytes, see section 19.2.4 */ #define IEEE802154_PHY_SUN_FSK_PHR_LEN 2 /* Default PHY PIB attribute aTurnaroundTime, in PHY symbols, see section 11.3, table 11-1. */ diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index c96c3c31ad..cc1ef4e835 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -58,6 +58,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL); #define CHANNEL_COUNT OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX - OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN + 1 +#define PHY_SHR_DURATION 160 /* duration of SHR in us */ + enum pending_events { PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */ PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */ @@ -395,7 +397,7 @@ void transmit_message(struct k_work *tx_job) (sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) { #if defined(CONFIG_NET_PKT_TXTIME) uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime + - sTransmitFrame.mInfo.mTxInfo.mTxDelay; + sTransmitFrame.mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION; struct net_ptp_time timestamp = ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at)); net_pkt_set_timestamp(tx_pkt, ×tamp); diff --git a/tests/subsys/openthread/radio_test.c b/tests/subsys/openthread/radio_test.c index 87a7013a0d..fb6c875503 100644 --- a/tests/subsys/openthread/radio_test.c +++ b/tests/subsys/openthread/radio_test.c @@ -30,6 +30,8 @@ DEFINE_FFF_GLOBALS; #define FRAME_TYPE_MASK 0x07 #define FRAME_TYPE_ACK 0x02 +#define PHY_SHR_DURATION 160 + K_SEM_DEFINE(ot_sem, 0, 1); /** @@ -293,10 +295,10 @@ ZTEST(openthread_radio, test_tx_test) get_time_mock_fake.return_val = (int64_t)UINT32_MAX * NSEC_PER_USEC + 1000; frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U; frm->mInfo.mTxInfo.mTxDelay = 5U; - expected_target_time = - get_time_mock_fake.return_val + - (frm->mInfo.mTxInfo.mTxDelayBaseTime + frm->mInfo.mTxInfo.mTxDelay) * - NSEC_PER_USEC; + expected_target_time = get_time_mock_fake.return_val + + (frm->mInfo.mTxInfo.mTxDelayBaseTime + + frm->mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION) * + NSEC_PER_USEC; } /* ACKed frame */