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/08/05 00:26:46 UTC

[1/6] incubator-mynewt-core git commit: eventq - os_eventq_poll() - Allow a timeout of 0.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 29b69ddf2 -> c483e8222


eventq - os_eventq_poll() - Allow a timeout of 0.

If the timeout is 0, don't involve the scheduler at all.  Grab an event
if one is available, else return immediately.


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

Branch: refs/heads/develop
Commit: 24b90c33a4bc6fb10110d3218e372d24dcff2ed9
Parents: 29b69dd
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 12:41:46 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 12:41:46 2016 -0700

----------------------------------------------------------------------
 libs/os/src/os_eventq.c        |  33 +++++++-
 libs/os/src/test/eventq_test.c | 149 +++++++++++++++++++++++-------------
 2 files changed, 125 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24b90c33/libs/os/src/os_eventq.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_eventq.c b/libs/os/src/os_eventq.c
index b3ff26f..f9cc283 100644
--- a/libs/os/src/os_eventq.c
+++ b/libs/os/src/os_eventq.c
@@ -117,6 +117,29 @@ pull_one:
     return (ev);
 }
 
+static struct os_event *
+os_eventq_poll_0timo(struct os_eventq **evq, int nevqs)
+{
+    struct os_event *ev;
+    os_sr_t sr;
+    int i;
+
+    ev = NULL;
+
+    OS_ENTER_CRITICAL(sr);
+    for (i = 0; i < nevqs; i++) {
+        ev = STAILQ_FIRST(&evq[i]->evq_list);
+        if (ev) {
+            STAILQ_REMOVE(&evq[i]->evq_list, ev, os_event, ev_next);
+            ev->ev_queued = 0;
+            break;
+        }
+    }
+    OS_EXIT_CRITICAL(sr);
+
+    return ev;
+}
+
 /**
  * Poll the list of event queues specified by the evq parameter 
  * (size nevqs), and return the "first" event available on any of 
@@ -137,6 +160,13 @@ os_eventq_poll(struct os_eventq **evq, int nevqs, os_time_t timo)
     int i, j;
     os_sr_t sr;
 
+    /* If the timeout is 0, don't involve the scheduler at all.  Grab an event
+     * if one is available, else return immediately.
+     */
+    if (timo == 0) {
+        return os_eventq_poll_0timo(evq, nevqs);
+    }
+
     ev = NULL;
 
     OS_ENTER_CRITICAL(sr);
@@ -147,8 +177,7 @@ os_eventq_poll(struct os_eventq **evq, int nevqs, os_time_t timo)
         if (ev) {
             STAILQ_REMOVE(&evq[i]->evq_list, ev, os_event, ev_next);
             ev->ev_queued = 0;
-            /* Reset the items that already have an evq task set
-             */
+            /* Reset the items that already have an evq task set. */
             for (j = 0; j < i; j++) {
                 evq[j]->evq_task = NULL;
             }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24b90c33/libs/os/src/test/eventq_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/eventq_test.c b/libs/os/src/test/eventq_test.c
index f17e5e4..cb1ed94 100644
--- a/libs/os/src/test/eventq_test.c
+++ b/libs/os/src/test/eventq_test.c
@@ -17,7 +17,7 @@
  * under the License.
  */
  
-
+#include <string.h>
 #include "testutil/testutil.h"
 #include "os/os.h"
 #include "os_test_priv.h"
@@ -59,10 +59,6 @@ os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];
 struct os_task eventq_task_poll_r;
 os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];
 
-struct os_eventq *poll_eventq[POLL_STACK_SIZE];
-struct os_eventq p_event[POLL_STACK_SIZE];
-struct os_event poll_event[POLL_STACK_SIZE];
-
 /* Setting the data for the poll timeout */
 /* Define the task stack for the eventq_task_poll_timeout_send */
 #define SEND_TASK_POLL_TIMEOUT_PRIO        (5)
@@ -74,10 +70,6 @@ os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];
 struct os_task eventq_task_poll_timeout_r;
 os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];
 
-struct os_eventq *poll_eventq_timeout[POLL_STACK_SIZE];
-struct os_eventq p_event_timeout[POLL_STACK_SIZE];
-struct os_event poll_event_timeout[POLL_STACK_SIZE];
-
 /* Setting the data for the poll single */
 /* Define the task stack for the eventq_task_poll_single_send */
 #define SEND_TASK_POLL_SINGLE_PRIO        (7)
@@ -89,10 +81,6 @@ os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
 struct os_task eventq_task_poll_single_r;
 os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
 
-struct os_eventq *poll_eventq_single[POLL_STACK_SIZE];
-struct os_eventq p_event_single[POLL_STACK_SIZE];
-struct os_event poll_event_single[POLL_STACK_SIZE];
-
 /* This is the task function  to send data */
 void
 eventq_task_send(void *arg)
@@ -143,24 +131,19 @@ eventq_task_receive(void *arg)
 void
 eventq_task_poll_send(void *arg)
 {
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
     int i;
 
-    /* Assigning the *poll_eventq[] */
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        poll_eventq[i] = &p_event[i];
+        eventqs[i] = &multi_eventq[i];
     }
 
-    /* Initializing the *poll_eventq */
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        os_eventq_init(poll_eventq[i]);
-    }
-
-    for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        poll_event[i].ev_type = i + 10;
-        poll_event[i].ev_arg = NULL;
+        m_event[i].ev_type = i + 10;
+        m_event[i].ev_arg = NULL;
 
         /* Put and send */
-        os_eventq_put(poll_eventq[i], &poll_event[i]);
+        os_eventq_put(eventqs[i], &m_event[i]);
         os_time_delay(OS_TICKS_PER_SEC / 2);
     }
 
@@ -171,12 +154,17 @@ eventq_task_poll_send(void *arg)
 void
 eventq_task_poll_receive(void *arg)
 {
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
     struct os_event *event;
     int i;
 
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
     /* Recieving using the os_eventq_poll*/
     for (i = 0; i < SIZE_MULTI_EVENT; i++) {
-        event = os_eventq_poll(poll_eventq, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
+        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
         TEST_ASSERT(event->ev_type == i +10);
     }
 
@@ -189,26 +177,18 @@ eventq_task_poll_receive(void *arg)
 void
 eventq_task_poll_timeout_send(void *arg)
 {
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
     int i;
 
-    /* Assigning the *poll_eventq_timeout[] */
-    for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        poll_eventq_timeout[i] = &p_event_timeout[i];
-    }
-
-    /* Initializing the *poll_eventq_timeout */
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        os_eventq_init(poll_eventq_timeout[i]);
+        eventqs[i] = &multi_eventq[i];
     }
 
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
          os_time_delay(1000);
 
-        poll_event_timeout[i].ev_type = i + 10;
-        poll_event_timeout[i].ev_arg = NULL;
-
         /* Put and send */
-        os_eventq_put(poll_eventq_timeout[i], &poll_event_timeout[i]);
+        os_eventq_put(eventqs[i], &m_event[i]);
         os_time_delay(OS_TICKS_PER_SEC / 2);
     }
 
@@ -221,12 +201,17 @@ eventq_task_poll_timeout_send(void *arg)
 void
 eventq_task_poll_timeout_receive(void *arg)
 {
-     struct os_event *event;
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *event;
     int i;
 
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
     /* Recieving using the os_eventq_poll_timeout*/
     for (i = 0; i < SIZE_MULTI_EVENT; i++) {
-        event = os_eventq_poll(poll_eventq_timeout, SIZE_MULTI_EVENT, 200);
+        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 200);
         TEST_ASSERT(event == NULL);
     }
 
@@ -239,45 +224,40 @@ eventq_task_poll_timeout_receive(void *arg)
 void
 eventq_task_poll_single_send(void *arg)
 {
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
     int i;
     int position = 2;
 
-    /* Assigning the *poll_eventq_single */
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        poll_eventq_single[i] = &p_event_single[i];
+        eventqs[i] = &multi_eventq[i];
     }
 
-    /* Initializing the *poll_eventq_single */
-    for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        os_eventq_init(poll_eventq_single[i]);
-    }
-
-    poll_event_single[position].ev_type = 20;
-    poll_event_single[position].ev_arg = NULL;
-
-        /* Put and send */
-        os_eventq_put(poll_eventq_single[position],
-            &poll_event_single[position]);
-        os_time_delay(OS_TICKS_PER_SEC / 2);
+    /* Put and send */
+    os_eventq_put(eventqs[position], &m_event[position]);
+    os_time_delay(OS_TICKS_PER_SEC / 2);
 
     /* This task sleeps until the receive task completes the test. */
     os_time_delay(1000000);
-
 }
 
 /* Recieving the single event */
 void
 eventq_task_poll_single_receive(void *arg)
 {
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
     struct os_event *event;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
 
     /* Recieving using the os_eventq_poll*/
-    event = os_eventq_poll(poll_eventq_single, SIZE_MULTI_EVENT,  OS_WAIT_FOREVER);
+    event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
     TEST_ASSERT(event->ev_type == 20);
 
     /* Finishes the test when OS has been started */
     os_test_restart();
-
 }
 
 TEST_CASE(event_test_sr)
@@ -309,6 +289,8 @@ TEST_CASE(event_test_sr)
 /* To test for the basic function of os_eventq_poll() */
 TEST_CASE(event_test_poll_sr)
 {
+    int i;
+
     /* Initializing the OS */
     os_init();
     /* Initialize the task */
@@ -321,6 +303,11 @@ TEST_CASE(event_test_poll_sr)
         NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
         POLL_STACK_SIZE);
 
+    /* Initializing the eventqs. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+    }
+
     /* Does not return until OS_restart is called */
     os_start();
 
@@ -329,6 +316,8 @@ TEST_CASE(event_test_poll_sr)
 /* Test case for poll timeout */
 TEST_CASE(event_test_poll_timeout_sr)
 {
+    int i;
+
     /* Initializing the OS */
     os_init();
     /* Initialize the task */
@@ -341,6 +330,14 @@ TEST_CASE(event_test_poll_timeout_sr)
         eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
         OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);
 
+    /* Initializing the eventqs. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+
+        m_event[i].ev_type = i + 10;
+        m_event[i].ev_arg = NULL;
+    }
+
     /* Does not return until OS_restart is called */
     os_start();
 
@@ -350,6 +347,8 @@ TEST_CASE(event_test_poll_timeout_sr)
 /* Test case for poll timeout */
 TEST_CASE(event_test_poll_single_sr)
 {
+    int i;
+
     /* Initializing the OS */
     os_init();
     /* Initialize the task */
@@ -362,16 +361,56 @@ TEST_CASE(event_test_poll_single_sr)
         eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
         OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);
 
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+
+        m_event[i].ev_type = 10 * i;
+        m_event[i].ev_arg = NULL;
+    }
+
     /* Does not return until OS_restart is called */
     os_start();
 
 }
 
+/**
+ * Tests eventq_poll() with a timeout of 0.  This should not involve the
+ * scheduler at all, so it should work without starting the OS.
+ */
+TEST_CASE(event_test_poll_0timo)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *evp;
+    struct os_event ev;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+    TEST_ASSERT(evp == NULL);
+
+    /* Ensure no eventq thinks a task is waiting on it. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+        TEST_ASSERT(eventqs[i]->evq_task == NULL);
+    }
+
+    /* Put an event on one of the queues. */
+    memset(&ev, 0, sizeof ev);
+    ev.ev_type = 1;
+    os_eventq_put(eventqs[3], &ev);
+
+    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+    TEST_ASSERT(evp == &ev);
+}
+
 TEST_SUITE(os_eventq_test_suite)
 {
     event_test_sr();
     event_test_poll_sr();
     event_test_poll_timeout_sr();
     event_test_poll_single_sr();
-
+    event_test_poll_0timo();
 }


[4/6] incubator-mynewt-core git commit: mempool - Allow mempool with 0 blocks.

Posted by cc...@apache.org.
mempool - Allow mempool with 0 blocks.

This is useful in cases when the mempool is sized according to an
application setting.  If the user wants 0 of something, it is easier to
just initialize the mempool with 0 blocks and a NULL buffer, and just
let any attempt to allocate from it to fail.


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

Branch: refs/heads/develop
Commit: 9d5aa01d3e1e46a4a78365c45680c8693747235c
Parents: 4965b05
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:24:47 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 16:24:47 2016 -0700

----------------------------------------------------------------------
 libs/os/src/os_mempool.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9d5aa01d/libs/os/src/os_mempool.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mempool.c b/libs/os/src/os_mempool.c
index 04a18a1..e940ba4 100644
--- a/libs/os/src/os_mempool.c
+++ b/libs/os/src/os_mempool.c
@@ -41,21 +41,29 @@ STAILQ_HEAD(, os_mempool) g_os_mempool_list =
  * @return os_error_t 
  */
 os_error_t
-os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
-                char *name)
+os_mempool_init(struct os_mempool *mp, int blocks, int block_size,
+                void *membuf, char *name)
 {
     int true_block_size;
     uint8_t *block_addr;
     struct os_memblock *block_ptr;
 
     /* Check for valid parameters */
-    if ((!mp) || (!membuf) || (blocks <= 0) || (block_size <= 0)) {
+    if ((!mp) || (blocks < 0) || (block_size <= 0)) {
         return OS_INVALID_PARM;
     }
 
-    /* Blocks need to be sized properly and memory buffer should be aligned */
-    if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) {
-        return OS_MEM_NOT_ALIGNED;
+    if ((!membuf) && (blocks != 0)) {
+        return OS_INVALID_PARM;
+    }
+
+    if (membuf != NULL) {
+        /* Blocks need to be sized properly and memory buffer should be
+         * aligned
+         */
+        if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) {
+            return OS_MEM_NOT_ALIGNED;
+        }
     }
     true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(block_size);
 


[2/6] incubator-mynewt-core git commit: BLE Host - Use os_eventq_poll()

Posted by cc...@apache.org.
BLE Host - Use os_eventq_poll()

Before, the host code implemented an eventq "peek" operation:
* disable interrupts
* check whether anything is on the eventq
* enable interrupts
* if something was on the queue, call os_eventq_get().

Unlike os_eventq_get(), os_eventq_poll() takes a timeout parameter.  Now
the host calls os_eventq_poll() with a timeout of 0 to perform a
non-blocking read of the eventq.


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

Branch: refs/heads/develop
Commit: b187e6dc21e87ce3f4592786506793f132779c06
Parents: 24b90c3
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 13:39:25 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 13:39:25 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b187e6dc/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 8035b49..225b26c 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -330,17 +330,19 @@ static void
 ble_hs_event_handle(void *unused)
 {
     struct os_callout_func *cf;
+    struct os_eventq *evqp;
     struct os_event *ev;
     uint8_t *hci_evt;
-    os_sr_t sr;
     int rc;
     int i;
 
+    evqp = &ble_hs_evq;
+
     i = 0;
     while (1) {
         /* If the host has already processed several consecutive events, stop
          * and return control to the parent task.  Put an event on the parent
-         * task's eventq so indicate that more host events are enqueued.
+         * task's eventq to indicate that more host events are enqueued.
          */
         if (i >= BLE_HS_MAX_EVS_IN_A_ROW) {
             os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
@@ -348,15 +350,11 @@ ble_hs_event_handle(void *unused)
         }
         i++;
 
-        OS_ENTER_CRITICAL(sr);
-        ev = STAILQ_FIRST(&ble_hs_evq.evq_list);
-        OS_EXIT_CRITICAL(sr);
-
+        ev = os_eventq_poll(&evqp, 1, 0);
         if (ev == NULL) {
             break;
         }
 
-        ev = os_eventq_get(&ble_hs_evq);
         switch (ev->ev_type) {
         case OS_EVENT_T_TIMER:
             cf = (struct os_callout_func *)ev;


[5/6] incubator-mynewt-core git commit: NimBLE - high / low prio event buffers.

Posted by cc...@apache.org.
NimBLE - high / low prio event buffers.

Events have one of two priorities:
o Low-priority   (BLE_HCI_TRANS_BUF_EVT_LO)
o High-priority  (BLE_HCI_TRANS_BUF_EVT_HI)

Low-priority event buffers are only used for advertising reports.  If
there are no free low-priority event buffers, then an incoming
advertising report will get dropped.

High-priority event buffers are for everything except advertising
reports.  If there are no free high-priority event buffers, a request to
allocate one will try to allocate a low-priority buffer instead.

If you want all events to be given equal treatment, then you should
allocate low-priority events only.

Event priorities solve the problem of critical events getting dropped
due to a flood of advertising reports.  This solution is likely
temporary: when HCI flow control is added, event priorities may become
obsolete.

Not all transports distinguish between low and high priority events.  If
the transport does not have separate settings for low and high buffer
counts, then it treats all events with equal priority.


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

Branch: refs/heads/develop
Commit: f8922493a9751ecf6618595f4b126e6449cfb21a
Parents: 9d5aa01
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:31:05 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 16:31:05 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/test/ble_hs_test_util.c     |  1 -
 net/nimble/include/nimble/ble_hci_trans.h       | 27 ++++--
 .../ram/include/transport/ram/ble_hci_ram.h     | 17 +++-
 net/nimble/transport/ram/src/ble_hci_ram.c      | 95 +++++++++++++++-----
 4 files changed, 110 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f8922493/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index cfb86fa..4f1c706 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -1382,7 +1382,6 @@ ble_hs_test_util_init(void)
                          ble_hs_test_util_pkt_txed, NULL);
 
     hci_cfg = ble_hci_ram_cfg_dflt;
-    hci_cfg.num_evt_bufs = cfg.max_hci_bufs;
     rc = ble_hci_ram_init(&hci_cfg);
     TEST_ASSERT_FATAL(rc == 0);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f8922493/net/nimble/include/nimble/ble_hci_trans.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble_hci_trans.h b/net/nimble/include/nimble/ble_hci_trans.h
index 822da96..3e2ec7a 100644
--- a/net/nimble/include/nimble/ble_hci_trans.h
+++ b/net/nimble/include/nimble/ble_hci_trans.h
@@ -27,13 +27,30 @@ struct os_mbuf;
 
 /*** Type of buffers for holding commands and events. */
 /**
- * Low-priority event (advertising reports).  A request to allocate a
- * high-priority event buffer may allocate one of these instead if no
- * high-priority buffers are available.
+ * Controller-to-host event buffers.  Events have one of two priorities:
+ * o Low-priority   (BLE_HCI_TRANS_BUF_EVT_LO)
+ * o High-priority  (BLE_HCI_TRANS_BUF_EVT_HI)
+ *
+ * Low-priority event buffers are only used for advertising reports.  If there
+ * are no free low-priority event buffers, then an incoming advertising report
+ * will get dropped.
+ *
+ * High-priority event buffers are for everything except advertising reports.
+ * If there are no free high-priority event buffers, a request to allocate one
+ * will try to allocate a low-priority buffer instead.
+ *
+ * If you want all events to be given equal treatment, then you should allocate
+ * low-priority events only.
+ *
+ * Event priorities solve the problem of critical events getting dropped due to
+ * a flood of advertising reports.  This solution is likely temporary: when
+ * HCI flow control is added, event priorities may become obsolete.
+ *
+ * Not all transports distinguish between low and high priority events.  If the
+ * transport does not have separate settings for low and high buffer counts,
+ * then it treats all events with equal priority.
  */
 #define BLE_HCI_TRANS_BUF_EVT_LO    1
-
-/* High-priority event (all events except advertising reports). */
 #define BLE_HCI_TRANS_BUF_EVT_HI    2
 
 /* Host-to-controller command. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f8922493/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
index 1c5b58e..9d2d672 100644
--- a/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
+++ b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
@@ -4,8 +4,23 @@
 #include "nimble/ble_hci_trans.h"
 
 struct ble_hci_ram_cfg {
-    uint16_t num_evt_bufs;
+    /** Number of high-priority event buffers. */
+    uint16_t num_evt_hi_bufs;
+
+    /** Number of low-priority event buffers. */
+    uint16_t num_evt_lo_bufs;
+
+    /** Size of each event buffer, in bytes. */
     uint16_t evt_buf_sz;
+
+    /* Note: For information about high-priority vs. low-priority event
+     * buffers, see net/nimble/include/nimble/ble_hci_trans.h.
+     */
+
+    /* Note: host-to-controller command buffers are not configurable.  The RAM
+     * transport only allows one outstanding command, so it uses a single
+     * statically-allocated buffer.
+     */
 };
 
 extern const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f8922493/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index aac5eb1..23a375d 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -7,7 +7,8 @@
 
 /** Default configuration. */
 const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt = {
-    .num_evt_bufs = 3,
+    .num_evt_hi_bufs = 1,
+    .num_evt_lo_bufs = 2,
     .evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
 };
 
@@ -23,17 +24,19 @@ static void *ble_hci_ram_rx_acl_hs_arg;
 static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_ll_cb;
 static void *ble_hci_ram_rx_acl_ll_arg;
 
-static struct os_mempool ble_hci_ram_evt_pool;
-static void *ble_hci_ram_evt_buf;
+static struct os_mempool ble_hci_ram_evt_hi_pool;
+static void *ble_hci_ram_evt_hi_buf;
+static struct os_mempool ble_hci_ram_evt_lo_pool;
+static void *ble_hci_ram_evt_lo_buf;
 
 static uint8_t *ble_hci_ram_hs_cmd_buf;
 static uint8_t ble_hci_ram_hs_cmd_buf_alloced;
 
 void
 ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                                void *cmd_arg,
-                                ble_hci_trans_rx_acl_fn *acl_cb,
-                                void *acl_arg)
+                     void *cmd_arg,
+                     ble_hci_trans_rx_acl_fn *acl_cb,
+                     void *acl_arg)
 {
     ble_hci_ram_rx_cmd_hs_cb = cmd_cb;
     ble_hci_ram_rx_cmd_hs_arg = cmd_arg;
@@ -43,9 +46,9 @@ ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
 
 void
 ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
-                                void *cmd_arg,
-                                ble_hci_trans_rx_acl_fn *acl_cb,
-                                void *acl_arg)
+                     void *cmd_arg,
+                     ble_hci_trans_rx_acl_fn *acl_cb,
+                     void *acl_arg)
 {
     ble_hci_ram_rx_cmd_ll_cb = cmd_cb;
     ble_hci_ram_rx_cmd_ll_arg = cmd_arg;
@@ -78,7 +81,7 @@ ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
 int
 ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
 {
-    int rc;
+   int rc;
 
     assert(ble_hci_ram_rx_acl_ll_cb != NULL);
 
@@ -103,9 +106,18 @@ ble_hci_trans_buf_alloc(int type)
     uint8_t *buf;
 
     switch (type) {
-    case BLE_HCI_TRANS_BUF_EVT_LO:
     case BLE_HCI_TRANS_BUF_EVT_HI:
-        buf = os_memblock_get(&ble_hci_ram_evt_pool);
+        buf = os_memblock_get(&ble_hci_ram_evt_hi_pool);
+        if (buf == NULL) {
+            /* If no high-priority event buffers remain, try to grab a
+             * low-priority one.
+             */
+            buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+        }
+        break;
+
+    case BLE_HCI_TRANS_BUF_EVT_LO:
+        buf = os_memblock_get(&ble_hci_ram_evt_lo_pool);
         break;
 
     case BLE_HCI_TRANS_BUF_CMD:
@@ -130,8 +142,12 @@ ble_hci_trans_buf_free(uint8_t *buf)
     if (buf == ble_hci_ram_hs_cmd_buf) {
         assert(ble_hci_ram_hs_cmd_buf_alloced);
         ble_hci_ram_hs_cmd_buf_alloced = 0;
+    } else if (os_memblock_from(&ble_hci_ram_evt_hi_pool, buf)) {
+        rc = os_memblock_put(&ble_hci_ram_evt_hi_pool, buf);
+        assert(rc == 0);
     } else {
-        rc = os_memblock_put(&ble_hci_ram_evt_pool, buf);
+        assert(os_memblock_from(&ble_hci_ram_evt_lo_pool, buf));
+        rc = os_memblock_put(&ble_hci_ram_evt_lo_pool, buf);
         assert(rc == 0);
     }
 }
@@ -139,8 +155,11 @@ ble_hci_trans_buf_free(uint8_t *buf)
 static void
 ble_hci_ram_free_mem(void)
 {
-    free(ble_hci_ram_evt_buf);
-    ble_hci_ram_evt_buf = NULL;
+    free(ble_hci_ram_evt_hi_buf);
+    ble_hci_ram_evt_hi_buf = NULL;
+
+    free(ble_hci_ram_evt_lo_buf);
+    ble_hci_ram_evt_lo_buf = NULL;
 
     free(ble_hci_ram_hs_cmd_buf);
     ble_hci_ram_hs_cmd_buf = NULL;
@@ -150,9 +169,21 @@ ble_hci_ram_free_mem(void)
 int
 ble_hci_trans_reset(void)
 {
+    /* No work to do.  All allocated buffers are owned by the host or
+     * controller, and they will get freed by their owners.
+     */
     return 0;
 }
 
+/**
+ * Initializes the RAM HCI transport module.
+ *
+ * @param cfg                   The settings to initialize the HCI RAM
+ *                                  transport with.
+ *
+ * @return                      0 on success;
+ *                              A BLE_ERR_[...] error code on failure.
+ */
 int
 ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
 {
@@ -160,17 +191,35 @@ ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
 
     ble_hci_ram_free_mem();
 
-    ble_hci_ram_evt_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_bufs,
-                                                  cfg->evt_buf_sz));
-    if (ble_hci_ram_evt_buf == NULL) {
-        rc = ENOMEM;
+    if (cfg->num_evt_hi_bufs > 0) {
+        ble_hci_ram_evt_hi_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_hi_bufs,
+                                                         cfg->evt_buf_sz));
+        if (ble_hci_ram_evt_hi_buf == NULL) {
+            rc = ENOMEM;
+            goto err;
+        }
+    }
+
+    rc = os_mempool_init(&ble_hci_ram_evt_hi_pool, cfg->num_evt_hi_bufs,
+                         cfg->evt_buf_sz, ble_hci_ram_evt_hi_buf,
+                         "ble_hci_ram_evt_hi_pool");
+    if (rc != 0) {
+        rc = EINVAL;
         goto err;
     }
 
-    /* Create memory pool of command buffers */
-    rc = os_mempool_init(&ble_hci_ram_evt_pool, cfg->num_evt_bufs,
-                         cfg->evt_buf_sz, ble_hci_ram_evt_buf,
-                         "ble_hci_ram_evt_pool");
+    if (cfg->num_evt_lo_bufs > 0) {
+        ble_hci_ram_evt_lo_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_lo_bufs,
+                                                         cfg->evt_buf_sz));
+        if (ble_hci_ram_evt_lo_buf == NULL) {
+            rc = ENOMEM;
+            goto err;
+        }
+    }
+
+    rc = os_mempool_init(&ble_hci_ram_evt_lo_pool, cfg->num_evt_lo_bufs,
+                         cfg->evt_buf_sz, ble_hci_ram_evt_lo_buf,
+                         "ble_hci_ram_evt_lo_pool");
     if (rc != 0) {
         rc = EINVAL;
         goto err;


[6/6] incubator-mynewt-core git commit: BLE apps - Update for latest HCI transport changes

Posted by cc...@apache.org.
BLE apps - Update for latest HCI transport changes


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

Branch: refs/heads/develop
Commit: c483e82226001714213fa57227a4d79625133ef3
Parents: f892249
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:31:33 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 16:31:33 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c |  7 ++++---
 apps/bletest/src/main.c |  3 +++
 apps/bletiny/src/main.c |  4 ++--
 apps/bleuart/src/main.c | 17 ++++++++++++-----
 4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c483e822/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index cff4763..9d75a66 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -390,6 +390,10 @@ main(void)
     rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
     assert(rc == 0);
 
+    /* Initialize the RAM HCI transport. */
+    rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+    assert(rc == 0);
+
     /* Initialize the NimBLE host configuration. */
     cfg = ble_hs_cfg_dflt;
     cfg.max_gattc_procs = 2;
@@ -419,9 +423,6 @@ main(void)
     rc = ble_hs_init(&bleprph_evq, &cfg);
     assert(rc == 0);
 
-    rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
-    assert(rc == 0);
-
     nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
     imgmgr_module_init();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c483e822/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index be0cf6d..c2635dd 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -44,6 +44,8 @@
 #include "controller/ble_ll_conn.h"
 #include "controller/ble_ll_scan.h"
 #include "controller/ble_ll_adv.h"
+
+/* RAM HCI transport. */
 #include "transport/ram/ble_hci_ram.h"
 
 /* XXX: An app should not include private headers from a library.  The bletest
@@ -1154,6 +1156,7 @@ main(void)
     rc = ble_hs_init(&g_bletest_evq, NULL);
     assert(rc == 0);
 
+    /* Initialize the RAM HCI transport. */
     rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
     assert(rc == 0);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c483e822/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 38ee467..dbb340b 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -45,6 +45,8 @@
 #include "host/ble_gatt.h"
 #include "host/ble_store.h"
 #include "host/ble_sm.h"
+
+/* RAM HCI transport. */
 #include "transport/ram/ble_hci_ram.h"
 
 /* RAM persistence layer. */
@@ -1697,13 +1699,11 @@ main(void)
 
     /* Initialize the RAM HCI transport. */
     hci_cfg = ble_hci_ram_cfg_dflt;
-    hci_cfg.num_evt_bufs = 3;
     rc = ble_hci_ram_init(&hci_cfg);
     assert(rc == 0);
 
     /* Initialize the NimBLE host configuration. */
     cfg = ble_hs_cfg_dflt;
-    cfg.max_hci_bufs = hci_cfg.num_evt_bufs;
     cfg.max_gattc_procs = 2;
     cfg.reset_cb = bletiny_on_reset;
     cfg.store_read_cb = ble_store_ram_read;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c483e822/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index f7c7714..a530195 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -39,10 +39,9 @@
 #include "host/ble_l2cap.h"
 #include "host/ble_sm.h"
 #include "controller/ble_ll.h"
-/* Newtmgr include */
-#include "newtmgr/newtmgr.h"
-#include "nmgrble/newtmgr_ble.h"
-#include "bleuart/bleuart.h"
+
+/* RAM HCI transport. */
+#include "transport/ram/ble_hci_ram.h"
 
 /* RAM persistence layer. */
 #include "store/ram/ble_store_ram.h"
@@ -51,6 +50,11 @@
 #include "services/mandatory/ble_svc_gap.h"
 #include "services/mandatory/ble_svc_gatt.h"
 
+/* Newtmgr include */
+#include "newtmgr/newtmgr.h"
+#include "nmgrble/newtmgr_ble.h"
+#include "bleuart/bleuart.h"
+
 /** Mbuf settings. */
 #define MBUF_NUM_MBUFS      (12)
 #define MBUF_BUF_SIZE       OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
@@ -292,9 +296,12 @@ main(void)
     rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
     assert(rc == 0);
 
+    /* Initialize the RAM HCI transport. */
+    rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+    assert(rc == 0);
+
     /* Initialize the BLE host. */
     cfg = ble_hs_cfg_dflt;
-    cfg.max_hci_bufs = 3;
     cfg.max_connections = 1;
     cfg.max_gattc_procs = 2;
     cfg.max_l2cap_chans = 3;


[3/6] incubator-mynewt-core git commit: mempool - fn to check if block came from pool.

Posted by cc...@apache.org.
mempool - fn to check if block came from 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/4965b05c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4965b05c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4965b05c

Branch: refs/heads/develop
Commit: 4965b05c5f6c469fc356c195e3bfe0da50385f96
Parents: b187e6d
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:24:14 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Aug 4 16:24:14 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_mempool.h |  3 ++
 libs/os/src/os_mempool.c        | 54 ++++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4965b05c/libs/os/include/os/os_mempool.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mempool.h b/libs/os/include/os/os_mempool.h
index 6b0f24c..a731618 100644
--- a/libs/os/include/os/os_mempool.h
+++ b/libs/os/include/os/os_mempool.h
@@ -82,6 +82,9 @@ typedef uint64_t os_membuf_t;
 os_error_t os_mempool_init(struct os_mempool *mp, int blocks, int block_size, 
                            void *membuf, char *name);
 
+/* Checks if a memory block was allocated from the specified mempool. */
+int os_memblock_from(struct os_mempool *mp, void *block_addr);
+
 /* Get a memory block from the pool */
 void *os_memblock_get(struct os_mempool *mp);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4965b05c/libs/os/src/os_mempool.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mempool.c b/libs/os/src/os_mempool.c
index 1e7428c..04a18a1 100644
--- a/libs/os/src/os_mempool.c
+++ b/libs/os/src/os_mempool.c
@@ -86,6 +86,42 @@ os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
 }
 
 /**
+ * Checks if a memory block was allocated from the specified mempool.
+ *
+ * @param mp                    The mempool to check as parent.
+ * @param block_addr            The memory block to check as child.
+ *
+ * @return                      0 if the block does not belong to the mempool;
+ *                              1 if the block does belong to the mempool.
+ */
+int
+os_memblock_from(struct os_mempool *mp, void *block_addr)
+{
+    uint32_t true_block_size;
+    uint32_t baddr32;
+    uint32_t end;
+
+    _Static_assert(sizeof block_addr == sizeof baddr32,
+                   "Pointer to void must be 32-bits.");
+
+    baddr32 = (uint32_t)block_addr;
+    true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp->mp_block_size);
+    end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size);
+
+    /* Check that the block is in the memory buffer range. */
+    if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) {
+        return 0;
+    }
+
+    /* All freed blocks should be on true block size boundaries! */
+    if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) {
+        return 0;
+    }
+
+    return 1;
+}
+
+/**
  * os memblock get 
  *  
  * Get a memory block from a memory pool 
@@ -135,9 +171,6 @@ os_error_t
 os_memblock_put(struct os_mempool *mp, void *block_addr)
 {
     os_sr_t sr;
-    uint32_t end;
-    uint32_t true_block_size;
-    uint32_t baddr32;
     struct os_memblock *block;
 
     /* Make sure parameters are valid */
@@ -146,23 +179,10 @@ os_memblock_put(struct os_mempool *mp, void *block_addr)
     }
 
     /* Check that the block we are freeing is a valid block! */
-    baddr32 = (uint32_t)block_addr;
-    true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp->mp_block_size);
-    end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size);
-    if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) {
-        return OS_INVALID_PARM;
-    }
-
-    /* All freed blocks should be on true block size boundaries! */
-    if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) {
+    if (!os_memblock_from(mp, block_addr)) {
         return OS_INVALID_PARM;
     }
 
-    /* 
-     * XXX: we should do boundary checks here! The block had better be within 
-     * the pool. If it fails, do we return an error or assert()? Add this when 
-     * we add the memory debug. 
-     */ 
     block = (struct os_memblock *)block_addr;
     OS_ENTER_CRITICAL(sr);