Skip to content

Commit 79315a8

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]> (cherry picked from commit 1ed975b)
1 parent 2031889 commit 79315a8

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
@@ -92,8 +92,7 @@ LOG_MODULE_REGISTER(esb, CONFIG_ESB_LOG_LEVEL);
9292
NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK | NRF_RADIO_SHORT_DISABLED_RSSISTOP_MASK)
9393
#else
9494
/* Devices without RSSISTOP task will stop RSSI measurement after specific period. */
95-
#define RADIO_SHORTS_FAST_SWITCHING_NO_RSSISTOP \
96-
(NRF_RADIO_SHORT_READY_START_MASK | NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
95+
#define RADIO_SHORTS_FAST_SWITCHING_NO_RSSISTOP (NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
9796
#define RADIO_SHORTS_NO_FAST_SWITCHING_NO_RSSISTOP \
9897
(NRF_RADIO_SHORT_READY_START_MASK | ESB_SHORT_DISABLE_MASK | \
9998
NRF_RADIO_SHORT_ADDRESS_RSSISTART_MASK)
@@ -113,6 +112,14 @@ LOG_MODULE_REGISTER(esb, CONFIG_ESB_LOG_LEVEL);
113112
NRF_RADIO_SHORT_READY_START_MASK)
114113
#endif /* !defined(CONFIG_SOC_SERIES_NRF54LX) */
115114

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

@@ -1281,7 +1288,8 @@ static void start_tx_transaction(void)
12811288
memcpy(pdu->data, current_payload->data, current_payload->length);
12821289

12831290
if (fast_switching) {
1284-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1291+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1292+
NRF_RADIO_SHORT_TXREADY_START_MASK));
12851293
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
12861294
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
12871295
} else {
@@ -1309,7 +1317,8 @@ static void start_tx_transaction(void)
13091317
/* Handling ack if noack is set to false or if selective auto ack is turned off */
13101318
if (ack) {
13111319
if (fast_switching) {
1312-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1320+
nrf_radio_shorts_set(NRF_RADIO,
1321+
(radio_shorts_common | NRF_RADIO_SHORT_TXREADY_START_MASK));
13131322
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
13141323
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
13151324
} else {
@@ -1343,8 +1352,9 @@ static void start_tx_transaction(void)
13431352
(esb_state == ESB_STATE_PTX_TX));
13441353
esb_state = ESB_STATE_PTX_TX;
13451354
} else {
1346-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common |
1347-
ESB_SHORT_DISABLE_MASK);
1355+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1356+
NRF_RADIO_SHORT_READY_START_MASK |
1357+
ESB_SHORT_DISABLE_MASK));
13481358

13491359
on_radio_disabled = on_radio_disabled_tx_noack;
13501360
esb_state = ESB_STATE_PTX_TX;
@@ -1483,8 +1493,9 @@ static void on_radio_disabled_tx(void)
14831493
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
14841494
if (fast_switching) {
14851495
nrf_radio_int_disable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
1486-
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | ESB_SHORT_DISABLE_MASK));
1487-
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
1496+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | ESB_SHORT_DISABLE_MASK |
1497+
NRF_RADIO_SHORT_RXREADY_START_MASK));
1498+
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_START);
14881499
}
14891500
on_radio_disabled = on_radio_disabled_tx_wait_for_ack;
14901501
esb_state = ESB_STATE_PTX_RX_ACK;
@@ -1555,7 +1566,8 @@ static void on_radio_disabled_tx_wait_for_ack(void)
15551566
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_READY);
15561567

15571568
if (fast_switching) {
1558-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1569+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1570+
NRF_RADIO_SHORT_TXREADY_START_MASK));
15591571
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
15601572
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
15611573
} else {
@@ -1625,7 +1637,8 @@ static void start_rx_listening(void)
16251637
on_radio_disabled = NULL;
16261638
} else {
16271639
if (fast_switching) {
1628-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1640+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1641+
NRF_RADIO_SHORT_READY_START_MASK));
16291642
nrf_radio_event_clear(NRF_RADIO, ESB_RADIO_EVENT_END);
16301643
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
16311644
} else {
@@ -1679,7 +1692,8 @@ static void clear_events_restart_rx(void)
16791692

16801693
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED);
16811694

1682-
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
1695+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_READY_START_MASK |
1696+
NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
16831697

16841698
esb_ppi_for_txrx_set(true, false);
16851699
esb_fem_for_rx_set();
@@ -1787,7 +1801,8 @@ static void on_radio_disabled_rx(void)
17871801
nrf_radio_packetptr_set(NRF_RADIO, tx_pdu);
17881802

17891803
if (fast_switching) {
1790-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1804+
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
1805+
NRF_RADIO_SHORT_READY_START_MASK));
17911806
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN);
17921807
} else {
17931808
nrf_radio_shorts_set(NRF_RADIO,
@@ -1821,7 +1836,8 @@ static void on_radio_disabled_rx_send_ack(void)
18211836

18221837
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
18231838
if (fast_switching) {
1824-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1839+
nrf_radio_shorts_set(NRF_RADIO,
1840+
(radio_shorts_common | NRF_RADIO_SHORT_READY_START_MASK));
18251841
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
18261842
} else {
18271843
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)