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 2022/06/22 13:18:24 UTC

[mynewt-nimble] 04/12: nimble/ll/css: Fix handling of 1st connection event

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 3f606a09bfe787d7601da21bbd15ed9cca5ce80d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Jun 9 16:13:17 2022 +0200

    nimble/ll/css: Fix handling of 1st connection event
    
    If there are no connections present, we can schedule 1st connection
    event as for any other connection, i.e. with non-zero txWindowOffset.
    We set this new connection as reference only if it's successfully
    created.
    
    For each subsequent connection we do not allow txWindowOffset since it
    has to be scheduled precisely at slot anchor.
    
    Also make sure that requested next slot is reset after connection is
    created to avoid scheduling another connection on the same slot.
---
 .../controller/include/controller/ble_ll_sched.h   |  1 +
 nimble/controller/src/ble_ll_conn.c                |  5 +++
 nimble/controller/src/ble_ll_sched.c               | 36 ++++++++++++----------
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_sched.h b/nimble/controller/include/controller/ble_ll_sched.h
index a65b5d43..7dac8495 100644
--- a/nimble/controller/include/controller/ble_ll_sched.h
+++ b/nimble/controller/include/controller/ble_ll_sched.h
@@ -179,6 +179,7 @@ int ble_ll_sched_dtm(struct ble_ll_sched_item *sch);
 #if !MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED_FIXED)
 void ble_ll_sched_css_set_params(uint32_t slot_us, uint32_t period_slots);
 #endif
+void ble_ll_sched_css_update_anchor(struct ble_ll_conn_sm *connsm);
 void ble_ll_sched_css_set_conn_anchor(struct ble_ll_conn_sm *connsm);
 #if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED_FIXED)
 static inline uint32_t
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 393ae879..9199c867 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -2682,6 +2682,11 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr)
         switch (connsm->conn_role) {
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
         case BLE_LL_CONN_ROLE_CENTRAL:
+#if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
+            ble_ll_sched_css_update_anchor(connsm);
+            ble_ll_conn_css_set_next_slot(BLE_LL_CONN_CSS_NO_SLOT);
+#endif
+
             evbuf = ble_ll_init_get_conn_comp_ev();
             ble_ll_conn_comp_event_send(connsm, BLE_ERR_SUCCESS, evbuf, NULL);
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)
diff --git a/nimble/controller/src/ble_ll_sched.c b/nimble/controller/src/ble_ll_sched.c
index 6e1cde54..14cb954e 100644
--- a/nimble/controller/src/ble_ll_sched.c
+++ b/nimble/controller/src/ble_ll_sched.c
@@ -408,7 +408,6 @@ ble_ll_sched_conn_central_new(struct ble_ll_conn_sm *connsm,
 {
 #if MYNEWT_VAL(BLE_LL_CONN_STRICT_SCHED)
     struct ble_ll_sched_css *css = &g_ble_ll_sched_css;
-    struct ble_ll_conn_sm *connsm_ref;
 #endif
     struct ble_ll_sched_item *sch;
     uint32_t orig_start_time;
@@ -504,18 +503,17 @@ ble_ll_sched_conn_central_new(struct ble_ll_conn_sm *connsm,
 
     OS_ENTER_CRITICAL(sr);
 
-    connsm_ref = g_ble_ll_conn_css_ref;
-    if (!connsm_ref) {
-        g_ble_ll_conn_css_ref = connsm;
-
-        css->period_anchor_slot_idx = connsm->css_slot_idx;
-        css->period_anchor_idx = 0;
-        css->period_anchor_ticks = adv_rxend;
+    if (!g_ble_ll_conn_css_ref) {
+        css->period_anchor_ticks = earliest_start;
         css->period_anchor_rem_us = 0;
+        css->period_anchor_idx = 0;
+        css->period_anchor_slot_idx = connsm->css_slot_idx;
 
-        connsm->css_period_idx = 1;
+        connsm->css_period_idx = 0;
+        max_delay = connsm->conn_itvl_ticks;
     } else {
-        connsm->css_period_idx = css->period_anchor_idx + 1;
+        connsm->css_period_idx = css->period_anchor_idx;
+        max_delay = 0;
     }
 
     ble_ll_sched_css_set_conn_anchor(connsm);
@@ -531,11 +529,7 @@ ble_ll_sched_conn_central_new(struct ble_ll_conn_sm *connsm,
     if (rem_us == 0) {
         sch->end_time--;
     }
-
-    max_delay = 0;
-
 #else
-
     sch->start_time = earliest_start - g_ble_ll_sched_offset_ticks;
     sch->end_time = earliest_start +
                     ble_ll_tmr_u2t(MYNEWT_VAL(BLE_LL_CONN_INIT_SLOTS) *
@@ -548,13 +542,11 @@ ble_ll_sched_conn_central_new(struct ble_ll_conn_sm *connsm,
     sch->remainder = 0;
 
     max_delay = connsm->conn_itvl_ticks - min_win_offset;
-
 #endif
 
     OS_ENTER_CRITICAL(sr);
 
     rc = ble_ll_sched_insert(sch, max_delay, preempt_none);
-
     if (rc == 0) {
         connsm->tx_win_off = ble_ll_tmr_t2u(sch->start_time - orig_start_time) /
                              BLE_LL_CONN_TX_OFF_USECS;
@@ -562,7 +554,6 @@ ble_ll_sched_conn_central_new(struct ble_ll_conn_sm *connsm,
         connsm->anchor_point = sch->start_time + g_ble_ll_sched_offset_ticks;
         connsm->anchor_point_usecs = sch->remainder;
         connsm->ce_end_time = sch->end_time;
-
     }
 
     OS_EXIT_CRITICAL(sr);
@@ -1194,6 +1185,17 @@ ble_ll_sched_css_set_params(uint32_t slot_us, uint32_t period_slots)
     g_ble_ll_sched_css.period_slots = period_slots;
 }
 #endif
+void
+ble_ll_sched_css_update_anchor(struct ble_ll_conn_sm *connsm)
+{
+    struct ble_ll_sched_css *css = &g_ble_ll_sched_css;
+
+    if (!g_ble_ll_conn_css_ref) {
+        g_ble_ll_conn_css_ref = connsm;
+        css->period_anchor_ticks = connsm->anchor_point;
+        css->period_anchor_rem_us = connsm->anchor_point_usecs;
+    }
+}
 
 void
 ble_ll_sched_css_set_conn_anchor(struct ble_ll_conn_sm *connsm)