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 <fgrandel@code-for-humans.de>
This commit is contained in:
Florian Grandel 2023-07-13 16:37:55 +02:00 committed by Carles Cufí
parent 7db0184e1b
commit 137a7edd6e
4 changed files with 16 additions and 7 deletions

View file

@ -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, .extra_cca_attempts = max_extra_cca_attempts,
#endif #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); return nrf_802154_transmit_raw_at(payload, tx_at, &metadata);
} }

View file

@ -52,7 +52,7 @@ extern "C" {
*/ */
#define IEEE802154_PHY_SYMBOLS_PER_SECOND(symbol_period) (USEC_PER_SEC / symbol_period) #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 #define IEEE802154_PHY_SUN_FSK_PHR_LEN 2
/* Default PHY PIB attribute aTurnaroundTime, in PHY symbols, see section 11.3, table 11-1. */ /* Default PHY PIB attribute aTurnaroundTime, in PHY symbols, see section 11.3, table 11-1. */

View file

@ -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 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 { enum pending_events {
PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */ PENDING_EVENT_FRAME_TO_SEND, /* There is a tx frame to send */
PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */ 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)) { (sTransmitFrame.mInfo.mTxInfo.mTxDelay != 0)) {
#if defined(CONFIG_NET_PKT_TXTIME) #if defined(CONFIG_NET_PKT_TXTIME)
uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime + uint32_t tx_at = sTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime +
sTransmitFrame.mInfo.mTxInfo.mTxDelay; sTransmitFrame.mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION;
struct net_ptp_time timestamp = struct net_ptp_time timestamp =
ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at)); ns_to_net_ptp_time(convert_32bit_us_wrapped_to_64bit_ns(tx_at));
net_pkt_set_timestamp(tx_pkt, &timestamp); net_pkt_set_timestamp(tx_pkt, &timestamp);

View file

@ -30,6 +30,8 @@ DEFINE_FFF_GLOBALS;
#define FRAME_TYPE_MASK 0x07 #define FRAME_TYPE_MASK 0x07
#define FRAME_TYPE_ACK 0x02 #define FRAME_TYPE_ACK 0x02
#define PHY_SHR_DURATION 160
K_SEM_DEFINE(ot_sem, 0, 1); 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; get_time_mock_fake.return_val = (int64_t)UINT32_MAX * NSEC_PER_USEC + 1000;
frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U; frm->mInfo.mTxInfo.mTxDelayBaseTime = 3U;
frm->mInfo.mTxInfo.mTxDelay = 5U; frm->mInfo.mTxInfo.mTxDelay = 5U;
expected_target_time = expected_target_time = get_time_mock_fake.return_val +
get_time_mock_fake.return_val + (frm->mInfo.mTxInfo.mTxDelayBaseTime +
(frm->mInfo.mTxInfo.mTxDelayBaseTime + frm->mInfo.mTxInfo.mTxDelay) * frm->mInfo.mTxInfo.mTxDelay + PHY_SHR_DURATION) *
NSEC_PER_USEC; NSEC_PER_USEC;
} }
/* ACKed frame */ /* ACKed frame */