Skip to content

nrf_802154: rev 8058d3003bbcef71b1b3b052c6a11a7e9903c0ae #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions drivers/nrf_802154/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
add_library(nrf-802154-driver-interface INTERFACE)
add_library(nrf-802154-serialization-interface INTERFACE)

if (CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION)
target_compile_definitions(zephyr-802154-interface
INTERFACE
NRF_802154_CCAIDLE_TO_TXEN_EXTRA_TIME_US=${CONFIG_NRF_802154_CCAIDLE_TO_TXEN_EXTRA_TIME_US}
)
endif()

add_subdirectory(common)

add_subdirectory(driver)
add_subdirectory(sl)

add_subdirectory(serialization)

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/internal/CMakeLists.txt)
add_subdirectory(internal)
endif ()
39 changes: 37 additions & 2 deletions drivers/nrf_802154/common/include/nrf_802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ bool nrf_802154_receive(void);
* If the requested reception time is in the past, the function returns false and does not
* schedule reception.
*
* A scheduled reception can be cancelled by a call to @ref nrf_802154_receive_at_cancel.
* The reception ends after the configured timeout has elapsed. This event is notified to the
* higher layer through the @ref nrf_802154_receive_failed notification with
* @ref NRF_802154_RX_ERROR_DELAYED_TIMEOUT status code.
*
* A scheduled reception can be cancelled by a call to @ref nrf_802154_receive_at_cancel or
* @ref nrf_802154_receive_at_scheduled_cancel.
*
* @note The identifier @p id must be unique. It must not have the same value as identifiers
* of other delayed timeslots active at the moment, so that it can be mapped unambiguously
Expand All @@ -427,7 +432,8 @@ bool nrf_802154_receive(void);
* @param[in] channel Radio channel on which the frame is to be received.
* @param[in] id Identifier of the scheduled reception window. If the reception has been
* scheduled successfully, the value of this parameter can be used in
* @ref nrf_802154_receive_at_cancel to cancel it.
* @ref nrf_802154_receive_at_cancel or
* @ref nrf_802154_receive_at_scheduled_cancel to cancel it.
*
* @retval true The reception procedure was scheduled.
* @retval false The driver could not schedule the reception procedure.
Expand All @@ -453,6 +459,35 @@ bool nrf_802154_receive_at(uint64_t rx_time,
*/
bool nrf_802154_receive_at_cancel(uint32_t id);

/**
* @brief Cancels a delayed reception scheduled by a call to @ref nrf_802154_receive_at.
*
* If the receive window has been scheduled but has not started yet, this function prevents
* entering the receive window. If the receive window has been scheduled and has already started,
* the receive window is not affected and will continue until its scheduled timeout.
*
* The function also returns success when no window with given ID is scheduled and is not currently
* ongoing.
*
* @note This function differs from @ref nrf_802154_receive_at_cancel in two aspects:
* 1. This function can only cancel receive windows that are scheduled, but haven't started yet.
* If the receive window has already started, the cancel will end with failure and the
* receive window will last for the planned duration, ending with
* @ref nrf_802154_receive_failed notification with @ref NRF_802154_RX_ERROR_DELAYED_TIMEOUT
* status.
* 2. If there are no scheduled and ongoing receive windows matching the given ID,
* the function ends with a success.
*
* @param[in] id Identifier of the delayed reception window to be cancelled. If the provided
* value does not refer to any scheduled or active receive window, the function
* returns true.
*
* @retval true The delayed reception was scheduled and successfully cancelled or the
* receive window was not scheduled at all.
* @retval false The scheduled window is currently ongoing.
*/
bool nrf_802154_receive_at_scheduled_cancel(uint32_t id);

/**
* @brief Changes the radio state to @ref RADIO_STATE_TX.
*
Expand Down
17 changes: 17 additions & 0 deletions drivers/nrf_802154/common/include/nrf_802154_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ extern "C" {
#define NRF_802154_CCA_CORR_LIMIT_DEFAULT 0x02
#endif

/**
* @def NRF_802154_CCAIDLE_TO_TXEN_EXTRA_TIME_US
*
* Additional time in microseconds that delays triggering of @c TXEN after the
* @c CCAIDLE event occurred. Default value for most use-cases is @c 0,
* In this scenario, the short between the @c CCAIDLE event and the
* @c TXEN task is used. If this value is non-zero, the short is not used.
* The triggering of @c TXEN occurs through (D)PPI and TIMER.
* A non-zero value may be necessary to ensure enough switching time for
* use with some Front-End Modules.
*
* This option is supported for the nRF53 Series and the nRF54L Series only.
*/
#ifndef NRF_802154_CCAIDLE_TO_TXEN_EXTRA_TIME_US
#define NRF_802154_CCAIDLE_TO_TXEN_EXTRA_TIME_US 0U
#endif

/**
* @def NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ static uint8_t security_key_id_set(const nrf_802154_frame_parser_data_t * p_fram
{
const uint8_t * p_frame_key_id = nrf_802154_frame_parser_key_id_get(p_frame_data);
uint8_t * p_ack_key_id = (uint8_t *)nrf_802154_frame_parser_key_id_get(p_ack_data);
uint8_t key_id_size = key_id_size_get(nrf_802154_frame_parser_sec_ctrl_key_id_mode_get(
p_ack_data));
uint8_t key_id_size =
key_id_size_get(nrf_802154_frame_parser_sec_ctrl_key_id_mode_get(p_ack_data));

if ((p_ack_key_id != NULL) && (p_frame_key_id != NULL))
{
Expand Down Expand Up @@ -416,35 +416,6 @@ static void ie_header_set(const uint8_t * p_ie_data,
#endif
}

static uint8_t ie_header_terminate(const uint8_t * p_ie_data,
uint8_t ie_data_len,
nrf_802154_frame_parser_data_t * p_ack_data)
{
if (p_ie_data == NULL)
{
// No IEs to terminate.
return 0U;
}

if ((nrf_802154_frame_parser_security_enabled_bit_is_set(p_ack_data) == false) ||
(nrf_802154_frame_parser_sec_ctrl_sec_lvl_get(p_ack_data) == SECURITY_LEVEL_NONE))
{
// This code assumes that neither regular frame payload nor Payload IEs can be set by the
// driver. Therefore without security, the Ack has no payload, so termination is not necessary.
return 0U;
}

uint8_t * p_ack_ie = (uint8_t *)p_ack_data->p_frame + p_ack_data->helper.aux_sec_hdr_end_offset;
uint8_t ie_hdr_term[IE_HEADER_SIZE];

NRF_802154_ASSERT(p_ack_ie != NULL);

host_16_to_little((IE_HT2) << IE_HEADER_ELEMENT_ID_OFFSET, ie_hdr_term);

memcpy(p_ack_ie + ie_data_len, ie_hdr_term, sizeof(ie_hdr_term));
return sizeof(ie_hdr_term);
}

/***************************************************************************************************
* @section Authentication and encryption transformation
**************************************************************************************************/
Expand Down Expand Up @@ -543,8 +514,8 @@ static void ie_process(const nrf_802154_frame_parser_data_t * p_frame_data)
ie_header_set(mp_ie_data, m_ie_data_len, &m_ack_data);
m_ack[PHR_OFFSET] += m_ie_data_len;

// Terminate the IE header if needed.
m_ack[PHR_OFFSET] += ie_header_terminate(mp_ie_data, m_ie_data_len, &m_ack_data) + FCS_SIZE;
// Add space for the FCS field.
m_ack[PHR_OFFSET] += FCS_SIZE;

bool result = nrf_802154_frame_parser_valid_data_extend(&m_ack_data,
m_ack[PHR_OFFSET] + PHR_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,10 @@ bool nrf_802154_delayed_trx_transmit(uint8_t * p

p_dly_tx_data->tx.p_data = p_data;
p_dly_tx_data->tx.params.frame_props = p_metadata->frame_props;
(void)nrf_802154_tx_power_convert_metadata_to_tx_power_split(p_metadata->channel,
p_metadata->tx_power,
&p_dly_tx_data->tx.params.tx_power);
(void)nrf_802154_tx_power_convert_metadata_to_tx_power_split(
p_metadata->channel,
p_metadata->tx_power,
&p_dly_tx_data->tx.params.tx_power);
p_dly_tx_data->tx.params.cca = p_metadata->cca;
p_dly_tx_data->tx.params.immediate = true;
p_dly_tx_data->tx.params.extra_cca_attempts = p_metadata->extra_cca_attempts;
Expand Down Expand Up @@ -918,6 +919,36 @@ bool nrf_802154_delayed_trx_receive_cancel(uint32_t id)
return stopped;
}

bool nrf_802154_delayed_trx_receive_scheduled_cancel(uint32_t id)
{
dly_op_data_t * p_dly_op_data = dly_rx_data_by_id_search(id);

if (p_dly_op_data == NULL)
{
// Delayed receive window with provided ID could not be found.
return true;
}

bool result = nrf_802154_rsch_delayed_timeslot_cancel(id, false);

if (!result)
{
result =
nrf_802154_sl_atomic_load_u8((uint8_t *)&p_dly_op_data->state) ==
DELAYED_TRX_OP_STATE_STOPPED;
}

if (result)
{
p_dly_op_data->id = NRF_802154_RESERVED_INVALID_ID;

nrf_802154_sl_atomic_store_u8((uint8_t *)&p_dly_op_data->state,
DELAYED_TRX_OP_STATE_STOPPED);
}

return result;
}

bool nrf_802154_delayed_trx_abort(nrf_802154_term_t term_lvl, req_originator_t req_orig)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_HIGH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ bool nrf_802154_delayed_trx_receive(uint64_t rx_time,
*/
bool nrf_802154_delayed_trx_receive_cancel(uint32_t id);

/**
* @brief Cancels a scheduled reception scheduled by a call to @ref nrf_802154_delayed_trx_receive.
*
* If the receive window is currently ongoing, it will not be affected and a timeout event will
* be notified at scheduled time.
*
* @param[in] id Identifier of the delayed reception window to be cancelled. If the provided
* value does not refer to any scheduled or active receive window, the function
* returns true.
*
* @retval true Successfully cancelled a scheduled transmission or no window
* with given ID is scheduled.
* @retval false The receive window is currently ongoing.
*/
bool nrf_802154_delayed_trx_receive_scheduled_cancel(uint32_t id);

/**
* @brief Aborts an ongoing delayed reception procedure.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ static bool sec_ctrl_parse(nrf_802154_frame_parser_data_t * p_parser_data)
if (nrf_802154_frame_parser_security_enabled_bit_is_set(p_parser_data) == false)
{
p_parser_data->helper.aux_sec_hdr_end_offset = offset;
p_parser_data->helper.mic_size = 0;
return true;
}

Expand Down Expand Up @@ -515,9 +516,10 @@ bool nrf_802154_frame_parser_data_init(const uint8_t * p_frame,
return parse_state_advance(p_parser_data, requested_parse_level);
}

bool nrf_802154_frame_parser_valid_data_extend(nrf_802154_frame_parser_data_t * p_parser_data,
uint8_t valid_data_len,
nrf_802154_frame_parser_level_t requested_parse_level)
bool nrf_802154_frame_parser_valid_data_extend(
nrf_802154_frame_parser_data_t * p_parser_data,
uint8_t valid_data_len,
nrf_802154_frame_parser_level_t requested_parse_level)
{
if (valid_data_len > p_parser_data->valid_data_len)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ bool nrf_802154_frame_parser_data_init(const uint8_t * p_frame,
* @retval true The parsing succeeded and requested parse level was achieved.
* @retval false The parsing failed or requested parse level could not be achieved.
*/
bool nrf_802154_frame_parser_valid_data_extend(nrf_802154_frame_parser_data_t * p_parser_data,
uint8_t valid_data_len,
nrf_802154_frame_parser_level_t requested_parse_level);
bool nrf_802154_frame_parser_valid_data_extend(
nrf_802154_frame_parser_data_t * p_parser_data,
uint8_t valid_data_len,
nrf_802154_frame_parser_level_t requested_parse_level);

/**
* @brief Gets current parse level of the provided parser data.
Expand Down Expand Up @@ -1015,6 +1016,19 @@ static inline const uint8_t * nrf_802154_frame_parser_mfr_get(
return &p_parser_data->p_frame[offset];
}

/**
* @brief Gets the length of the MIC field.
*
* @param[in] p_parser_data Pointer to a frame parser data.
*
* @returns Length of the MIC field.
*/
static inline uint8_t nrf_802154_frame_parser_mic_size_get(
const nrf_802154_frame_parser_data_t * p_parser_data)
{
return p_parser_data->helper.mic_size;
}

/**
* @brief Gets the length of the MAC payload.
*
Expand All @@ -1025,8 +1039,9 @@ static inline const uint8_t * nrf_802154_frame_parser_mfr_get(
static inline uint8_t nrf_802154_frame_parser_mac_payload_length_get(
const nrf_802154_frame_parser_data_t * p_parser_data)
{
uint8_t mic_len = nrf_802154_frame_parser_mic_size_get(p_parser_data);
uint8_t payload_start = nrf_802154_frame_parser_mac_payload_offset_get(p_parser_data);
uint8_t payload_end = nrf_802154_frame_parser_mfr_offset_get(p_parser_data);
uint8_t payload_end = nrf_802154_frame_parser_mfr_offset_get(p_parser_data) - mic_len;

return payload_end - payload_start;
}
Expand All @@ -1052,19 +1067,6 @@ static inline uint8_t nrf_802154_frame_parser_mac_header_length_get(
return mhr_end - mhr_start;
}

/**
* @brief Gets the length of the MIC field.
*
* @param[in] p_parser_data Pointer to a frame parser data.
*
* @returns Length of the MIC field.
*/
static inline uint8_t nrf_802154_frame_parser_mic_size_get(
const nrf_802154_frame_parser_data_t * p_parser_data)
{
return p_parser_data->helper.mic_size;
}

/**
* @brief Gets the end offset of the destination addressing section.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ static void cst_ie_write_reset(void)
#endif // NRF_802154_DELAYED_TRX_ENABLED

static uint8_t * mp_lm_rssi_addr; ///< Cached Link Metrics information element RSSI field address
static uint8_t * mp_lm_margin_addr; ///< Cached Link Metrics information element link margin field address
static uint8_t * mp_lm_lqi_addr; ///< Cached Link Metrics information element LQI field address
static uint8_t * mp_lm_margin_addr; ///< Cached Link Metrics information element link margin field address
static uint8_t * mp_lm_lqi_addr; ///< Cached Link Metrics information element LQI field address

static uint8_t rssi_scale(int8_t rssi)
{
Expand Down
12 changes: 12 additions & 0 deletions drivers/nrf_802154/driver/src/nrf_802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,18 @@ bool nrf_802154_receive_at_cancel(uint32_t id)
return result;
}

bool nrf_802154_receive_at_scheduled_cancel(uint32_t id)
{
bool result;

nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);

result = nrf_802154_request_receive_at_scheduled_cancel(id);

nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}

#endif // NRF_802154_DELAYED_TRX_ENABLED

bool nrf_802154_energy_detection(uint32_t time_us)
Expand Down
5 changes: 5 additions & 0 deletions drivers/nrf_802154/driver/src/nrf_802154_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,11 @@ void nrf_802154_trx_receive_frame_received(void)
#if (NRF_802154_FRAME_TIMESTAMP_ENABLED)
uint64_t ts = timer_coord_timestamp_get();

if (ts != NRF_802154_NO_TIMESTAMP)
{
ts -= RX_PHYEND_EVENT_LATENCY_US;
}

nrf_802154_stat_timestamp_write(last_rx_end_timestamp, ts);
#endif

Expand Down
4 changes: 2 additions & 2 deletions drivers/nrf_802154/driver/src/nrf_802154_critical_section.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@

#define NESTED_CRITICAL_SECTION_ALLOWED_PRIORITY_NONE (-1)

static volatile uint8_t m_nested_critical_section_counter; ///< Counter of nested critical sections
static volatile int8_t m_nested_critical_section_allowed_priority; ///< Indicator if nested critical sections are currently allowed
static volatile uint8_t m_nested_critical_section_counter; ///< Counter of nested critical sections
static volatile int8_t m_nested_critical_section_allowed_priority; ///< Indicator if nested critical sections are currently allowed

/***************************************************************************************************
* @section Critical sections management
Expand Down
Loading