Skip to content

Commit 137a7ed

Browse files
fg-cfhcarlescufi
authored andcommitted
drivers: ieee802154: nRF5: TX timestamp now refers to start of PHR
Based on the standard based definitions given in previous commits, the TX timestamp used for timed TX now refers to the start of PHR. As OT continues to calculate timestamps based on a "start of SHR" definition, the duration of the PHY specific SHR is added in the OT adaptation layer to make up for this OT quirk. Fixes: #59245 Signed-off-by: Florian Grandel <[email protected]>
1 parent 7db0184 commit 137a7ed

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,12 @@ static bool nrf5_tx_at(struct nrf5_802154_data *nrf5_radio, struct net_pkt *pkt,
527527
.extra_cca_attempts = max_extra_cca_attempts,
528528
#endif
529529
};
530-
uint64_t tx_at = net_ptp_time_to_ns(net_pkt_timestamp(pkt)) / NSEC_PER_USEC;
530+
531+
/* The timestamp points to the start of PHR but `nrf_802154_transmit_raw_at`
532+
* expects a timestamp pointing to start of SHR.
533+
*/
534+
uint64_t tx_at = nrf_802154_timestamp_phr_to_shr_convert(
535+
net_ptp_time_to_ns(net_pkt_timestamp(pkt)) / NSEC_PER_USEC);
531536

532537
return nrf_802154_transmit_raw_at(payload, tx_at, &metadata);
533538
}

include/zephyr/net/ieee802154_radio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C" {
5252
*/
5353
#define IEEE802154_PHY_SYMBOLS_PER_SECOND(symbol_period) (USEC_PER_SEC / symbol_period)
5454

55-
/* see section 19.2.4 */
55+
/* in bytes, see section 19.2.4 */
5656
#define IEEE802154_PHY_SUN_FSK_PHR_LEN 2
5757

5858
/* Default PHY PIB attribute aTurnaroundTime, in PHY symbols, see section 11.3, table 11-1. */

modules/openthread/platform/radio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
5858

5959
#define CHANNEL_COUNT OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX - OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN + 1
6060

61+
#define PHY_SHR_DURATION 160 /* duration of SHR in us */
62+
6163
enum pending_events {
6264
PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */
6365
PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */
@@ -395,7 +397,7 @@ void transmit_message(struct k_work *tx_job)
395397
(sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) {
396398
#if defined(CONFIG_NET_PKT_TXTIME)
397399
uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime +
398-
sTransmitFrame.mInfo.mTxInfo.mTxDelay;
400+
sTransmitFrame.mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION;
399401
struct net_ptp_time timestamp =
400402
ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at));
401403
net_pkt_set_timestamp(tx_pkt, &timestamp);

tests/subsys/openthread/radio_test.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ DEFINE_FFF_GLOBALS;
3030
#define FRAME_TYPE_MASK 0x07
3131
#define FRAME_TYPE_ACK 0x02
3232

33+
#define PHY_SHR_DURATION 160
34+
3335
K_SEM_DEFINE(ot_sem, 0, 1);
3436

3537
/**
@@ -293,10 +295,10 @@ ZTEST(openthread_radio, test_tx_test)
293295
get_time_mock_fake.return_val = (int64_t)UINT32_MAX * NSEC_PER_USEC + 1000;
294296
frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U;
295297
frm->mInfo.mTxInfo.mTxDelay = 5U;
296-
expected_target_time =
297-
get_time_mock_fake.return_val +
298-
(frm->mInfo.mTxInfo.mTxDelayBaseTime + frm->mInfo.mTxInfo.mTxDelay) *
299-
NSEC_PER_USEC;
298+
expected_target_time = get_time_mock_fake.return_val +
299+
(frm->mInfo.mTxInfo.mTxDelayBaseTime +
300+
frm->mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION) *
301+
NSEC_PER_USEC;
300302
}
301303

302304
/* ACKed frame */

0 commit comments

Comments
 (0)