Skip to content

Commit 1ed975b

Browse files
Szynkaarlubos
authored andcommitted
esb: fix fast switching causing retransmissions
When both PTX and PRX where have fast switching enabled, PRX was sending ACK packet when PTX was still in RX ramp up. Now PTX completes RX ramp up earlier by shorting PHYEND to RXEN over DPPI, and radio interrupt triggers START instead of RXEN. Signed-off-by: Szymon Antkowiak <[email protected]>
1 parent 1ddde35 commit 1ed975b

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

subsys/esb/esb.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ LOG_MODULE_REGISTER(esb, CONFIG_ESB_LOG_LEVEL);
9090
NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK | NRF_RADIO_SHORT_DISABLED_RSSISTOP_MASK)
9191
#else
9292
/* Devices without RSSISTOP task will stop RSSI measurement after specific period. */
93-
#define RADIO_SHORTS_FAST_SWITCHING_NO_RSSISTOP \
94-
(NRF_RADIO_SHORT_READY_START_MASK | NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
93+
#define RADIO_SHORTS_FAST_SWITCHING_NO_RSSISTOP (NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
9594
#define RADIO_SHORTS_NO_FAST_SWITCHING_NO_RSSISTOP \
9695
(NRF_RADIO_SHORT_READY_START_MASK | ESB_SHORT_DISABLE_MASK | \
9796
NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
@@ -111,6 +110,14 @@ LOG_MODULE_REGISTER(esb, CONFIG_ESB_LOG_LEVEL);
111110
NRF_RADIO_SHORT_READY_START_MASK)
112111
#endif /* !defined(CONFIG_SOC_SERIES_NRF54LX) */
113112

113+
/* Define empty shorts for nRF52 devices. These shorts are used only for fast switching. */
114+
#if !defined(RADIO_SHORTS_TXREADY_START_Msk)
115+
#define NRF_RADIO_SHORT_TXREADY_START_MASK 0
116+
#endif
117+
#if !defined(RADIO_SHORTS_RXREADY_START_Msk)
118+
#define NRF_RADIO_SHORT_RXREADY_START_MASK 0
119+
#endif
120+
114121
/* Flag for changing radio channel. */
115122
#define RF_CHANNEL_UPDATE_FLAG 0
116123

@@ -1182,7 +1189,8 @@ static void start_tx_transaction(void)
11821189
memcpy(pdu->data, current_payload->data, current_payload->length);
11831190

11841191
if (fast_switching) {
1185-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1192+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1193+
NRF_RADIO_SHORT_TXREADY_START_MASK));
11861194
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
11871195
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
11881196
} else {
@@ -1210,7 +1218,8 @@ static void start_tx_transaction(void)
12101218
/* Handling ack if noack is set to false or if selective auto ack is turned off */
12111219
if (ack) {
12121220
if (fast_switching) {
1213-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1221+
nrf_radio_shorts_set(NRF_RADIO,
1222+
(radio_shorts_common | NRF_RADIO_SHORT_TXREADY_START_MASK));
12141223
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
12151224
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
12161225
} else {
@@ -1244,8 +1253,9 @@ static void start_tx_transaction(void)
12441253
(esb_state == ESB_STATE_PTX_TX));
12451254
esb_state = ESB_STATE_PTX_TX;
12461255
} else {
1247-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common |
1248-
ESB_SHORT_DISABLE_MASK);
1256+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1257+
NRF_RADIO_SHORT_READY_START_MASK |
1258+
ESB_SHORT_DISABLE_MASK));
12491259

12501260
on_radio_disabled = on_radio_disabled_tx_noack;
12511261
esb_state = ESB_STATE_PTX_TX;
@@ -1384,8 +1394,9 @@ static void on_radio_disabled_tx(void)
13841394
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
13851395
if (fast_switching) {
13861396
nrf_radio_int_disable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
1387-
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | ESB_SHORT_DISABLE_MASK));
1388-
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
1397+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | ESB_SHORT_DISABLE_MASK |
1398+
NRF_RADIO_SHORT_RXREADY_START_MASK));
1399+
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_START);
13891400
}
13901401
on_radio_disabled = on_radio_disabled_tx_wait_for_ack;
13911402
esb_state = ESB_STATE_PTX_RX_ACK;
@@ -1456,7 +1467,8 @@ static void on_radio_disabled_tx_wait_for_ack(void)
14561467
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_READY);
14571468

14581469
if (fast_switching) {
1459-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1470+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1471+
NRF_RADIO_SHORT_TXREADY_START_MASK));
14601472
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
14611473
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
14621474
} else {
@@ -1526,7 +1538,8 @@ static void start_rx_listening(void)
15261538
on_radio_disabled = NULL;
15271539
} else {
15281540
if (fast_switching) {
1529-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1541+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1542+
NRF_RADIO_SHORT_READY_START_MASK));
15301543
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
15311544
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
15321545
} else {
@@ -1580,7 +1593,8 @@ static void clear_events_restart_rx(void)
15801593

15811594
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED);
15821595

1583-
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
1596+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_READY_START_MASK |
1597+
NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
15841598

15851599
esb_ppi_for_txrx_set(true, false);
15861600
esb_fem_for_rx_set();
@@ -1688,7 +1702,8 @@ static void on_radio_disabled_rx(void)
16881702
nrf_radio_packetptr_set(NRF_RADIO, tx_pdu);
16891703

16901704
if (fast_switching) {
1691-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1705+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1706+
NRF_RADIO_SHORT_READY_START_MASK));
16921707
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN);
16931708
} else {
16941709
nrf_radio_shorts_set(NRF_RADIO,
@@ -1722,7 +1737,8 @@ static void on_radio_disabled_rx_send_ack(void)
17221737

17231738
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
17241739
if (fast_switching) {
1725-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1740+
nrf_radio_shorts_set(NRF_RADIO,
1741+
(radio_shorts_common | NRF_RADIO_SHORT_READY_START_MASK));
17261742
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
17271743
} else {
17281744
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |

subsys/esb/esb_dppi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start)
5353
egu_timer_start);
5454
}
5555

56+
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING) && timer_start && !rx) {
57+
nrf_radio_subscribe_set(NRF_RADIO, NRF_RADIO_TASK_RXEN, disabled_phy_end_egu);
58+
}
59+
5660
channels_mask = (BIT(egu_timer_start) |
5761
BIT(egu_ramp_up));
5862

@@ -82,6 +86,10 @@ void esb_ppi_for_txrx_clear(bool rx, bool timer_start)
8286
if (timer_start) {
8387
nrf_timer_subscribe_clear(ESB_NRF_TIMER_INSTANCE, NRF_TIMER_TASK_START);
8488
}
89+
90+
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING) && timer_start && !rx) {
91+
nrf_radio_subscribe_clear(NRF_RADIO, NRF_RADIO_TASK_RXEN);
92+
}
8593
}
8694

8795
void esb_ppi_for_fem_set(void)

0 commit comments

Comments
 (0)