You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2019/06/04 09:50:28 UTC

[mynewt-nimble] 01/02: nimble/ll: Move window widening algorithm to utils

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

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

commit 57d59b1fb86eed8a7844946e813ab826c4370b46
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Tue Apr 16 10:58:29 2019 +0200

    nimble/ll: Move window widening algorithm to utils
    
    This will also be used by periodic advertising scanner.
---
 .../controller/include/controller/ble_ll_utils.h   |  3 ++
 nimble/controller/src/ble_ll_conn.c                | 42 +++-------------------
 nimble/controller/src/ble_ll_utils.c               | 28 +++++++++++++++
 3 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index bf560d7..2483090 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -24,3 +24,6 @@ uint8_t ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanma
 uint8_t ble_ll_utils_calc_dci_csa2(uint16_t event_cntr, uint16_t channel_id,
                                    uint8_t num_used_chans, const uint8_t *chanmap);
 uint8_t ble_ll_utils_calc_num_used_chans(const uint8_t *chanmap);
+uint32_t ble_ll_utils_calc_window_widening(uint32_t anchor_point,
+                                           uint32_t last_anchor_point,
+                                           uint8_t master_sca);
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 1837c35..8661927 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -131,12 +131,6 @@ struct ble_ll_empty_pdu
     #error "Maximum # of connections is 254"
 #endif
 
-/* Sleep clock accuracy table (in ppm) */
-static const uint16_t g_ble_sca_ppm_tbl[8] =
-{
-    500, 250, 150, 100, 75, 50, 30, 20
-};
-
 /* Global connection complete event. Used when initiating */
 uint8_t *g_ble_ll_conn_comp_ev;
 
@@ -432,37 +426,6 @@ ble_ll_conn_sm_get(void)
     return connsm;
 }
 
-/**
- * Calculate the amount of window widening for a given connection event. This
- * is the amount of time that a slave has to account for when listening for
- * the start of a connection event.
- *
- * @param connsm Pointer to connection state machine.
- *
- * @return uint32_t The current window widening amount (in microseconds)
- */
-uint32_t
-ble_ll_conn_calc_window_widening(struct ble_ll_conn_sm *connsm)
-{
-    uint32_t total_sca_ppm;
-    uint32_t window_widening;
-    int32_t time_since_last_anchor;
-    uint32_t delta_msec;
-
-    window_widening = 0;
-
-    time_since_last_anchor = (int32_t)(connsm->anchor_point -
-                                       connsm->last_anchor_point);
-    if (time_since_last_anchor > 0) {
-        delta_msec = os_cputime_ticks_to_usecs(time_since_last_anchor) / 1000;
-        total_sca_ppm = g_ble_sca_ppm_tbl[connsm->master_sca] +
-            MYNEWT_VAL(BLE_LL_OUR_SCA);
-        window_widening = (total_sca_ppm * delta_msec) / 1000;
-    }
-
-    return window_widening;
-}
-
 static uint8_t
 ble_ll_conn_calc_dci_csa1(struct ble_ll_conn_sm *conn)
 {
@@ -2143,7 +2106,10 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
     itvl = MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) * BLE_LL_SCHED_32KHZ_TICKS_PER_SLOT;
 #endif
     if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
-        cur_ww = ble_ll_conn_calc_window_widening(connsm);
+
+        cur_ww = ble_ll_utils_calc_window_widening(connsm->anchor_point,
+                                                   connsm->last_anchor_point,
+                                                   connsm->master_sca);
         max_ww = (connsm->conn_itvl * (BLE_LL_CONN_ITVL_USECS/2)) - BLE_LL_IFS;
         if (cur_ww >= max_ww) {
             return -1;
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 43a0887..7fbb18f 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -26,6 +26,11 @@
 /* 37 bits require 5 bytes */
 #define BLE_LL_CHMAP_LEN (5)
 
+/* Sleep clock accuracy table (in ppm) */
+static const uint16_t g_ble_sca_ppm_tbl[8] = {
+    500, 250, 150, 100, 75, 50, 30, 20
+};
+
 uint32_t
 ble_ll_utils_calc_access_addr(void)
 {
@@ -271,3 +276,26 @@ ble_ll_utils_calc_dci_csa2(uint16_t event_cntr, uint16_t channel_id,
     return ble_ll_utils_remapped_channel(remap_index, chanmap);
 }
 #endif
+
+uint32_t
+ble_ll_utils_calc_window_widening(uint32_t anchor_point,
+                                  uint32_t last_anchor_point,
+                                  uint8_t master_sca)
+{
+    uint32_t total_sca_ppm;
+    uint32_t window_widening;
+    int32_t time_since_last_anchor;
+    uint32_t delta_msec;
+
+    window_widening = 0;
+
+    time_since_last_anchor = (int32_t)(anchor_point - last_anchor_point);
+    if (time_since_last_anchor > 0) {
+        delta_msec = os_cputime_ticks_to_usecs(time_since_last_anchor) / 1000;
+        total_sca_ppm = g_ble_sca_ppm_tbl[master_sca] +
+                                          MYNEWT_VAL(BLE_LL_OUR_SCA);
+        window_widening = (total_sca_ppm * delta_msec) / 1000;
+    }
+
+    return window_widening;
+}