From 77cf73807448208370c8fb7733162c57ace7a576 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Mon, 28 Feb 2022 23:58:43 +0100 Subject: [PATCH] nimble/phy/nrf52: Add tx-tx transition This adds TX-TX transition, initially supported only on nRF52 PHY. --- .../controller/include/controller/ble_phy.h | 1 + nimble/drivers/nrf52/src/ble_phy.c | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/nimble/controller/include/controller/ble_phy.h b/nimble/controller/include/controller/ble_phy.h index 44e8809b2..3980d344e 100644 --- a/nimble/controller/include/controller/ble_phy.h +++ b/nimble/controller/include/controller/ble_phy.h @@ -65,6 +65,7 @@ struct os_mbuf; #define BLE_PHY_TRANSITION_NONE (0) #define BLE_PHY_TRANSITION_RX_TX (1) #define BLE_PHY_TRANSITION_TX_RX (2) +#define BLE_PHY_TRANSITION_TX_TX (3) /* PHY error codes */ #define BLE_PHY_ERR_RADIO_STATE (1) diff --git a/nimble/drivers/nrf52/src/ble_phy.c b/nimble/drivers/nrf52/src/ble_phy.c index c06536a9a..c4086a235 100644 --- a/nimble/drivers/nrf52/src/ble_phy.c +++ b/nimble/drivers/nrf52/src/ble_phy.c @@ -977,6 +977,7 @@ ble_phy_tx_end_isr(void) uint8_t was_encrypted; uint8_t transition; uint32_t rx_time; + uint32_t tx_time; /* Store PHY on which we've just transmitted smth */ tx_phy_mode = g_ble_phy_data.phy_cur_phy_mode; @@ -1001,14 +1002,9 @@ ble_phy_tx_end_isr(void) } #endif - /* Call transmit end callback */ - if (g_ble_phy_data.txend_cb) { - g_ble_phy_data.txend_cb(g_ble_phy_data.txend_arg); - } - transition = g_ble_phy_data.phy_transition; - if (transition == BLE_PHY_TRANSITION_TX_RX) { + if (transition == BLE_PHY_TRANSITION_TX_RX) { #if (BLE_LL_BT5_PHY_SUPPORTED == 1) ble_phy_mode_apply(g_ble_phy_data.phy_rx_phy_mode); #endif @@ -1032,6 +1028,25 @@ ble_phy_tx_end_isr(void) nrf_ppi_channels_enable(NRF_PPI, PPI_CHEN_CH21_Msk); ble_phy_plna_enable_lna(); + } else if (transition == BLE_PHY_TRANSITION_TX_TX) { + /* Schedule TX exactly T_IFS after TX end captured in CC[2] */ + tx_time = NRF_TIMER0->CC[2] + BLE_LL_IFS; + /* Adjust for delay between EVENT_END and actual TX end time */ + tx_time += g_ble_phy_t_txenddelay[tx_phy_mode]; + /* Adjust for radio ramp-up */ + tx_time -= BLE_PHY_T_TXENFAST; + /* Adjust for delay between EVENT_READY and actual TX start time */ + tx_time -= g_ble_phy_t_txdelay[g_ble_phy_data.phy_cur_phy_mode]; + + nrf_timer_cc_set(NRF_TIMER0, 0, tx_time); + NRF_TIMER0->EVENTS_COMPARE[0] = 0; + nrf_ppi_channels_enable(NRF_PPI, PPI_CHEN_CH20_Msk); + + nrf_timer_task_trigger(NRF_TIMER0, NRF_TIMER_TASK_CAPTURE3); + if (NRF_TIMER0->CC[3] > NRF_TIMER0->CC[0]) { + nrf_ppi_channels_disable(NRF_PPI, PPI_CHEN_CH20_Msk); + g_ble_phy_data.phy_transition_late = 1; + } } else { /* * XXX: not sure we need to stop the timer here all the time. Or that @@ -1043,6 +1058,10 @@ ble_phy_tx_end_isr(void) PPI_CHEN_CH20_Msk | PPI_CHEN_CH31_Msk); assert(transition == BLE_PHY_TRANSITION_NONE); } + + if (g_ble_phy_data.txend_cb) { + g_ble_phy_data.txend_cb(g_ble_phy_data.txend_arg); + } } static inline uint8_t