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/07/08 20:42:21 UTC

incubator-mynewt-core git commit: MYNEWT-83: Controller should use a fixed buffer for reception

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop e9f0c16e4 -> 28e2a8b4e


MYNEWT-83: Controller should use a fixed buffer for reception

In preparation for the rather large code change that will come
with this ticket, I am moving some things from the connection
receive end ISR processing into either the rx start is or the
Link Layer. The reason is that when we use a fixed buffer for
reception we will have to copy the receive buffer into a mbuf.
This will take extra time so we need to do everything we can do
to remove time from the rx end isr.

The changes are pretty simple: move the check for proper access
address into the rx start isr and we can do that there. We also
moved the anchor point processing into the receive start ISR as
we use the receive start time to calculate the anchor point.


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

Branch: refs/heads/develop
Commit: 28e2a8b4efcda9d241720f25749137de37ad71e8
Parents: e9f0c16
Author: William San Filippo <wi...@runtime.io>
Authored: Fri Jul 8 13:39:15 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Fri Jul 8 13:42:09 2016 -0700

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll.c           | 10 ++---
 net/nimble/controller/src/ble_ll_conn.c      | 49 ++++++++++++++---------
 net/nimble/controller/src/ble_ll_conn_priv.h |  4 +-
 3 files changed, 35 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/28e2a8b4/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index f1b5f6c..3a09e3e 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -667,6 +667,7 @@ ble_ll_rx_start(struct os_mbuf *rxpdu, uint8_t chan)
     int rc;
     uint8_t pdu_type;
     uint8_t *rxbuf;
+    struct ble_mbuf_hdr *ble_hdr;
 
     ble_ll_log(BLE_LL_LOG_ID_RX_START, chan, 0, (uint32_t)rxpdu);
 
@@ -678,11 +679,8 @@ ble_ll_rx_start(struct os_mbuf *rxpdu, uint8_t chan)
          * ongoing connection
          */
         if (g_ble_ll_data.ll_state == BLE_LL_STATE_CONNECTION) {
-            /* Call conection pdu rx start function */
-            ble_ll_conn_rx_isr_start();
-
-            /* Set up to go from rx to tx */
-            rc = 1;
+            ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
+            rc = ble_ll_conn_rx_isr_start(ble_hdr, ble_phy_access_addr_get());
         } else {
             STATS_INC(ble_ll_stats, bad_ll_state);
             rc = 0;
@@ -778,7 +776,7 @@ ble_ll_rx_end(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *ble_hdr)
          * Data channel pdu. We should be in CONNECTION state with an
          * ongoing connection.
          */
-        rc = ble_ll_conn_rx_isr_end(rxpdu, ble_phy_access_addr_get());
+        rc = ble_ll_conn_rx_isr_end(rxpdu);
         return rc;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/28e2a8b4/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 312c26f..ca94310 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2410,9 +2410,11 @@ ble_ll_conn_spvn_timeout(void *arg)
  * been checked yet.
  *
  * Context: Interrupt
+ *
+ * @param rxhdr
  */
-void
-ble_ll_conn_rx_isr_start(void)
+int
+ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa)
 {
     struct ble_ll_conn_sm *connsm;
 
@@ -2425,8 +2427,30 @@ ble_ll_conn_rx_isr_start(void)
     ble_ll_wfr_disable();
     connsm = g_ble_ll_conn_cur_sm;
     if (connsm) {
+        /* Double check access address. Better match connection state machine */
+        if (aa != connsm->access_addr) {
+            STATS_INC(ble_ll_conn_stats, rx_data_pdu_bad_aa);
+            ble_ll_state_set(BLE_LL_STATE_STANDBY);
+            ble_ll_event_send(&connsm->conn_ev_end);
+            g_ble_ll_conn_cur_sm = NULL;
+            return -1;
+        }
+
+        /* Set connection handle in mbuf header */
+        rxhdr->rxinfo.handle = connsm->conn_handle;
+
+        /* Set flag denoting we have received a packet in connection event */
         connsm->csmflags.cfbit.pkt_rxd = 1;
+
+        /* Set anchor point (and last) if 1st rxd frame in connection event */
+        if (connsm->csmflags.cfbit.slave_set_last_anchor) {
+            connsm->csmflags.cfbit.slave_set_last_anchor = 0;
+            connsm->last_anchor_point = rxhdr->beg_cputime;
+            connsm->anchor_point = connsm->last_anchor_point;
+        }
     }
+
+    return 1;
 }
 
 /**
@@ -2577,7 +2601,7 @@ conn_rx_data_pdu_end:
  *       > 0: Do not disable PHY as that has already been done.
  */
 int
-ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
+ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu)
 {
     int rc;
     int is_ctrl;
@@ -2607,15 +2631,8 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
         goto conn_exit;
     }
 
-    /* Double check access address. Better match connection state machine! */
-    if (aa != connsm->access_addr) {
-        STATS_INC(ble_ll_conn_stats, rx_data_pdu_bad_aa);
-        goto conn_exit;
-    }
-
     /* Set the handle in the ble mbuf header */
     rxhdr = BLE_MBUF_HDR_PTR(rxpdu);
-    rxhdr->rxinfo.handle = connsm->conn_handle;
     hdr_byte = rxpdu->om_data[0];
     rx_pyld_len = rxpdu->om_data[1];
 
@@ -2725,7 +2742,7 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
                         rc = ble_ll_ctrl_tx_done(txpdu, connsm);
                         if (rc) {
                             /* Means we transmitted a TERMINATE_IND */
-                            goto conn_rx_pdu_end;
+                            goto conn_exit;
                         } else {
                             goto chk_rx_terminate_ind;
                         }
@@ -2792,16 +2809,8 @@ chk_rx_terminate_ind:
         rc = ble_ll_conn_tx_data_pdu(connsm);
     }
 
-conn_rx_pdu_end:
-    /* Set anchor point (and last) if 1st received frame in connection event */
-    if (connsm->csmflags.cfbit.slave_set_last_anchor) {
-        connsm->csmflags.cfbit.slave_set_last_anchor = 0;
-        connsm->last_anchor_point = rxhdr->beg_cputime;
-        connsm->anchor_point = connsm->last_anchor_point;
-    }
-
-    /* Send link layer a connection end event if over */
 conn_exit:
+    /* Send link layer a connection end event if over */
     if (rc) {
         ble_ll_conn_current_sm_over();
         if (connsm) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/28e2a8b4/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 c94093e..218ecbc 100644
--- a/net/nimble/controller/src/ble_ll_conn_priv.h
+++ b/net/nimble/controller/src/ble_ll_conn_priv.h
@@ -106,8 +106,8 @@ void ble_ll_conn_module_reset(void);
 void ble_ll_conn_event_end(void *arg);
 void ble_ll_conn_tx_pkt_in(struct os_mbuf *om, uint16_t handle, uint16_t len);
 void ble_ll_conn_spvn_timeout(void *arg);
-void ble_ll_conn_rx_isr_start(void);
-int ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa);
+int ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa);
+int ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu);
 void ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr);
 void ble_ll_init_rx_pkt_in(uint8_t *rxbuf, struct ble_mbuf_hdr *ble_hdr);
 int ble_ll_init_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok);