Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 826fd665f -> f10034d73


MYNEWT-539: Controller allocates too many os events for commands

The controller now uses a global os event and does not allocate a
memory pool.


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

Branch: refs/heads/develop
Commit: f10034d73e2cb5667bc1948f0a7b12af9aad9f1a
Parents: 826fd66
Author: William San Filippo <[email protected]>
Authored: Fri Jan 6 16:39:13 2017 -0800
Committer: William San Filippo <[email protected]>
Committed: Fri Jan 6 16:39:53 2017 -0800

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll_hci.h      |  4 +++-
 net/nimble/controller/src/ble_ll.c                  | 13 -------------
 net/nimble/controller/src/ble_ll_conn_priv.h        |  3 ---
 net/nimble/controller/src/ble_ll_hci.c              | 16 ++++++++--------
 4 files changed, 11 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f10034d7/net/nimble/controller/include/controller/ble_ll_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h 
b/net/nimble/controller/include/controller/ble_ll_hci.h
index 05f0be6..c2c4542 100644
--- a/net/nimble/controller/include/controller/ble_ll_hci.h
+++ b/net/nimble/controller/include/controller/ble_ll_hci.h
@@ -33,7 +33,9 @@ extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
 
 /*
  * This determines the number of outstanding commands allowed from the
- * host to the controller.
+ * host to the controller. NOTE: you cannot change this without modifying
+ * other portions of the code as we currently use a global os event for
+ * the command; you would need to allocate a pool of these.
  */
 #define BLE_LL_CFG_NUM_HCI_CMD_PKTS     (1)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f10034d7/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 63b3cac..81cd148 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -190,9 +190,6 @@ static void ble_ll_event_dbuf_overflow(struct os_event *ev);
 struct os_task g_ble_ll_task;
 os_stack_t g_ble_ll_stack[BLE_LL_STACK_SIZE];
 
-struct os_mempool g_ble_ll_hci_ev_pool;
-static void *ble_ll_hci_os_event_buf;
-
 /** Our global device address (public) */
 uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
 
@@ -1249,16 +1246,6 @@ ble_ll_init(void)
     os_cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
                           NULL);
 
-    ble_ll_hci_os_event_buf = malloc(
-        OS_MEMPOOL_BYTES(16, sizeof (struct os_event)));
-    SYSINIT_PANIC_ASSERT(ble_ll_hci_os_event_buf != NULL);
-
-    /* Create memory pool of OS events */
-    rc = os_mempool_init(&g_ble_ll_hci_ev_pool, 16,
-                         sizeof (struct os_event), ble_ll_hci_os_event_buf,
-                         "g_ble_ll_hci_ev_pool");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
     /* Initialize LL HCI */
     ble_ll_hci_init();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f10034d7/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 eea5439..f3ede51 100644
--- a/net/nimble/controller/src/ble_ll_conn_priv.h
+++ b/net/nimble/controller/src/ble_ll_conn_priv.h
@@ -85,9 +85,6 @@ extern struct ble_ll_conn_free_list g_ble_ll_conn_free_list;
 /* Pointer to connection state machine we are trying to create */
 extern struct ble_ll_conn_sm *g_ble_ll_conn_create_sm;
 
-extern struct os_mempool g_ble_ll_hci_ev_pool;
-
-
 /* Generic interface */
 struct ble_ll_len_req;
 struct hci_create_conn;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f10034d7/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c 
b/net/nimble/controller/src/ble_ll_hci.c
index 7f3bb09..e7480a1 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -37,6 +37,9 @@
 
 static void ble_ll_hci_cmd_proc(struct os_event *ev);
 
+/* OS event to enqueue command */
+static struct os_event g_ble_ll_hci_cmd_ev;
+
 /* LE event mask */
 static uint8_t g_ble_ll_hci_le_event_mask[BLE_HCI_SET_LE_EVENT_MASK_LEN];
 static uint8_t g_ble_ll_hci_event_mask[BLE_HCI_SET_EVENT_MASK_LEN];
@@ -991,16 +994,11 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
     uint8_t *cmdbuf;
     uint16_t opcode;
     uint16_t ocf;
-    os_error_t err;
 
     /* The command buffer is the event argument */
     cmdbuf = (uint8_t *)ev->ev_arg;
     assert(cmdbuf != NULL);
 
-    /* Free the event */
-    err = os_memblock_put(&g_ble_ll_hci_ev_pool, ev);
-    assert(err == OS_OK);
-
     /* Get the opcode from the command buffer */
     opcode = le16toh(cmdbuf);
     ocf = BLE_HCI_OCF(opcode);
@@ -1081,14 +1079,13 @@ ble_ll_hci_cmd_rx(uint8_t *cmd, void *arg)
     struct os_event *ev;
 
     /* Get an event structure off the queue */
-    ev = (struct os_event *)os_memblock_get(&g_ble_ll_hci_ev_pool);
-    if (!ev) {
+    ev = &g_ble_ll_hci_cmd_ev;
+    if (ev->ev_queued) {
         return BLE_ERR_MEM_CAPACITY;
     }
 
     /* Fill out the event and post to Link Layer */
     ev->ev_queued = 0;
-    ev->ev_cb = ble_ll_hci_cmd_proc;
     ev->ev_arg = cmd;
     os_eventq_put(&g_ble_ll_data.ll_evq, ev);
 
@@ -1112,6 +1109,9 @@ ble_ll_hci_acl_rx(struct os_mbuf *om, void *arg)
 void
 ble_ll_hci_init(void)
 {
+    /* Set event callback for command processing */
+    g_ble_ll_hci_cmd_ev.ev_cb = ble_ll_hci_cmd_proc;
+
     /* Set defaults for LE events: Vol 2 Part E 7.8.1 */
     g_ble_ll_hci_le_event_mask[0] = 0x1f;
 

Reply via email to