You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/01/29 10:00:01 UTC

[mynewt-nimble] 02/03: nimble/phy: Add API to set ifs for tx-tx transition

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 20198fae319842e445cfb24cc5038ccb877be41e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Jan 21 00:49:50 2023 +0100

    nimble/phy: Add API to set ifs for tx-tx transition
    
    TX-TX transition is kind of special since we'll use it e.g. for ISO to
    achieve proper spacing between subevents thus we want to be able to
    control time between start of PDUs.
---
 nimble/controller/include/controller/ble_phy.h |  4 ++++
 nimble/drivers/nrf5x/src/ble_phy.c             | 28 ++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/nimble/controller/include/controller/ble_phy.h b/nimble/controller/include/controller/ble_phy.h
index 9b3a57b9..902ac034 100644
--- a/nimble/controller/include/controller/ble_phy.h
+++ b/nimble/controller/include/controller/ble_phy.h
@@ -92,6 +92,10 @@ int ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit);
 void ble_phy_tifs_set(uint16_t tifs);
 #endif
 
+/* Set T_ifs for tx-tx transitions. Anchor is 0 for start of previous PDU,
+ * non-zero for end of PDU */
+void ble_phy_tifs_txtx_set(uint16_t usecs, uint8_t anchor);
+
 /* Set transmit start time */
 int ble_phy_tx_set_start_time(uint32_t cputime, uint8_t rem_usecs);
 
diff --git a/nimble/drivers/nrf5x/src/ble_phy.c b/nimble/drivers/nrf5x/src/ble_phy.c
index d4fe0a51..3cdae5c5 100644
--- a/nimble/drivers/nrf5x/src/ble_phy.c
+++ b/nimble/drivers/nrf5x/src/ble_phy.c
@@ -68,6 +68,8 @@
 extern void tm_tick(void);
 #endif
 
+#include <controller/ble_ll_pdu.h>
+
 /*
  * NOTE: This code uses a couple of PPI channels so care should be taken when
  *       using PPI somewhere else.
@@ -153,6 +155,9 @@ struct ble_phy_obj
 #if MYNEWT_VAL(BLE_PHY_VARIABLE_TIFS)
     uint16_t tifs;
 #endif
+
+    uint16_t txtx_time_us;
+    uint8_t txtx_time_anchor;
 };
 static struct ble_phy_obj g_ble_phy_data;
 
@@ -1092,8 +1097,20 @@ ble_phy_tx_end_isr(void)
          *       case we still rxd something, so perhaps we could check it here
          */
     } 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] + tifs;
+        if (g_ble_phy_data.txtx_time_anchor) {
+            /* Schedule next TX relative to current TX end. TX end timestamp is
+             * captured in CC[2].
+             */
+            tx_time = NRF_TIMER0->CC[2] + g_ble_phy_data.txtx_time_us;
+        } else {
+            /* Schedule next TX relative to current TX start. AA timestamp is
+             * captured in CC[1], we need to adjust for sync word to get TX
+             * start.
+             */
+            tx_time = NRF_TIMER0->CC[1] - ble_ll_pdu_syncword_us(tx_phy_mode) +
+                      g_ble_phy_data.txtx_time_us;
+        }
+
         /* Adjust for delay between EVENT_END and actual TX end time */
         tx_time += g_ble_phy_t_txenddelay[tx_phy_mode];
 
@@ -2228,3 +2245,10 @@ ble_phy_rfclk_disable(void)
     nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTOP);
 #endif
 }
+
+void
+ble_phy_tifs_txtx_set(uint16_t usecs, uint8_t anchor)
+{
+    g_ble_phy_data.txtx_time_us = usecs;
+    g_ble_phy_data.txtx_time_anchor = anchor;
+}