Skip to content

Commit

Permalink
esb: Fix fast switching configuration when ACK is disabled
Browse files Browse the repository at this point in the history
Update the fast_switching configuration to handle scenarios where
ACK (acknowledgment) is disabled.

Ref: NCSDK-28905

Signed-off-by: Marcin Jelinski <[email protected]>
  • Loading branch information
maje-emb authored and rlubos committed Sep 20, 2024
1 parent 0abbcf4 commit 3e120af
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
20 changes: 11 additions & 9 deletions subsys/esb/esb.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ static volatile uint32_t last_tx_attempts;
static volatile uint32_t wait_for_ack_timeout_us;

static uint32_t radio_shorts_common = RADIO_SHORTS_COMMON;
static const bool fast_switching = IS_ENABLED(CONFIG_ESB_FAST_SWITCHING);

static const mpsl_fem_event_t rx_event = {
.type = MPSL_FEM_EVENT_TYPE_TIMER,
Expand Down Expand Up @@ -1086,7 +1087,8 @@ static void start_tx_transaction(void)
(esb_state == ESB_STATE_PTX_TX));
esb_state = ESB_STATE_PTX_TX;
} else {
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common |
ESB_SHORT_DISABLE_MASK);

on_radio_disabled = on_radio_disabled_tx_noack;
esb_state = ESB_STATE_PTX_TX;
Expand Down Expand Up @@ -1121,7 +1123,7 @@ static void start_tx_transaction(void)
if (is_tx_idle) {
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_START);
} else {
esb_ppi_for_txrx_set(false, ack);
esb_ppi_for_txrx_set(false, ack, fast_switching && ack);
esb_fem_for_tx_set(ack);

radio_start();
Expand Down Expand Up @@ -1158,7 +1160,7 @@ static void on_radio_end_tx_noack(void)
static void on_radio_disabled_tx_noack(void)
{
esb_fem_pa_reset();
esb_ppi_for_txrx_clear(false, false);
esb_ppi_for_txrx_clear(false, false, false);

interrupt_flags |= INT_TX_SUCCESS_MSK;
tx_fifo_remove_last();
Expand All @@ -1174,7 +1176,7 @@ static void on_radio_disabled_tx_noack(void)

static void on_radio_disabled_tx(void)
{
esb_ppi_for_txrx_clear(false, true);
esb_ppi_for_txrx_clear(false, true, fast_switching);
/* The timer was triggered on radio disabled event so we can clear PPI connections here. */
esb_ppi_for_fem_clear();
esb_fem_for_rx_ack();
Expand Down Expand Up @@ -1310,7 +1312,7 @@ static void on_radio_disabled_tx_wait_for_ack(void)
esb_ppi_for_retransmission_clear();

/* Start radio here. */
esb_ppi_for_txrx_set(false, true);
esb_ppi_for_txrx_set(false, true, fast_switching);
esb_fem_for_tx_set(true);

radio_start();
Expand All @@ -1322,7 +1324,7 @@ static void on_radio_disabled_tx_wait_for_ack(void)
static void clear_events_restart_rx(void)
{
esb_fem_lna_reset();
esb_ppi_for_txrx_clear(true, false);
esb_ppi_for_txrx_clear(true, false, fast_switching);

nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);

Expand All @@ -1341,7 +1343,7 @@ static void clear_events_restart_rx(void)

nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_DISABLED_TXEN_MASK));

esb_ppi_for_txrx_set(true, false);
esb_ppi_for_txrx_set(true, false, fast_switching);
esb_fem_for_rx_set();

radio_start();
Expand Down Expand Up @@ -1960,7 +1962,7 @@ int esb_start_rx(void)
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_PAYLOAD);
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED);

esb_ppi_for_txrx_set(true, false);
esb_ppi_for_txrx_set(true, false, fast_switching);
esb_fem_for_rx_set();

radio_start();
Expand All @@ -1974,7 +1976,7 @@ int esb_stop_rx(void)
return -EINVAL;
}

esb_ppi_for_txrx_clear(true, false);
esb_ppi_for_txrx_clear(true, false, fast_switching);
esb_fem_reset();

nrf_radio_shorts_disable(NRF_RADIO, 0xFFFFFFFF);
Expand Down
8 changes: 4 additions & 4 deletions subsys/esb/esb_dppi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static uint8_t radio_end_timer_start;

static nrf_dppi_channel_group_t ramp_up_dppi_group;

void esb_ppi_for_txrx_set(bool rx, bool timer_start)
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
{
uint32_t channels_mask;

Expand All @@ -48,7 +48,7 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start)

nrf_egu_subscribe_set(ESB_EGU, ESB_EGU_TASK, disabled_phy_end_egu);

if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
if (fast_switching) {
nrf_radio_subscribe_set(NRF_RADIO, rx ? NRF_RADIO_TASK_TXEN : NRF_RADIO_TASK_RXEN,
disabled_phy_end_egu);
}
Expand All @@ -64,7 +64,7 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start)
nrf_dppi_channels_enable(ESB_DPPIC, channels_mask);
}

void esb_ppi_for_txrx_clear(bool rx, bool timer_start)
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching)
{
uint32_t channels_mask;

Expand All @@ -84,7 +84,7 @@ void esb_ppi_for_txrx_clear(bool rx, bool timer_start)

nrf_dppi_channels_remove_from_group(ESB_DPPIC, BIT(egu_ramp_up), ramp_up_dppi_group);

if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
if (fast_switching) {
nrf_radio_subscribe_clear(NRF_RADIO, rx ? NRF_RADIO_TASK_TXEN :
NRF_RADIO_TASK_RXEN);
}
Expand Down
10 changes: 7 additions & 3 deletions subsys/esb/esb_ppi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ void esb_ppi_for_fem_clear(void)
nrf_ppi_channel_endpoint_setup(NRF_PPI, egu_timer_start, 0, 0);
}

void esb_ppi_for_txrx_set(bool rx, bool timer_start)
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
{
ARG_UNUSED(fast_switching);

uint32_t channels_mask;
uint32_t egu_event = nrf_egu_event_address_get(ESB_EGU, ESB_EGU_EVENT);
uint32_t egu_task = nrf_egu_task_address_get(ESB_EGU, ESB_EGU_TASK);
Expand Down Expand Up @@ -73,11 +75,13 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start)
nrf_ppi_channels_enable(NRF_PPI, channels_mask);
}

void esb_ppi_for_txrx_clear(bool rx, bool timer_start)
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching)
{
ARG_UNUSED(fast_switching);
ARG_UNUSED(rx);

uint32_t channels_mask = (BIT(egu_ramp_up) | BIT(disabled_egu));

ARG_UNUSED(rx);

if (timer_start) {
channels_mask |= BIT(egu_timer_start);
Expand Down
7 changes: 5 additions & 2 deletions subsys/esb/esb_ppi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ extern "C" {
*
* @param[in] rx Radio Rx mode, otherwise Tx mode.
* @param[in] timer_start Indicates whether the timer is to be started on the EGU event.
* @param[in] fast_switch Indicates whether to configure fast switching.
*/
void esb_ppi_for_txrx_set(bool rx, bool timer_start);
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching);

/** @brief Clear PPI/DPPI connection for Tx or Rx radio operations
*
* @param[in] rx Radio Rx mode, otherwise Tx mode.
* @param[in] timer_start Clear timer connections if the timer was set using
* the @ref esb_ppi_for_txrx_set function.
* @param[in] fast_switching Clear fast switching configuration if the fast switching was set using
* the @ref esb_ppi_for_txrx_set function.
*/
void esb_ppi_for_txrx_clear(bool rx, bool timer_start);
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching);

/** @brief Configure PPIs/DPPIs for the external front-end module. The EGU event will be connected
* to the TIMER_START event. As a result, the front-end module ramp-up will be scheduled\
Expand Down

0 comments on commit 3e120af

Please sign in to comment.