You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2017/03/24 19:12:25 UTC

incubator-mynewt-core git commit: Fix bug where radio disabled interrupt was not being set. Slight refactor of wfr enable code in the phy.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/nrf_cputime ad64d0c88 -> 96e2cd2f7


Fix bug where radio disabled interrupt was not being set. Slight
refactor of wfr enable code in the phy.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/96e2cd2f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/96e2cd2f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/96e2cd2f

Branch: refs/heads/nrf_cputime
Commit: 96e2cd2f7d37154d7e991f67875f5f3b1fe17e4a
Parents: ad64d0c
Author: William San Filippo <wi...@runtime.io>
Authored: Fri Mar 24 12:11:32 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Fri Mar 24 12:11:32 2017 -0700

----------------------------------------------------------------------
 hw/drivers/nimble/nrf52/src/ble_phy.c           | 69 ++++++++++++--------
 .../controller/include/controller/ble_phy.h     |  4 +-
 net/nimble/controller/src/ble_ll_conn.c         |  9 ++-
 3 files changed, 50 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96e2cd2f/hw/drivers/nimble/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/hw/drivers/nimble/nrf52/src/ble_phy.c b/hw/drivers/nimble/nrf52/src/ble_phy.c
index a3254ca..8d8b0e1 100644
--- a/hw/drivers/nimble/nrf52/src/ble_phy.c
+++ b/hw/drivers/nimble/nrf52/src/ble_phy.c
@@ -362,20 +362,51 @@ ble_phy_set_start_time(uint32_t cputime, uint8_t rem_usecs)
     return 0;
 }
 
+/**
+ * Function is used to set PPI so that we can time out waiting for a reception
+ * to occur. This happens for two reasons: we have sent a packet and we are
+ * waiting for a respons (txrx should be set to ENABLE_TXRX) or we are
+ * starting a connection event and we are a slave and we are waiting for the
+ * master to send us a packet (txrx should be set to ENABLE_RX).
+ *
+ * NOTE: when waiting for a txrx turn-around, wfr_usecs is not used as there
+ * is no additional time to wait; we know when we should receive the address of
+ * the received frame.
+ *
+ * @param txrx Flag denoting if this wfr is a txrx turn-around or not.
+ * @param wfr_usecs Amount of usecs to wait.
+ */
 void
-ble_phy_wfr_enable(uint32_t wfr_usecs)
+ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs)
 {
-    uint32_t start;
+    uint32_t end_time;
 
-    /* CC[0] is set to when RXEN occurs */
-    start = NRF_TIMER0->CC[0];
+    if (txrx == BLE_PHY_WFR_ENABLE_TXRX) {
+        /*
+         * Timeout occurs an IFS time plus time it takes to receive address
+         * from the transmit end. We add additional time to make sure the
+         * address event comes before the compare. Note that transmit end
+         * is captured in CC[2]
+         *
+         * XXX: this assumes 1Mbps as 40 usecs is header rx time for 1Mbps
+         */
+        end_time = NRF_TIMER0->CC[2] + BLE_LL_IFS + 40 + 16;
+    } else {
+        /* CC[0] is set to when RXEN occurs. NOTE: the extra 16 usecs is
+           jitter */
+        end_time = NRF_TIMER0->CC[0] + XCVR_RX_START_DELAY_USECS + wfr_usecs +
+            40 + 16;
+    }
 
     /* wfr_secs is the time from rxen until timeout */
-    NRF_TIMER0->CC[3] = start + XCVR_RX_START_DELAY_USECS + wfr_usecs;
+    NRF_TIMER0->CC[3] = end_time;
     NRF_TIMER0->EVENTS_COMPARE[3] = 0;
 
     /* Enable wait for response PPI */
     NRF_PPI->CHENSET = (PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk);
+
+    /* Enable the disabled interrupt so we time out on events compare */
+    NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk;
 }
 #endif
 
@@ -459,16 +490,11 @@ ble_phy_tx_end_isr(void)
     uint8_t transition;
     uint8_t txlen;
     uint32_t wfr_time;
-#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
-    uint32_t txend;
-#else
+#if (MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768)
     uint32_t txstart;
 #endif
 
-#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
-    /* Read captured end time */
-    txend = NRF_TIMER0->CC[2];
-#else
+#if (MYNEWT_VAL(OS_CPUTIME_FREQ) != 32768)
     /*
      * Read captured tx start time. This is not the actual transmit start
      * time but it is the time at which the address event occurred
@@ -486,7 +512,7 @@ ble_phy_tx_end_isr(void)
     /* Log the event */
 #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
     ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
-               was_encrypted, txend);
+               was_encrypted, NRF_TIMER0->CC[2]);
 #else
     ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, g_ble_phy_data.phy_tx_pyld_len,
                was_encrypted, txstart);
@@ -497,6 +523,7 @@ ble_phy_tx_end_isr(void)
     NRF_RADIO->INTENCLR = RADIO_INTENCLR_DISABLED_Msk;
     NRF_RADIO->EVENTS_END = 0;
     wfr_time = NRF_RADIO->SHORTS;
+    (void)wfr_time;
 
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
     /*
@@ -530,21 +557,7 @@ ble_phy_tx_end_isr(void)
             txlen += BLE_LL_DATA_MIC_LEN;
         }
 #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
-        /*
-         * Set TIMER0 CC[3] to wait for response timeout. This occurs an IFS
-         * time plus the time it takes to receive the address from the transmit
-         * end. We add additional time to make sure the address event comes
-         * before the compare.
-         */
-        wfr_time = BLE_LL_IFS + 40 + 16;
-        NRF_TIMER0->CC[3] = txend + wfr_time;
-        NRF_TIMER0->EVENTS_COMPARE[3] = 0;
-
-        /* Enable wait for response PPI */
-        NRF_PPI->CHENSET = (PPI_CHEN_CH4_Msk | PPI_CHEN_CH5_Msk);
-
-        /* Enable the disabled interrupt so we time out on events compare */
-        NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk;
+        ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_TXRX, 0);
 #else
         wfr_time = BLE_LL_WFR_USECS - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET);
         wfr_time += BLE_TX_DUR_USECS_M(txlen);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96e2cd2f/net/nimble/controller/include/controller/ble_phy.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_phy.h b/net/nimble/controller/include/controller/ble_phy.h
index 2487168..e62b216 100644
--- a/net/nimble/controller/include/controller/ble_phy.h
+++ b/net/nimble/controller/include/controller/ble_phy.h
@@ -124,7 +124,9 @@ void ble_phy_disable(void);
 
 #if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768)
 void ble_phy_stop_usec_timer(void);
-void ble_phy_wfr_enable(uint32_t wfr_usecs);
+void ble_phy_wfr_enable(int txrx, uint32_t wfr_usecs);
+#define BLE_PHY_WFR_ENABLE_RX       (0)
+#define BLE_PHY_WFR_ENABLE_TXRX     (1)
 #else
 #define ble_phy_stop_usec_timer()
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96e2cd2f/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 253e96e..a32d8f8 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -1276,11 +1276,14 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
              *   -> up to one 32 kHz tick since we discard remainder.
              *   -> Up to one tick since the usecs to ticks calc can be off
              *   by up to one tick.
-             * NOTE: the 61 we add is for the two ticks mentioned above.
+             * NOTES:
+             * 1) the 61 we add is for the two ticks mentioned above.
+             * 2) The address rx time and jitter is accounted for in the
+             * phy function
              */
-            usecs = connsm->slave_cur_tx_win_usecs + 40 + 16 + 61 +
+            usecs = connsm->slave_cur_tx_win_usecs + 61 +
                 (2 * connsm->slave_cur_window_widening);
-            ble_phy_wfr_enable(usecs);
+            ble_phy_wfr_enable(BLE_PHY_WFR_ENABLE_RX, usecs);
 #else
             usecs = connsm->slave_cur_tx_win_usecs + BLE_LL_WFR_USECS +
                 connsm->slave_cur_window_widening;