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 2016/09/09 19:49:29 UTC

incubator-mynewt-core git commit: MYNEWT-382: Controller number of completed packets event changes

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop ea6396046 -> 1efc7116c


MYNEWT-382: Controller number of completed packets event changes

The controller will now send a completed packets event when a
connection event ends and there is at least one completed
packet. The NIMBLE_OPT_NUM_COMP_PKT_RATE is still in the code but
its only real purpose now is to periodically send the number of
completed packet events when a connection has data buffers in its
transmit queue but the packets are not completing. The spec
requires the controller to periodically inform the host in this
case.


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/1efc7116
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1efc7116
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1efc7116

Branch: refs/heads/develop
Commit: 1efc7116c98edc0eccc837c4280b66b6083aa1b5
Parents: ea63960
Author: William San Filippo <wi...@runtime.io>
Authored: Fri Sep 9 12:38:38 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Fri Sep 9 12:49:24 2016 -0700

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_conn.c      |  4 +--
 net/nimble/controller/src/ble_ll_conn_hci.c  | 38 ++++++++++++++++++-----
 net/nimble/controller/src/ble_ll_conn_priv.h |  2 +-
 net/nimble/include/nimble/nimble_opt.h       | 18 +++++++++--
 4 files changed, 47 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1efc7116/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 f8d21cd..642e8c6 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -1937,9 +1937,7 @@ ble_ll_conn_event_end(void *arg)
     }
 
     /* If we have completed packets, send an event */
-    if (connsm->completed_pkts) {
-        ble_ll_conn_num_comp_pkts_event_send();
-    }
+    ble_ll_conn_num_comp_pkts_event_send(connsm);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1efc7116/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index d7001f8..5d44d27 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -38,7 +38,7 @@
  * Used to limit the rate at which we send the number of completed packets
  * event to the host. This is the os time at which we can send an event.
  */
-static uint32_t g_ble_ll_next_num_comp_pkt_evt;
+static uint32_t g_ble_ll_last_num_comp_pkt_evt;
 
 /**
  * Called to check that the connection parameters are within range
@@ -216,7 +216,7 @@ ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status)
  * to make it contiguous with the handles.
  */
 void
-ble_ll_conn_num_comp_pkts_event_send(void)
+ble_ll_conn_num_comp_pkts_event_send(struct ble_ll_conn_sm *connsm)
 {
     /** The maximum number of handles that will fit in an event buffer. */
     static const int max_handles =
@@ -227,11 +227,33 @@ ble_ll_conn_num_comp_pkts_event_send(void)
     uint8_t *handle_ptr;
     uint8_t *comp_pkt_ptr;
     uint8_t handles;
-    struct ble_ll_conn_sm *connsm;
 
-    /* Check rate limit */
-    if ((uint32_t)(g_ble_ll_next_num_comp_pkt_evt - os_time_get()) <
-         NIMBLE_OPT_NUM_COMP_PKT_RATE) {
+    /*
+     * At some periodic rate, make sure we go through all active connections
+     * and send the number of completed packet events. We do this mainly
+     * because the spec says we must update the host even though no packets
+     * have completed by there are data packets in the controller buffers
+     * (i.e. enqueued in a connection state machine).
+     */
+    if ((uint32_t)(g_ble_ll_last_num_comp_pkt_evt - os_time_get()) <
+         (NIMBLE_OPT_NUM_COMP_PKT_RATE * OS_TICKS_PER_SEC)) {
+        /*
+         * If this connection has completed packets, send an event right away.
+         * We do this to increase throughput but we dont want to search the
+         * entire active list every time.
+         */
+        if (connsm->completed_pkts) {
+            evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+            if (evbuf) {
+                evbuf[0] = BLE_HCI_EVCODE_NUM_COMP_PKTS;
+                evbuf[1] = (2 * sizeof(uint16_t)) + 1;
+                evbuf[2] = 1;
+                htole16(evbuf + 3, connsm->conn_handle);
+                htole16(evbuf + 5, connsm->completed_pkts);
+                ble_ll_hci_event_send(evbuf);
+                connsm->completed_pkts = 0;
+            }
+        }
         return;
     }
 
@@ -294,8 +316,8 @@ ble_ll_conn_num_comp_pkts_event_send(void)
     }
 
     if (event_sent) {
-        g_ble_ll_next_num_comp_pkt_evt = os_time_get() +
-            NIMBLE_OPT_NUM_COMP_PKT_RATE;
+        g_ble_ll_last_num_comp_pkt_evt = os_time_get() +
+            (NIMBLE_OPT_NUM_COMP_PKT_RATE * OS_TICKS_PER_SEC);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1efc7116/net/nimble/controller/src/ble_ll_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_priv.h b/net/nimble/controller/src/ble_ll_conn_priv.h
index fc06e5f..b8c4fa1 100644
--- a/net/nimble/controller/src/ble_ll_conn_priv.h
+++ b/net/nimble/controller/src/ble_ll_conn_priv.h
@@ -132,7 +132,7 @@ int ble_ll_conn_hci_update(uint8_t *cmdbuf);
 int ble_ll_conn_hci_set_chan_class(uint8_t *cmdbuf);
 int ble_ll_conn_hci_param_reply(uint8_t *cmdbuf, int negative_reply);
 int ble_ll_conn_create_cancel(void);
-void ble_ll_conn_num_comp_pkts_event_send(void);
+void ble_ll_conn_num_comp_pkts_event_send(struct ble_ll_conn_sm *connsm);
 void ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status);
 void ble_ll_conn_timeout(struct ble_ll_conn_sm *connsm, uint8_t ble_err);
 int ble_ll_conn_hci_chk_conn_params(uint16_t itvl_min, uint16_t itvl_max,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1efc7116/net/nimble/include/nimble/nimble_opt.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h
index 859b0aa..db4f38b 100644
--- a/net/nimble/include/nimble/nimble_opt.h
+++ b/net/nimble/include/nimble/nimble_opt.h
@@ -253,11 +253,23 @@
 #endif
 
 /*
- * Determines the maximum rate at which the controller will send the
- * number of completed packets event to the host. Rate is in os time ticks
+ * Timeout used by the controller when determining if a number of completed
+ * packets event should be sent to the host if there are data buffers in the
+ * controller that have not completed.
+ *
+ * NOTE:  the controller attempts to send the number of completed packets
+ * event after each connection event in which a packet was completed. This
+ * means that the host should expect that event at a rate much faster than
+ * defined here (assuming packets are being sent and the connection interval
+ * is shorter than the rate defined here). Thus, this definition exists in
+ * order to satisfy the spec requirement to notify the host (at some
+ * manufacturer specified rate) when the controller has data buffers that
+ * have not completed.
+ *
+ * This rate is in seconds.
  */
 #ifndef NIMBLE_OPT_NUM_COMP_PKT_RATE
-#define NIMBLE_OPT_NUM_COMP_PKT_RATE    ((2000 * OS_TICKS_PER_SEC) / 1000)
+#define NIMBLE_OPT_NUM_COMP_PKT_RATE            (10)
 #endif
 
 /* Manufacturer ID. Should be set to unique ID per manufacturer */