Skip to content

Commit 63f2092

Browse files
e-rknordicjm
authored andcommitted
nrf_802154: rev 3a74e8b8e6399903215ef4ee1e8de8950d4e31e9
This commit updates revision of the nrf_802154 component. Signed-off-by: Rafal Kuznia <[email protected]>
1 parent d4b4d0f commit 63f2092

21 files changed

+425
-80
lines changed

nrf_802154/common/include/nrf_802154.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ bool nrf_802154_receive_at_scheduled_cancel(uint32_t id);
514514
* @note This function is implemented in zero-copy fashion. It passes the given buffer pointer to
515515
* the RADIO peripheral.
516516
*
517+
* @note Setting @p tx_timestamp_encode to true is only allowed if
518+
* @ref NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED is enabled.
519+
* If this condition is not met, any attempt to transmit a frame will fail unconditionally.
520+
*
517521
* In the transmit state, the radio transmits a given frame. If requested, it waits for
518522
* an ACK frame. Depending on @ref NRF_802154_ACK_TIMEOUT_ENABLED, the radio driver automatically
519523
* stops waiting for an ACK frame or waits indefinitely for an ACK frame. If it is configured to
@@ -542,6 +546,7 @@ bool nrf_802154_receive_at_scheduled_cancel(uint32_t id);
542546
* ----------------|-----------------------------------------------------
543547
* @c frame_props | @ref NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT
544548
* @c cca | @c true
549+
* @c tx_timestamp_encode | @c false
545550
*
546551
* @retval true The transmission procedure was scheduled.
547552
* @retval false The driver could not schedule the transmission procedure.
@@ -602,6 +607,10 @@ bool nrf_802154_transmit_raw(uint8_t * p_data,
602607
* A successfully scheduled transmission can be cancelled by a call
603608
* to @ref nrf_802154_transmit_at_cancel.
604609
*
610+
 * @note Setting @p tx_timestamp_encode to true is only allowed if
611+
* @ref NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED is enabled.
612+
* If this condition is not met, any attempt to transmit a frame will fail unconditionally.
613+
*
605614
* @param[in] p_data Pointer to the array with data to transmit. The first byte must contain
606615
* the frame length (including FCS). The following bytes contain data.
607616
* The CRC is computed automatically by the radio hardware. Therefore,
@@ -616,6 +625,7 @@ bool nrf_802154_transmit_raw(uint8_t * p_data,
616625
* @c channel | As returned by @ref nrf_802154_channel_get
617626
* @c tx_power | As set with @ref nrf_802154_tx_power_set
618627
* @c extra_cca_attempts | @c 0
628+
* @c tx_timestamp_encode | @c 0
619629
*
620630
* @retval true The transmission procedure was scheduled.
621631
* @retval false The driver could not schedule the transmission procedure.
@@ -1063,13 +1073,17 @@ void nrf_802154_cca_cfg_get(nrf_802154_cca_cfg_t * p_cca_cfg);
10631073
* the CSMA-CA procedure does not time out waiting for an ACK frame if a frame
10641074
* with the ACK request bit set was transmitted.
10651075
* @note This function is available if @ref NRF_802154_CSMA_CA_ENABLED is enabled.
1076+
* @note Setting @p tx_timestamp_encode to true is only allowed if
1077+
* @ref NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED is enabled.
1078+
* If this condition is not met, any attempt to transmit a frame will fail unconditionally.
10661079
*
10671080
* @param[in] p_data Pointer to the frame to transmit. See also @ref nrf_802154_transmit_raw.
10681081
* @param[in] p_metadata Pointer to metadata structure. Contains detailed properties of data
10691082
* to transmit. If @c NULL following metadata are used:
10701083
* Field | Value
10711084
* ----------------|-----------------------------------------------------
10721085
* @c frame_props | @ref NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT
1086+
* @c tx_timestamp_encode | false
10731087
*
10741088
* @retval true The chain of CSMA-CA and transmission procedure was scheduled.
10751089
* @retval false The driver could not schedule the procedure chain.

nrf_802154/common/include/nrf_802154_config.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,22 @@ extern "C" {
595595
#define NRF_802154_REQUEST_IMPL NRF_802154_REQUEST_IMPL_SWI
596596
#endif
597597

598+
/**
599+
* @}
600+
* @defgroup nrf_802154_tx_timestamp_provider Transmit Timestamp configuration
601+
* @{
602+
*/
603+
604+
/**
605+
* @def NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
606+
*
607+
* Enables the Transmit Timestamp Provider module. The module encodes the transmission
608+
* start timestamp in a frame's payload upon request.
609+
*/
610+
#ifndef NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
611+
#define NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED 0
612+
#endif
613+
598614
/** @} */
599615

600616
/**

nrf_802154/common/include/nrf_802154_types.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ typedef uint8_t nrf_802154_state_t;
8181
*/
8282
typedef uint8_t nrf_802154_tx_error_t;
8383

84-
#define NRF_802154_TX_ERROR_NONE 0x00 // !< There is no transmit error.
85-
#define NRF_802154_TX_ERROR_BUSY_CHANNEL 0x01 // !< CCA reported busy channel before the transmission.
86-
#define NRF_802154_TX_ERROR_INVALID_ACK 0x02 // !< Received ACK frame is other than expected.
87-
#define NRF_802154_TX_ERROR_NO_MEM 0x03 // !< No receive buffer is available to receive an ACK.
88-
#define NRF_802154_TX_ERROR_TIMESLOT_ENDED 0x04 // !< Radio timeslot ended during the transmission procedure.
89-
#define NRF_802154_TX_ERROR_NO_ACK 0x05 // !< ACK frame was not received during the timeout period.
90-
#define NRF_802154_TX_ERROR_ABORTED 0x06 // !< Procedure was aborted by another operation.
91-
#define NRF_802154_TX_ERROR_TIMESLOT_DENIED 0x07 // !< Transmission did not start due to a denied timeslot request.
92-
#define NRF_802154_TX_ERROR_KEY_ID_INVALID 0x08 // !< Transmission did not start due to invalid key ID in frame's security header.
93-
#define NRF_802154_TX_ERROR_FRAME_COUNTER_ERROR 0x09 // !< Transmission did not start due a frame counter error.
84+
#define NRF_802154_TX_ERROR_NONE 0x00 // !< There is no transmit error.
85+
#define NRF_802154_TX_ERROR_BUSY_CHANNEL 0x01 // !< CCA reported busy channel before the transmission.
86+
#define NRF_802154_TX_ERROR_INVALID_ACK 0x02 // !< Received ACK frame is other than expected.
87+
#define NRF_802154_TX_ERROR_NO_MEM 0x03 // !< No receive buffer is available to receive an ACK.
88+
#define NRF_802154_TX_ERROR_TIMESLOT_ENDED 0x04 // !< Radio timeslot ended during the transmission procedure.
89+
#define NRF_802154_TX_ERROR_NO_ACK 0x05 // !< ACK frame was not received during the timeout period.
90+
#define NRF_802154_TX_ERROR_ABORTED 0x06 // !< Procedure was aborted by another operation.
91+
#define NRF_802154_TX_ERROR_TIMESLOT_DENIED 0x07 // !< Transmission did not start due to a denied timeslot request.
92+
#define NRF_802154_TX_ERROR_KEY_ID_INVALID 0x08 // !< Transmission did not start due to invalid key ID in frame's security header.
93+
#define NRF_802154_TX_ERROR_FRAME_COUNTER_ERROR 0x09 // !< Transmission did not start due a frame counter error.
94+
#define NRF_802154_TX_ERROR_TIMESTAMP_ENCODING_ERROR 0x0A // !< Timestamp could not been encoded in the transmission process.
9495

9596
/**
9697
* @brief Possible errors during the frame reception.
@@ -442,6 +443,7 @@ typedef struct
442443
bool cca; // !< If the driver is to perform a CCA procedure before transmission.
443444
nrf_802154_tx_power_metadata_t tx_power; // !< Information about the TX power to be used.
444445
nrf_802154_tx_channel_metadata_t tx_channel; // !< Information about the TX channel to be used.
446+
bool tx_timestamp_encode; // !< True if the transmit timestamp shall be encoded in the payload.
445447
} nrf_802154_transmit_metadata_t;
446448

447449
/**
@@ -454,6 +456,7 @@ typedef struct
454456
uint8_t channel; // !< Radio channel on which the frame is to be transmitted.
455457
nrf_802154_tx_power_metadata_t tx_power; // !< Information about the TX power to be used.
456458
uint8_t extra_cca_attempts; // !< Maximum number of additional CCA attempts that can be performed if the first attempt returns busy channel. Ignored if @ref cca equals @c false.
459+
bool tx_timestamp_encode; // !< True if the transmit timestamp shall be encoded in the payload.
457460
} nrf_802154_transmit_at_metadata_t;
458461

459462
/**
@@ -464,6 +467,7 @@ typedef struct
464467
nrf_802154_transmitted_frame_props_t frame_props; // !< Properties of the frame to be transmitted.
465468
nrf_802154_tx_power_metadata_t tx_power; // !< Information about the TX power to be used.
466469
nrf_802154_tx_channel_metadata_t tx_channel; // !< Information about the TX channel to be used.
470+
bool tx_timestamp_encode; // !< True if the transmit timestamp shall be encoded in the payload.
467471
} nrf_802154_transmit_csma_ca_metadata_t;
468472

469473
/**

nrf_802154/doc/CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Added
3333
Use this API during clock platform initialization.
3434
If the latency is not set, the driver assumes a default worst-case startup latency of 1650 us.
3535
* When the FEM power amplifier is configured, the Errata 56 for nRF54L15 is automatically applied. (KRKNWK-20409)
36+
* Added the new flag to :c:type:`nrf_802154_transmitted_frame_props_t` that allows to request encoding the transmit timestamp in the transmitted payload.
37+
The feature can be enabled with the :c:macro:`NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED` configuration macro. (KRKNWK-20426)
3638

3739
Removed
3840
=======

nrf_802154/driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ target_sources(nrf-802154-driver
7878
src/mac_features/nrf_802154_security_pib_ram.c
7979
src/mac_features/nrf_802154_security_writer.c
8080
src/mac_features/nrf_802154_precise_ack_timeout.c
81+
src/mac_features/nrf_802154_tx_timestamp_provider.c
8182
src/mac_features/ack_generator/nrf_802154_ack_data.c
8283
src/mac_features/ack_generator/nrf_802154_ack_generator.c
8384
src/mac_features/ack_generator/nrf_802154_enh_ack_generator.c

nrf_802154/driver/src/mac_features/nrf_802154_csma_ca.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ static uint8_t * mp_data; ///< Pointer to a buff
7979
static nrf_802154_transmitted_frame_props_t m_data_props; ///< Structure containing detailed properties of data in buffer.
8080
static nrf_802154_fal_tx_power_split_t m_tx_power; ///< Power to be used when transmitting the frame split into components.
8181
static uint8_t m_tx_channel; ///< Channel to be used to transmit the current frame.
82-
static csma_ca_state_t m_state; ///< The current state of the CSMA-CA procedure.
82+
#if NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
83+
static bool m_tx_timestamp_encode; ///< Tx timestamp request flag for the current transmission attempt.
84+
#endif
85+
static csma_ca_state_t m_state; ///< The current state of the CSMA-CA procedure.
8386

8487
/**
8588
* @brief Perform appropriate actions for busy channel conditions.
@@ -198,6 +201,11 @@ static void frame_transmit(rsch_dly_ts_id_t dly_ts_id)
198201
.cca = true,
199202
.immediate = NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT ? false : true,
200203
.extra_cca_attempts = 0,
204+
#if NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
205+
.tx_timestamp_encode = m_tx_timestamp_encode,
206+
#else
207+
.tx_timestamp_encode = false,
208+
#endif
201209
};
202210

203211
if (!nrf_802154_request_transmit(NRF_802154_TERM_NONE,
@@ -372,6 +380,9 @@ bool nrf_802154_csma_ca_start(uint8_t * p_d
372380
m_nb = 0;
373381
m_be = nrf_802154_pib_csmaca_min_be_get();
374382
m_tx_channel = channel;
383+
#if NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
384+
m_tx_timestamp_encode = p_metadata->tx_timestamp_encode;
385+
#endif
375386
(void)nrf_802154_tx_power_convert_metadata_to_tx_power_split(channel,
376387
p_metadata->tx_power,
377388
&m_tx_power);
@@ -427,7 +438,7 @@ bool nrf_802154_csma_ca_tx_failed_hook(uint8_t * p_frame, nrf_802154_tx_error_t
427438
// Below errors mean a failure occurred during the frame processing and the frame cannot be
428439
// transmitted unless a higher layer takes appropriate actions, hence the CSMA-CA procedure
429440
// shall be stopped.
430-
441+
case NRF_802154_TX_ERROR_TIMESTAMP_ENCODING_ERROR:
431442
case NRF_802154_TX_ERROR_KEY_ID_INVALID:
432443
/* Fallthrough. */
433444
case NRF_802154_TX_ERROR_FRAME_COUNTER_ERROR:

nrf_802154/driver/src/mac_features/nrf_802154_delayed_trx.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,12 @@ bool nrf_802154_delayed_trx_transmit(uint8_t * p
802802
p_metadata->channel,
803803
p_metadata->tx_power,
804804
&p_dly_tx_data->tx.params.tx_power);
805-
p_dly_tx_data->tx.params.cca = p_metadata->cca;
806-
p_dly_tx_data->tx.params.immediate = true;
807-
p_dly_tx_data->tx.params.extra_cca_attempts = p_metadata->extra_cca_attempts;
808-
p_dly_tx_data->tx.params.channel = p_metadata->channel;
809-
p_dly_tx_data->id = NRF_802154_RESERVED_DTX_ID;
805+
p_dly_tx_data->tx.params.cca = p_metadata->cca;
806+
p_dly_tx_data->tx.params.immediate = true;
807+
p_dly_tx_data->tx.params.extra_cca_attempts = p_metadata->extra_cca_attempts;
808+
p_dly_tx_data->tx.params.channel = p_metadata->channel;
809+
p_dly_tx_data->tx.params.tx_timestamp_encode = p_metadata->tx_timestamp_encode;
810+
p_dly_tx_data->id = NRF_802154_RESERVED_DTX_ID;
810811

811812
rsch_dly_ts_param_t dly_ts_param =
812813
{
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2025, Nordic Semiconductor ASA
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this
11+
* list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18+
* contributors may be used to endorse or promote products derived from this
19+
* software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*
33+
*/
34+
35+
/**
36+
* @file
37+
* This file implements the transmit timestamp provider for the 802.15.4 driver.
38+
*
39+
*/
40+
41+
#include "mac_features/nrf_802154_tx_timestamp_provider.h"
42+
43+
#include "mac_features/nrf_802154_frame_parser.h"
44+
#include "nrf_802154_utils_byteorder.h"
45+
#include "nrf_802154_sl_timer.h"
46+
47+
#if NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED
48+
49+
static uint64_t m_tx_timestamp_us; ///< Cached transmit timestamp.
50+
static uint8_t * mp_tx_timestamp_addr; ///< Cached tx timestamp placeholder address.
51+
52+
bool nrf_802154_tx_timestamp_provider_tx_setup(
53+
uint8_t * p_frame,
54+
nrf_802154_transmit_params_t * p_params,
55+
nrf_802154_transmit_failed_notification_t notify_function)
56+
{
57+
nrf_802154_frame_parser_data_t frame_data;
58+
bool result = false;
59+
60+
m_tx_timestamp_us = 0;
61+
mp_tx_timestamp_addr = NULL;
62+
63+
if (p_params->tx_timestamp_encode == false)
64+
{
65+
// There is nothing to do.
66+
return true;
67+
}
68+
69+
do
70+
{
71+
if (p_params->frame_props.is_secured)
72+
{
73+
result = false;
74+
break;
75+
}
76+
77+
result = nrf_802154_frame_parser_data_init(p_frame,
78+
p_frame[PHR_OFFSET] +
79+
PHR_SIZE,
80+
PARSE_LEVEL_FULL,
81+
&frame_data);
82+
83+
if (result == false)
84+
{
85+
break;
86+
}
87+
88+
if (nrf_802154_frame_parser_frame_type_get(&frame_data) != FRAME_TYPE_DATA)
89+
{
90+
result = false;
91+
break;
92+
}
93+
94+
if (nrf_802154_frame_parser_mac_payload_get(&frame_data) == NULL)
95+
{
96+
result = false;
97+
break;
98+
}
99+
100+
uint8_t payload_len = nrf_802154_frame_parser_mac_payload_length_get(&frame_data);
101+
102+
if (payload_len < NRF_802154_TX_TIMESTAMP_PROVIDER_TIMESTAMP_SIZE)
103+
{
104+
result = false;
105+
break;
106+
}
107+
108+
mp_tx_timestamp_addr = (uint8_t *)(nrf_802154_frame_parser_mac_payload_get(&frame_data) +
109+
payload_len -
110+
NRF_802154_TX_TIMESTAMP_PROVIDER_TIMESTAMP_SIZE);
111+
}
112+
while (0);
113+
114+
if (result == false)
115+
{
116+
nrf_802154_transmit_done_metadata_t metadata = {};
117+
118+
metadata.frame_props = p_params->frame_props;
119+
notify_function(p_frame, NRF_802154_TX_ERROR_TIMESTAMP_ENCODING_ERROR, &metadata);
120+
}
121+
122+
return result;
123+
}
124+
125+
bool nrf_802154_tx_timestamp_provider_tx_started_hook(uint8_t * p_frame)
126+
{
127+
NRF_802154_ASSERT(m_tx_timestamp_us == 0);
128+
129+
// Verify that the setup phase has been completed.
130+
if (mp_tx_timestamp_addr == NULL)
131+
{
132+
return true;
133+
}
134+
/* This function is executed in the handler of RADIO.ADDRESS event. According to the IPS,
135+
* in 802.15.4 transmit sequence RADIO.FRAMESTART event is triggered after the SHR is
136+
* transmitted (nRF52840 PS v1.7 -- 6.20.12.6 Transmit sequence). However, RADIO.ADDRESS
137+
* event is also triggered in 802.15.4 transmit sequence with a constant 32us offset.
138+
* This handler is therefore expected to execute 32us before the SHR transmission ends.
139+
*
140+
* This function executes approximately 32us before the first bit of PHR.
141+
* The calculation takes it into account by adding 32us to the current time.
142+
*/
143+
m_tx_timestamp_us = nrf_802154_sl_timer_current_time_get() + 32;
144+
host_64_to_big(m_tx_timestamp_us, mp_tx_timestamp_addr);
145+
146+
mp_tx_timestamp_addr = NULL;
147+
148+
return true;
149+
}
150+
151+
#endif // NRF_802154_TX_TIMESTAMP_PROVIDER_ENABLED

0 commit comments

Comments
 (0)