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/13 15:46:06 UTC

incubator-mynewt-core git commit: MYNEWT-387: Separate ACL buffer pool for controller only

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 77ddfe7fc -> 0fa968e2d


MYNEWT-387: Separate ACL buffer pool for controller only

The controller (for the controller only implementation) now uses
a separate pool of buffers for ACL data. This pool is only used
by the host to send ACL data; the controller will never grab a
buffer from this pool for any other reason. This was done so that
the controller and host will stay in sync regarding reported
total ACL buffers and the number of completed packets. By default,
4 ACL buffers are allocated. This is quite an arbitrary number
and should be modified based on memory available and application
requirements.


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

Branch: refs/heads/develop
Commit: 0fa968e2db3f18442ee417affb9fe2105c6f4b09
Parents: 77ddfe7
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Sep 13 08:42:45 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Tue Sep 13 08:45:54 2016 -0700

----------------------------------------------------------------------
 apps/blehci/src/main.c                          |  9 ++--
 .../uart/include/transport/uart/ble_hci_uart.h  |  1 +
 net/nimble/transport/uart/src/ble_hci_uart.c    | 50 +++++++++++++++++++-
 3 files changed, 54 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fa968e2/apps/blehci/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c
index e95f402..0dd77e8 100755
--- a/apps/blehci/src/main.c
+++ b/apps/blehci/src/main.c
@@ -51,7 +51,7 @@ struct os_mempool default_mbuf_mpool;
 int
 main(void)
 {
-    struct ble_hci_uart_cfg hci_cfg;
+    const struct ble_hci_uart_cfg *hci_cfg;
     int rc;
 
     /* Initialize OS */
@@ -74,11 +74,12 @@ main(void)
     assert(rc == 0);
 
     /* Initialize the BLE LL */
-    rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
+    hci_cfg = &ble_hci_uart_cfg_dflt;
+    rc = ble_ll_init(BLE_LL_TASK_PRI, hci_cfg->num_acl_bufs,
+                     BLE_MBUF_PAYLOAD_SIZE);
     assert(rc == 0);
 
-    hci_cfg = ble_hci_uart_cfg_dflt;
-    rc = ble_hci_uart_init(&hci_cfg);
+    rc = ble_hci_uart_init(hci_cfg);
     assert(rc == 0);
 
     /* Start the OS */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fa968e2/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h b/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
index 1fbaa74..de84ada 100644
--- a/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
+++ b/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
@@ -5,6 +5,7 @@ struct ble_hci_uart_cfg {
     uint32_t baud;
     uint16_t num_evt_bufs;
     uint16_t evt_buf_sz;
+    uint16_t num_acl_bufs;
     uint8_t uart_port;
     uint8_t flow_ctrl;
     uint8_t data_bits;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fa968e2/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
index 0fa982a..98e3eb2 100755
--- a/net/nimble/transport/uart/src/ble_hci_uart.c
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -59,6 +59,8 @@ const struct ble_hci_uart_cfg ble_hci_uart_cfg_dflt = {
 
     .num_evt_bufs = 8,
     .evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
+
+    .num_acl_bufs = 4
 };
 
 static ble_hci_trans_rx_cmd_fn *ble_hci_uart_rx_cmd_cb;
@@ -73,6 +75,10 @@ static void *ble_hci_uart_evt_buf;
 static struct os_mempool ble_hci_uart_pkt_pool;
 static void *ble_hci_uart_pkt_buf;
 
+static struct os_mbuf_pool ble_hci_uart_acl_mbuf_pool;
+static struct os_mempool ble_hci_uart_acl_pool;
+static void *ble_hci_uart_acl_buf;
+
 /**
  * An incoming or outgoing command or event.
  */
@@ -119,6 +125,21 @@ static struct {
 
 static struct ble_hci_uart_cfg ble_hci_uart_cfg;
 
+/**
+ * Allocates a buffer (mbuf) for ACL operation.
+ *
+ * @return                      The allocated buffer on success;
+ *                              NULL on buffer exhaustion.
+ */
+static struct os_mbuf *
+ble_hci_trans_acl_buf_alloc(void)
+{
+    struct os_mbuf *m;
+
+    m = os_mbuf_get_pkthdr(&ble_hci_uart_acl_mbuf_pool, 0);
+    return m;
+}
+
 static int
 ble_hci_uart_acl_tx(struct os_mbuf *om)
 {
@@ -296,8 +317,7 @@ ble_hci_uart_rx_pkt_type(uint8_t data)
         break;
 
     case BLE_HCI_UART_H4_ACL:
-        ble_hci_uart_state.rx_acl.buf =
-            os_msys_get_pkthdr(BLE_HCI_DATA_HDR_SZ, 0);
+        ble_hci_uart_state.rx_acl.buf = ble_hci_trans_acl_buf_alloc();
         assert(ble_hci_uart_state.rx_acl.buf != NULL);
 
         ble_hci_uart_state.rx_acl.len = 0;
@@ -456,6 +476,9 @@ ble_hci_uart_free_mem(void)
 
     free(ble_hci_uart_pkt_buf);
     ble_hci_uart_pkt_buf = NULL;
+
+    free(ble_hci_uart_acl_buf);
+    ble_hci_uart_acl_buf = NULL;
 }
 
 static int
@@ -700,11 +723,34 @@ int
 ble_hci_uart_init(const struct ble_hci_uart_cfg *cfg)
 {
     int rc;
+    int acl_block_size;
 
     ble_hci_uart_free_mem();
 
     ble_hci_uart_cfg = *cfg;
 
+    /*
+     * XXX: For now, we will keep the ACL buffer size such that it can
+     * accommodate BLE_MBUF_PAYLOAD_SIZE. It should be possible to make this
+     * user defined but more testing would need to be done in that case.
+     */
+    acl_block_size = BLE_MBUF_PAYLOAD_SIZE + BLE_MBUF_MEMBLOCK_OVERHEAD;
+    acl_block_size = OS_ALIGN(acl_block_size, OS_ALIGNMENT);
+    rc = mem_malloc_mempool(&ble_hci_uart_acl_pool,
+                            cfg->num_acl_bufs,
+                            acl_block_size,
+                            "ble_hci_uart_acl_pool",
+                            &ble_hci_uart_acl_buf);
+    if (rc != 0) {
+        rc = ble_err_from_os(rc);
+        goto err;
+    }
+
+    rc = os_mbuf_pool_init(&ble_hci_uart_acl_mbuf_pool, &ble_hci_uart_acl_pool,
+                           acl_block_size, cfg->num_acl_bufs);
+    assert(rc == 0);
+
+
     /* Create memory pool of HCI command / event buffers */
     rc = mem_malloc_mempool(&ble_hci_uart_evt_pool,
                             cfg->num_evt_bufs,