Skip to content

Commit f59ca21

Browse files
maje-embrlubos
authored andcommitted
esb: Fix radio mode switching in fast_switching mode
Manual switching between radio TX/RX and RX/TX modes in fast_switching mode instead of using DPPI. In some cases, linking the RADIO_PHYEND event to the RADIO_TASK_TXEN/RXEN task caused the radio to start transmitting or receiving before the radio was configured and the appropriate buffers were set. Ref: NCSDK-30467 Signed-off-by: Marcin Jelinski <[email protected]>
1 parent f76220a commit f59ca21

File tree

4 files changed

+34
-51
lines changed

4 files changed

+34
-51
lines changed

subsys/esb/esb.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ static void start_tx_transaction(void)
10641064

10651065
memcpy(pdu->data, current_payload->data, current_payload->length);
10661066

1067-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1067+
if (fast_switching) {
10681068
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
10691069
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
10701070
} else {
@@ -1093,7 +1093,7 @@ static void start_tx_transaction(void)
10931093
* selective auto ack is turned off
10941094
*/
10951095
if (ack) {
1096-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1096+
if (fast_switching) {
10971097
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
10981098
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
10991099
} else {
@@ -1163,7 +1163,7 @@ static void start_tx_transaction(void)
11631163
if (is_tx_idle) {
11641164
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_START);
11651165
} else {
1166-
esb_ppi_for_txrx_set(false, ack, fast_switching && ack);
1166+
esb_ppi_for_txrx_set(false, ack);
11671167
esb_fem_for_tx_set(ack);
11681168

11691169
radio_start();
@@ -1200,7 +1200,7 @@ static void on_radio_end_tx_noack(void)
12001200
static void on_radio_disabled_tx_noack(void)
12011201
{
12021202
esb_fem_pa_reset();
1203-
esb_ppi_for_txrx_clear(false, false, false);
1203+
esb_ppi_for_txrx_clear(false, false);
12041204

12051205
interrupt_flags |= INT_TX_SUCCESS_MSK;
12061206
tx_fifo_remove_last();
@@ -1216,7 +1216,7 @@ static void on_radio_disabled_tx_noack(void)
12161216

12171217
static void on_radio_disabled_tx(void)
12181218
{
1219-
esb_ppi_for_txrx_clear(false, true, fast_switching);
1219+
esb_ppi_for_txrx_clear(false, true);
12201220
/* The timer was triggered on radio disabled event so we can clear PPI connections here. */
12211221
esb_ppi_for_fem_clear();
12221222
esb_fem_for_rx_ack();
@@ -1255,6 +1255,9 @@ static void on_radio_disabled_tx(void)
12551255
}
12561256

12571257
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
1258+
if (fast_switching) {
1259+
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
1260+
}
12581261
on_radio_disabled = on_radio_disabled_tx_wait_for_ack;
12591262
esb_state = ESB_STATE_PTX_RX_ACK;
12601263
}
@@ -1317,7 +1320,7 @@ static void on_radio_disabled_tx_wait_for_ack(void)
13171320
* be entered again as soon as the system timer reaches
13181321
* CC[1].
13191322
*/
1320-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1323+
if (fast_switching) {
13211324
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
13221325
} else {
13231326
nrf_radio_shorts_set(NRF_RADIO,
@@ -1354,7 +1357,7 @@ static void on_radio_disabled_tx_wait_for_ack(void)
13541357
esb_ppi_for_retransmission_clear();
13551358

13561359
/* Start radio here. */
1357-
esb_ppi_for_txrx_set(false, true, fast_switching);
1360+
esb_ppi_for_txrx_set(false, true);
13581361
esb_fem_for_tx_set(true);
13591362

13601363
radio_start();
@@ -1366,7 +1369,7 @@ static void on_radio_disabled_tx_wait_for_ack(void)
13661369
static void clear_events_restart_rx(void)
13671370
{
13681371
esb_fem_lna_reset();
1369-
esb_ppi_for_txrx_clear(true, false, fast_switching);
1372+
esb_ppi_for_txrx_clear(true, false);
13701373

13711374
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
13721375

@@ -1385,7 +1388,7 @@ static void clear_events_restart_rx(void)
13851388

13861389
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common | NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
13871390

1388-
esb_ppi_for_txrx_set(true, false, fast_switching);
1391+
esb_ppi_for_txrx_set(true, false);
13891392
esb_fem_for_rx_set();
13901393

13911394
radio_start();
@@ -1473,13 +1476,6 @@ static void on_radio_disabled_rx(void)
14731476
if ((esb_cfg.selective_auto_ack == false) || rx_pdu->type.dpl_pdu.no_ack) {
14741477
esb_fem_for_tx_ack();
14751478

1476-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1477-
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1478-
} else {
1479-
nrf_radio_shorts_set(NRF_RADIO,
1480-
(radio_shorts_common | NRF_RADIO_SHORT_DISABLED_RXEN_MASK));
1481-
}
1482-
14831479
switch (esb_cfg.protocol) {
14841480
case ESB_PROTOCOL_ESB_DPL:
14851481
on_radio_disabled_rx_dpl(retransmit_payload, pipe_info);
@@ -1501,6 +1497,14 @@ static void on_radio_disabled_rx(void)
15011497
nrf_radio_txaddress_set(NRF_RADIO, nrf_radio_rxmatch_get(NRF_RADIO));
15021498
nrf_radio_packetptr_set(NRF_RADIO, tx_pdu);
15031499

1500+
if (fast_switching) {
1501+
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
1502+
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_TXEN);
1503+
} else {
1504+
nrf_radio_shorts_set(NRF_RADIO,
1505+
(radio_shorts_common | NRF_RADIO_SHORT_DISABLED_RXEN_MASK));
1506+
}
1507+
15041508
on_radio_disabled = on_radio_disabled_rx_ack;
15051509
} else {
15061510
clear_events_restart_rx();
@@ -1522,17 +1526,16 @@ static void on_radio_disabled_rx_ack(void)
15221526
{
15231527
esb_fem_for_ack_rx();
15241528

1525-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1529+
update_rf_payload_format(esb_cfg.payload_length);
1530+
1531+
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
1532+
if (fast_switching) {
15261533
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
15271534
nrf_radio_task_trigger(NRF_RADIO, NRF_RADIO_TASK_RXEN);
15281535
} else {
15291536
nrf_radio_shorts_set(NRF_RADIO, (radio_shorts_common |
15301537
NRF_RADIO_SHORT_DISABLED_TXEN_MASK));
15311538
}
1532-
1533-
update_rf_payload_format(esb_cfg.payload_length);
1534-
1535-
nrf_radio_packetptr_set(NRF_RADIO, rx_payload_buffer);
15361539
on_radio_disabled = on_radio_disabled_rx;
15371540

15381541
esb_state = ESB_STATE_PRX;
@@ -1703,7 +1706,7 @@ int esb_init(const struct esb_config *config)
17031706

17041707
memcpy(&esb_cfg, config, sizeof(esb_cfg));
17051708

1706-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
1709+
if (fast_switching) {
17071710
if (!esb_cfg.use_fast_ramp_up) {
17081711
return -EINVAL;
17091712
}
@@ -2038,7 +2041,7 @@ int esb_start_rx(void)
20382041

20392042
on_radio_disabled = on_radio_disabled_rx;
20402043

2041-
if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) {
2044+
if (fast_switching) {
20422045
nrf_radio_shorts_set(NRF_RADIO, radio_shorts_common);
20432046
nrf_radio_int_enable(NRF_RADIO, ESB_RADIO_INT_END_MASK);
20442047
} else {
@@ -2062,7 +2065,7 @@ int esb_start_rx(void)
20622065
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_PAYLOAD);
20632066
nrf_radio_event_clear(NRF_RADIO, NRF_RADIO_EVENT_DISABLED);
20642067

2065-
esb_ppi_for_txrx_set(true, false, fast_switching);
2068+
esb_ppi_for_txrx_set(true, false);
20662069
esb_fem_for_rx_set();
20672070

20682071
radio_start();
@@ -2076,7 +2079,7 @@ int esb_stop_rx(void)
20762079
return -EINVAL;
20772080
}
20782081

2079-
esb_ppi_for_txrx_clear(true, false, fast_switching);
2082+
esb_ppi_for_txrx_clear(true, false);
20802083
esb_fem_reset();
20812084

20822085
nrf_radio_shorts_disable(NRF_RADIO, 0xFFFFFFFF);

subsys/esb/esb_dppi.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static uint8_t radio_end_timer_start;
2727

2828
static nrf_dppi_channel_group_t ramp_up_dppi_group;
2929

30-
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
30+
void esb_ppi_for_txrx_set(bool rx, bool timer_start)
3131
{
3232
uint32_t channels_mask;
3333

@@ -48,11 +48,6 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
4848

4949
nrf_egu_subscribe_set(ESB_EGU, ESB_EGU_TASK, disabled_phy_end_egu);
5050

51-
if (fast_switching) {
52-
nrf_radio_subscribe_set(NRF_RADIO, rx ? NRF_RADIO_TASK_TXEN : NRF_RADIO_TASK_RXEN,
53-
disabled_phy_end_egu);
54-
}
55-
5651
if (timer_start) {
5752
nrf_timer_subscribe_set(ESB_NRF_TIMER_INSTANCE, NRF_TIMER_TASK_START,
5853
egu_timer_start);
@@ -64,7 +59,7 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
6459
nrf_dppi_channels_enable(ESB_DPPIC, channels_mask);
6560
}
6661

67-
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching)
62+
void esb_ppi_for_txrx_clear(bool rx, bool timer_start)
6863
{
6964
uint32_t channels_mask;
7065

@@ -84,11 +79,6 @@ void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching)
8479

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

87-
if (fast_switching) {
88-
nrf_radio_subscribe_clear(NRF_RADIO, rx ? NRF_RADIO_TASK_TXEN :
89-
NRF_RADIO_TASK_RXEN);
90-
}
91-
9282
if (timer_start) {
9383
nrf_timer_subscribe_clear(ESB_NRF_TIMER_INSTANCE, NRF_TIMER_TASK_START);
9484
}

subsys/esb/esb_ppi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ void esb_ppi_for_fem_clear(void)
4343
nrf_ppi_channel_endpoint_setup(NRF_PPI, egu_timer_start, 0, 0);
4444
}
4545

46-
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
46+
void esb_ppi_for_txrx_set(bool rx, bool timer_start)
4747
{
48-
ARG_UNUSED(fast_switching);
49-
5048
uint32_t channels_mask;
5149
uint32_t egu_event = nrf_egu_event_address_get(ESB_EGU, ESB_EGU_EVENT);
5250
uint32_t egu_task = nrf_egu_task_address_get(ESB_EGU, ESB_EGU_TASK);
@@ -75,9 +73,8 @@ void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching)
7573
nrf_ppi_channels_enable(NRF_PPI, channels_mask);
7674
}
7775

78-
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching)
76+
void esb_ppi_for_txrx_clear(bool rx, bool timer_start)
7977
{
80-
ARG_UNUSED(fast_switching);
8178
ARG_UNUSED(rx);
8279

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

subsys/esb/esb_ppi_api.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,18 @@ extern "C" {
3535
* |
3636
* \----> self disable
3737
*
38-
* if (fast_switching)
39-
* 1
40-
* RADIO_PHYEND ---> RADIO_TASK_TXEN/RXEN
41-
*
4238
* @param[in] rx Radio Rx mode, otherwise Tx mode.
4339
* @param[in] timer_start Indicates whether the timer is to be started on the EGU event.
44-
* @param[in] fast_switch Indicates whether to configure fast switching.
4540
*/
46-
void esb_ppi_for_txrx_set(bool rx, bool timer_start, bool fast_switching);
41+
void esb_ppi_for_txrx_set(bool rx, bool timer_start);
4742

4843
/** @brief Clear PPI/DPPI connection for Tx or Rx radio operations
4944
*
5045
* @param[in] rx Radio Rx mode, otherwise Tx mode.
5146
* @param[in] timer_start Clear timer connections if the timer was set using
5247
* the @ref esb_ppi_for_txrx_set function.
53-
* @param[in] fast_switching Clear fast switching configuration if the fast switching was set using
54-
* the @ref esb_ppi_for_txrx_set function.
5548
*/
56-
void esb_ppi_for_txrx_clear(bool rx, bool timer_start, bool fast_switching);
49+
void esb_ppi_for_txrx_clear(bool rx, bool timer_start);
5750

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

0 commit comments

Comments
 (0)