You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/02/09 01:13:38 UTC
[4/5] incubator-mynewt-larva git commit: Make number of HCI bufs
configurable.
Make number of HCI bufs configurable.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/f9c49254
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/f9c49254
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/f9c49254
Branch: refs/heads/master
Commit: f9c49254b88e0a4245f87e73658d3c5a1173c746
Parents: 741edf5
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 16:08:38 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 16:11:38 2016 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs.h | 3 ++
net/nimble/host/src/ble_hs.c | 65 +++++++++++++++++++++---------
net/nimble/host/src/ble_hs_cfg.c | 3 ++
project/bletiny/src/main.c | 1 +
4 files changed, 52 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f9c49254/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index a6b5154..eaa5a3a 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -59,6 +59,9 @@
#define BLE_HS_L2C_ERR(x) ((x) ? BLE_HS_ERR_L2C_BASE + (x) : 0)
struct ble_hs_cfg {
+ /** HCI settings. */
+ uint8_t max_hci_bufs;
+
/** Connection settings. */
uint16_t max_outstanding_pkts_per_conn;
uint8_t max_connections;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f9c49254/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 26467bc..6f33430 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -39,26 +39,21 @@
#ifdef ARCH_sim
#define BLE_HS_STACK_SIZE (1024)
#else
-#define BLE_HS_STACK_SIZE (256)
+#define BLE_HS_STACK_SIZE (176)
#endif
static struct os_task ble_hs_task;
static os_stack_t ble_hs_stack[BLE_HS_STACK_SIZE] bssnz_t;
-#define HCI_CMD_BUFS (4)
#define HCI_CMD_BUF_SIZE (260) /* XXX: temporary, Fix later */
struct os_mempool g_hci_cmd_pool;
-static os_membuf_t g_hci_cmd_buf[OS_MEMPOOL_SIZE(HCI_CMD_BUFS,
- HCI_CMD_BUF_SIZE)] bssnz_t;
+static void *ble_hs_hci_cmd_buf;
/* XXX: this might be transport layer*/
-#define HCI_NUM_OS_EVENTS (HCI_CMD_BUFS)
#define HCI_OS_EVENT_BUF_SIZE (sizeof(struct os_event))
struct os_mempool g_hci_os_event_pool;
-static os_membuf_t
- g_hci_os_event_buf[OS_MEMPOOL_SIZE(HCI_NUM_OS_EVENTS,
- HCI_OS_EVENT_BUF_SIZE)] bssnz_t;
+static void *ble_hs_hci_os_event_buf;
/* Host HCI Task Events */
struct os_eventq ble_hs_evq;
@@ -205,6 +200,16 @@ ble_hs_kick_l2cap_sig(void)
os_eventq_put(&ble_hs_evq, &ble_hs_kick_l2cap_sig_ev);
}
+static void
+ble_hs_free_mem(void)
+{
+ free(ble_hs_hci_cmd_buf);
+ ble_hs_hci_cmd_buf = NULL;
+
+ free(ble_hs_hci_os_event_buf);
+ ble_hs_hci_os_event_buf = NULL;
+}
+
/**
* Initializes the host portion of the BLE stack.
*/
@@ -213,20 +218,36 @@ ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg)
{
int rc;
+ ble_hs_free_mem();
+
ble_hs_cfg_init(cfg);
os_task_init(&ble_hs_task, "ble_hs", ble_hs_task_handler, NULL, prio,
OS_WAIT_FOREVER, ble_hs_stack, BLE_HS_STACK_SIZE);
+ ble_hs_hci_cmd_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
+ HCI_CMD_BUF_SIZE));
+ if (ble_hs_hci_cmd_buf == NULL) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+
/* Create memory pool of command buffers */
- rc = os_mempool_init(&g_hci_cmd_pool, HCI_CMD_BUFS, HCI_CMD_BUF_SIZE,
- &g_hci_cmd_buf, "HCICmdPool");
+ rc = os_mempool_init(&g_hci_cmd_pool, ble_hs_cfg.max_hci_bufs,
+ HCI_CMD_BUF_SIZE, ble_hs_hci_cmd_buf,
+ "HCICmdPool");
assert(rc == 0);
- /* XXX: really only needed by the transport */
+ ble_hs_hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
+ HCI_OS_EVENT_BUF_SIZE));
+ if (ble_hs_hci_os_event_buf == NULL) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+
/* Create memory pool of OS events */
- rc = os_mempool_init(&g_hci_os_event_pool, HCI_NUM_OS_EVENTS,
- HCI_OS_EVENT_BUF_SIZE, &g_hci_os_event_buf,
+ rc = os_mempool_init(&g_hci_os_event_pool, ble_hs_cfg.max_hci_bufs,
+ HCI_OS_EVENT_BUF_SIZE, ble_hs_hci_os_event_buf,
"HCIOsEventPool");
assert(rc == 0);
@@ -237,41 +258,41 @@ ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg)
rc = ble_hs_conn_init();
if (rc != 0) {
- return rc;
+ goto err;
}
rc = ble_l2cap_init();
if (rc != 0) {
- return rc;
+ goto err;
}
ble_att_init();
rc = ble_att_svr_init();
if (rc != 0) {
- return rc;
+ goto err;
}
rc = ble_gap_init();
if (rc != 0) {
- return rc;
+ goto err;
}
ble_hci_ack_init();
rc = ble_hci_sched_init();
if (rc != 0) {
- return rc;
+ goto err;
}
rc = ble_gattc_init();
if (rc != 0) {
- return rc;
+ goto err;
}
rc = ble_gatts_init();
if (rc != 0) {
- return rc;
+ goto err;
}
ble_hs_kick_hci_ev.ev_queued = 0;
@@ -290,4 +311,8 @@ ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg)
os_mqueue_init(&ble_hs_tx_q, NULL);
return 0;
+
+err:
+ ble_hs_free_mem();
+ return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f9c49254/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index 9a4f0fb..d3873ac 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -20,6 +20,9 @@
#include "ble_hs_priv.h"
const struct ble_hs_cfg ble_hs_cfg_dflt = {
+ /** HCI settings. */
+ .max_hci_bufs = 8,
+
/** Connection settings. */
.max_outstanding_pkts_per_conn = 5,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/f9c49254/project/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/project/bletiny/src/main.c b/project/bletiny/src/main.c
index c1e2131..b822095 100755
--- a/project/bletiny/src/main.c
+++ b/project/bletiny/src/main.c
@@ -1316,6 +1316,7 @@ main(void)
/* Initialize the BLE host. */
cfg = ble_hs_cfg_dflt;
+ cfg.max_hci_bufs = 3;
cfg.max_connections = 1;
cfg.max_attrs = 32;
cfg.max_services = 4;