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/11/01 17:16:44 UTC

[01/11] incubator-mynewt-core git commit: Replace os_event types with callback functions.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 9c8786439 -> 1242fddde


Replace os_event types with callback functions.

All scheduled events contain a pointer to a callback function.  When a
task dequeues an event, it just executes the callback.  Before this
change, the task would inspect the event type and use it to decide what
action to take.

The reason for this change is to allow "taskless" packages to seamlessly
use any task's eventq.  With event codes, there would be conflicts in
the global event ID number space.


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

Branch: refs/heads/develop
Commit: 918811f826f9308e0b0b5abb0c0328be3c4dc6f4
Parents: 9c87864
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 08:55:14 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:04:57 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c           |   3 +-
 hw/mcu/native/src/hal_timer.c     |  39 ++++--------
 kernel/os/include/os/os_callout.h |  13 +---
 kernel/os/include/os/os_eventq.h  |  18 +++---
 kernel/os/include/os/os_mbuf.h    |   2 +-
 kernel/os/src/os_callout.c        |  30 ++++-----
 kernel/os/src/os_eventq.c         |  64 ++++++++++++++++++-
 kernel/os/src/os_mbuf.c           |   4 +-
 net/nimble/host/pkg.yml           |   5 +-
 net/nimble/host/src/ble_hs.c      | 108 ++++++++++++---------------------
 10 files changed, 145 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index e650ca1..e9a99e0 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -301,6 +301,8 @@ main(void)
     /* Set initial BLE device address. */
     memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
 
+    ble_hs_cfg.parent_evq = &bleprph_evq;
+
     /* Initialize OS */
     sysinit();
 
@@ -319,7 +321,6 @@ main(void)
 
     /* Initialize the NimBLE host configuration. */
     log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-    ble_hs_cfg.parent_evq = &bleprph_evq;
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;
     ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/hw/mcu/native/src/hal_timer.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_timer.c b/hw/mcu/native/src/hal_timer.c
index 8d4a8ca..6947123 100644
--- a/hw/mcu/native/src/hal_timer.c
+++ b/hw/mcu/native/src/hal_timer.c
@@ -32,7 +32,7 @@ static struct os_task native_timer_task_struct;
 static struct os_eventq native_timer_evq;
 
 struct native_timer {
-    struct os_callout_func callout;
+    struct os_callout callout;
     uint32_t ticks_per_ostick;
     uint32_t cnt;
     uint32_t last_ostime;
@@ -45,10 +45,10 @@ struct native_timer {
  *
  * @param arg
  */
-void
-native_timer_cb(void *arg)
+static void
+native_timer_cb(struct os_event *ev)
 {
-    struct native_timer *nt = (struct native_timer *)arg;
+    struct native_timer *nt = (struct native_timer *)ev->ev_arg;
     uint32_t cnt;
     struct hal_timer *ht;
     os_sr_t sr;
@@ -66,30 +66,17 @@ native_timer_cb(void *arg)
     }
     ht = TAILQ_FIRST(&nt->timers);
     if (ht) {
-        os_callout_reset(&nt->callout.cf_c,
+        os_callout_reset(&nt->callout,
           (ht->expiry - hal_timer_read(nt->num)) / nt->ticks_per_ostick);
     }
     OS_EXIT_CRITICAL(sr);
 }
 
-void
+static void
 native_timer_task(void *arg)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
-
     while (1) {
-        ev = os_eventq_get(&native_timer_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&native_timer_evq);
     }
 }
 
@@ -132,7 +119,7 @@ hal_timer_init(int num, uint32_t clock_freq)
     }
 
     /* Initialize the callout function */
-    os_callout_func_init(&nt->callout, &native_timer_evq, native_timer_cb, nt);
+    os_callout_init(&nt->callout, &native_timer_evq, native_timer_cb, nt);
 
     return 0;
 }
@@ -147,7 +134,7 @@ hal_timer_deinit(int num)
     }
     nt = &native_timers[num];
 
-    os_callout_stop(&nt->callout.cf_c);
+    os_callout_stop(&nt->callout);
     return 0;
 }
 
@@ -323,11 +310,11 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
         /*
          * Event in the past (should be the case if it was just inserted).
          */
-        os_callout_reset(&nt->callout.cf_c, 0);
+        os_callout_reset(&nt->callout, 0);
     } else {
         if (timer == TAILQ_FIRST(&nt->timers)) {
             osticks = (tick - curtime) / nt->ticks_per_ostick;
-            os_callout_reset(&nt->callout.cf_c, osticks);
+            os_callout_reset(&nt->callout, osticks);
         }
     }
     OS_EXIT_CRITICAL(sr);
@@ -366,11 +353,11 @@ hal_timer_stop(struct hal_timer *timer)
         timer->link.tqe_prev = NULL;
         if (reset_ocmp) {
             if (ht) {
-                os_callout_reset(&nt->callout.cf_c,
+                os_callout_reset(&nt->callout,
                   (ht->expiry - hal_timer_read(nt->num) /
                     nt->ticks_per_ostick));
             } else {
-                os_callout_stop(&nt->callout.cf_c);
+                os_callout_stop(&nt->callout);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/include/os/os_callout.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_callout.h b/kernel/os/include/os/os_callout.h
index 59333be..a56654f 100644
--- a/kernel/os/include/os/os_callout.h
+++ b/kernel/os/include/os/os_callout.h
@@ -36,19 +36,10 @@ struct os_callout {
     TAILQ_ENTRY(os_callout) c_next;
 };
 
-typedef void (*os_callout_func_t)(void *);
-
-struct os_callout_func {
-    /* Must be the first element in the structure for casting
-     * purposes.
-     */
-    struct os_callout cf_c;
-    os_callout_func_t cf_func;
-};
 #define CF_ARG(__cf) ((__cf)->cf_c.c_ev.ev_arg)
 
-void os_callout_func_init(struct os_callout_func *cf, struct os_eventq *evq,
-  os_callout_func_t timo_func, void *ev_arg);
+void os_callout_init(struct os_callout *cf, struct os_eventq *evq,
+                     os_event_fn *ev_cb, void *ev_arg);
 void os_callout_stop(struct os_callout *);
 int os_callout_reset(struct os_callout *, int32_t);
 void os_callout_tick(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/include/os/os_eventq.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_eventq.h b/kernel/os/include/os/os_eventq.h
index f2fba2b..c9ae3e2 100644
--- a/kernel/os/include/os/os_eventq.h
+++ b/kernel/os/include/os/os_eventq.h
@@ -28,19 +28,16 @@
 extern "C" {
 #endif
 
+struct os_event;
+typedef void os_event_fn(struct os_event *ev);
+
 struct os_event {
     uint8_t ev_queued;
-    uint8_t ev_type;
+    os_event_fn *ev_cb;
     void *ev_arg;
     STAILQ_ENTRY(os_event) ev_next;
 };
 
-/*
- * If event type is OS_EVENT_T_CB, then this function pointer will be
- * in ev_arg.
- */
-typedef void (*os_event_cb_func)(struct os_event *);
-
 #define OS_EVENT_QUEUED(__ev) ((__ev)->ev_queued)
 
 #define OS_EVENT_T_TIMER        (1)
@@ -54,10 +51,17 @@ struct os_eventq {
 };
 
 void os_eventq_init(struct os_eventq *);
+int os_eventq_inited(const struct os_eventq *evq);
 void os_eventq_put(struct os_eventq *, struct os_event *);
 struct os_event *os_eventq_get(struct os_eventq *);
+void os_eventq_run(struct os_eventq *evq);
 struct os_event *os_eventq_poll(struct os_eventq **, int, os_time_t);
 void os_eventq_remove(struct os_eventq *, struct os_event *);
+void os_eventq_dflt_set(struct os_eventq *evq);
+struct os_eventq *os_eventq_dflt_get(void);
+void os_eventq_designate(struct os_eventq **dst, struct os_eventq *val,
+                         struct os_event *start_ev);
+void os_eventq_ensure(struct os_eventq **evq, struct os_event *start_ev);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_mbuf.h b/kernel/os/include/os/os_mbuf.h
index 81fc87e..0b56962 100644
--- a/kernel/os/include/os/os_mbuf.h
+++ b/kernel/os/include/os/os_mbuf.h
@@ -229,7 +229,7 @@ _os_mbuf_trailingspace(struct os_mbuf *om)
 /* Mbuf queue functions */
 
 /* Initialize a mbuf queue */
-int os_mqueue_init(struct os_mqueue *, void *arg);
+int os_mqueue_init(struct os_mqueue *mq, os_event_fn *ev_cb, void *arg);
 
 /* Get an element from a mbuf queue */
 struct os_mbuf *os_mqueue_get(struct os_mqueue *);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_callout.c b/kernel/os/src/os_callout.c
index 1b57778..bc152fd 100644
--- a/kernel/os/src/os_callout.c
+++ b/kernel/os/src/os_callout.c
@@ -17,12 +17,12 @@
  * under the License.
  */
 
-#include "os/os.h"
-#include "os_priv.h"
-
 #include <assert.h>
 #include <string.h>
 
+#include "os/os.h"
+#include "os_priv.h"
+
 /**
  * @addtogroup OSKernel
  * @{
@@ -31,22 +31,13 @@
  */
 struct os_callout_list g_callout_list;
 
-static void
-_os_callout_init(struct os_callout *c, struct os_eventq *evq, void *ev_arg)
-{
-    memset(c, 0, sizeof(*c));
-    c->c_ev.ev_type = OS_EVENT_T_TIMER;
-    c->c_ev.ev_arg = ev_arg;
-    c->c_evq = evq;
-}
-
 /**
  * Initialize a callout.
  *
  * Callouts are used to schedule events in the future onto a task's event
  * queue.  Callout timers are scheduled using the os_callout_reset()
  * function.  When the timer expires, an event is posted to the event
- * queue specified in os_callout_func_init().  The event argument given here
+ * queue specified in os_callout_init().  The event argument given here
  * is posted in the ev_arg field of that event.
  *
  * @param c The callout to initialize
@@ -57,12 +48,13 @@ _os_callout_init(struct os_callout *c, struct os_eventq *evq, void *ev_arg)
  * @param ev_arg The argument to provide to the event when posting the
  *               timer.
  */
-void
-os_callout_func_init(struct os_callout_func *cf, struct os_eventq *evq,
-  os_callout_func_t timo_func, void *ev_arg)
+void os_callout_init(struct os_callout *c, struct os_eventq *evq,
+                     os_event_fn *ev_cb, void *ev_arg)
 {
-    _os_callout_init(&cf->cf_c, evq, ev_arg);
-    cf->cf_func = timo_func;
+    memset(c, 0, sizeof(*c));
+    c->c_ev.ev_cb = ev_cb;
+    c->c_ev.ev_arg = ev_arg;
+    c->c_evq = evq;
 }
 
 /**
@@ -143,7 +135,7 @@ err:
  * This function is called by the OS in the time tick.  It searches the list
  * of callouts, and sees if any of them are ready to run.  If they are ready
  * to run, it posts an event for each callout that's ready to run,
- * to the event queue provided to os_callout_func_init().
+ * to the event queue provided to os_callout_init().
  */
 void
 os_callout_tick(void)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/src/os_eventq.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_eventq.c b/kernel/os/src/os_eventq.c
index 410b67a..3d79533 100644
--- a/kernel/os/src/os_eventq.c
+++ b/kernel/os/src/os_eventq.c
@@ -17,11 +17,11 @@
  * under the License.
  */
 
+#include <assert.h>
+#include <string.h>
 
 #include "os/os.h"
 
-#include <string.h>
-
 /**
  * @addtogroup OSKernel
  * @{
@@ -29,6 +29,8 @@
  *   @{
  */
 
+static struct os_eventq *os_eventq_main;
+
 /**
  * Initialize the event queue
  *
@@ -41,6 +43,12 @@ os_eventq_init(struct os_eventq *evq)
     STAILQ_INIT(&evq->evq_list);
 }
 
+int
+os_eventq_inited(const struct os_eventq *evq)
+{
+    return evq->evq_list.stqh_last != NULL;
+}
+
 /**
  * Put an event on the event queue.
  *
@@ -124,6 +132,17 @@ pull_one:
     return (ev);
 }
 
+void
+os_eventq_run(struct os_eventq *evq)
+{
+    struct os_event *ev;
+
+    ev = os_eventq_get(evq);
+    assert(ev->ev_cb != NULL);
+
+    ev->ev_cb(ev);
+}
+
 static struct os_event *
 os_eventq_poll_0timo(struct os_eventq **evq, int nevqs)
 {
@@ -241,6 +260,47 @@ os_eventq_remove(struct os_eventq *evq, struct os_event *ev)
     OS_EXIT_CRITICAL(sr);
 }
 
+void
+os_eventq_dflt_set(struct os_eventq *evq)
+{
+    os_eventq_main = evq;
+}
+
+struct os_eventq *
+os_eventq_dflt_get(void)
+{
+    return os_eventq_main;
+}
+
+void
+os_eventq_designate(struct os_eventq **dst, struct os_eventq *val,
+                    struct os_event *start_ev)
+{
+    *dst = val;
+    if (start_ev != NULL) {
+        os_eventq_put(*dst, start_ev);
+    }
+}
+
+void
+os_eventq_ensure(struct os_eventq **evq, struct os_event *start_ev)
+{
+    struct os_eventq *eventq_dflt;
+
+    if (*evq == NULL) {
+        eventq_dflt = os_eventq_dflt_get();
+        if (eventq_dflt != NULL) {
+            os_eventq_designate(evq, eventq_dflt, start_ev);
+        }
+
+        /* The system is misconfigured if there is still no parent eventq.  The
+         * application should have explicitly specified a parent queue for each
+         * package, or indicated a default.
+         */
+        assert(*evq != NULL);
+    }
+}
+
 /**
  *   @} OSEvent
  * @} OSKernel

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/kernel/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_mbuf.c b/kernel/os/src/os_mbuf.c
index 7b03114..9f6e0b1 100644
--- a/kernel/os/src/os_mbuf.c
+++ b/kernel/os/src/os_mbuf.c
@@ -66,7 +66,7 @@ STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list =
  *
  */
 int
-os_mqueue_init(struct os_mqueue *mq, void *arg)
+os_mqueue_init(struct os_mqueue *mq, os_event_fn *ev_cb, void *arg)
 {
     struct os_event *ev;
 
@@ -74,8 +74,8 @@ os_mqueue_init(struct os_mqueue *mq, void *arg)
 
     ev = &mq->mq_ev;
     memset(ev, 0, sizeof(*ev));
+    ev->ev_cb = ev_cb;
     ev->ev_arg = arg;
-    ev->ev_type = OS_EVENT_T_MQUEUE_DATA;
 
     return (0);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/net/nimble/host/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/pkg.yml b/net/nimble/host/pkg.yml
index 9ab8ebd..57170f3 100644
--- a/net/nimble/host/pkg.yml
+++ b/net/nimble/host/pkg.yml
@@ -26,10 +26,11 @@ pkg.keywords:
     - bluetooth
 
 pkg.deps:
-    - sys/log
-    - sys/stats
     - kernel/os
     - net/nimble
+    - sys/log
+    - sys/stats
+    - util/childq
 
 pkg.deps.BLE_SM:
     - crypto/mbedtls

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/918811f8/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 2abc307..3974acc 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -24,6 +24,7 @@
 #include "bsp/bsp.h"
 #include "stats/stats.h"
 #include "os/os.h"
+#include "childq/childq.h"
 #include "nimble/ble_hci_trans.h"
 #include "ble_hs_priv.h"
 
@@ -64,17 +65,14 @@ static int ble_hs_reset_reason;
 
 static struct os_task *ble_hs_parent_task;
 
-#define BLE_HS_SYNC_RETRY_RATE          (OS_TICKS_PER_SEC / 10)
-
 /**
  * Handles unresponsive timeouts and periodic retries in case of resource
  * shortage.
  */
 static struct os_callout_func ble_hs_heartbeat_timer;
-static struct os_callout_func ble_hs_event_co;
 
 /* Queue for host-specific OS events. */
-static struct os_eventq ble_hs_evq;
+static struct childq ble_hs_cq;
 
 static struct os_mqueue ble_hs_rx_q;
 static struct os_mqueue ble_hs_tx_q;
@@ -337,76 +335,52 @@ ble_hs_heartbeat(void *unused)
 }
 
 static void
-ble_hs_event_handle(void *unused)
+ble_hs_event_handle(struct os_event *ev)
 {
     struct os_callout_func *cf;
-    struct os_eventq *evqp;
-    struct os_event *ev;
     uint8_t *hci_evt;
     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 to indicate that more host events are enqueued.
-         */
-        if (i >= BLE_HS_MAX_EVS_IN_A_ROW) {
-            os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
-            break;
-        }
-        i++;
 
-        ev = os_eventq_poll(&evqp, 1, 0);
-        if (ev == NULL) {
-            break;
-        }
+    switch (ev->ev_type) {
+    case OS_EVENT_T_TIMER:
+        cf = (struct os_callout_func *)ev;
+        assert(cf->cf_func);
+        cf->cf_func(ev->ev_arg);
+        break;
 
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(ev->ev_arg);
-            break;
+    case BLE_HOST_HCI_EVENT_CTLR_EVENT:
+        hci_evt = ev->ev_arg;
+        rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
+        BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 
-        case BLE_HOST_HCI_EVENT_CTLR_EVENT:
-            hci_evt = ev->ev_arg;
-            rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
-            BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+        ble_hs_hci_evt_process(hci_evt);
+        break;
 
-            ble_hs_hci_evt_process(hci_evt);
-            break;
-
-        case BLE_HS_EVENT_TX_NOTIFICATIONS:
-            BLE_HS_DBG_ASSERT(ev == &ble_hs_event_tx_notifications);
-            ble_gatts_tx_notifications();
-            break;
+    case BLE_HS_EVENT_TX_NOTIFICATIONS:
+        BLE_HS_DBG_ASSERT(ev == &ble_hs_event_tx_notifications);
+        ble_gatts_tx_notifications();
+        break;
 
-        case OS_EVENT_T_MQUEUE_DATA:
-            ble_hs_process_tx_data_queue();
-            ble_hs_process_rx_data_queue();
-            break;
+    case OS_EVENT_T_MQUEUE_DATA:
+        ble_hs_process_tx_data_queue();
+        ble_hs_process_rx_data_queue();
+        break;
 
-        case BLE_HS_EVENT_RESET:
-            BLE_HS_DBG_ASSERT(ev == &ble_hs_event_reset);
-            ble_hs_reset();
-            break;
+    case BLE_HS_EVENT_RESET:
+        BLE_HS_DBG_ASSERT(ev == &ble_hs_event_reset);
+        ble_hs_reset();
+        break;
 
-        default:
-            BLE_HS_DBG_ASSERT(0);
-            break;
-        }
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        break;
     }
 }
 
 void
 ble_hs_event_enqueue(struct os_event *ev)
 {
-    os_eventq_put(&ble_hs_evq, ev);
-    os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
+    childq_put(&ble_hs_cq, ev);
 }
 
 void
@@ -516,14 +490,13 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
 {
     int rc;
 
-    rc = os_mqueue_put(&ble_hs_rx_q, &ble_hs_evq, om);
-    if (rc == 0) {
-        os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
-    } else {
+    rc = childq_put_mqueue(&ble_hs_cq, &ble_hs_rx_q, om);
+    if (rc != 0) {
         os_mbuf_free_chain(om);
-        rc = BLE_HS_EOS;
+        return BLE_HS_EOS;
     }
-    return rc;
+
+    return 0;
 }
 
 /**
@@ -540,12 +513,11 @@ ble_hs_tx_data(struct os_mbuf *om)
 {
     int rc;
 
-    rc = os_mqueue_put(&ble_hs_tx_q, &ble_hs_evq, om);
+    rc = childq_put_mqueue(&ble_hs_cq, &ble_hs_tx_q, om);
     if (rc != 0) {
         os_mbuf_free_chain(om);
         return BLE_HS_EOS;
     }
-    os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
 
     return 0;
 }
@@ -570,8 +542,7 @@ ble_hs_init(void)
                          "ble_hs_hci_ev_pool");
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    /* Initialize eventq */
-    os_eventq_init(&ble_hs_evq);
+    childq_init(&ble_hs_cq, ble_hs_cfg.parent_evq, ble_hs_event_handle);
 
     ble_hs_hci_init();
 
@@ -604,9 +575,6 @@ ble_hs_init(void)
         STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_hs_stats), "ble_hs");
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    os_callout_func_init(&ble_hs_event_co, &ble_hs_evq,
-                         ble_hs_event_handle, NULL);
-
     rc = os_mutex_init(&ble_hs_mutex);
     SYSINIT_PANIC_ASSERT(rc == 0);
 


[04/11] incubator-mynewt-core git commit: Newtmgr: Event codes -> callbacks

Posted by cc...@apache.org.
Newtmgr: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: 6c85e728d30f94f7366deb556ad7e59a69da102c
Parents: f0b8cbd
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 17:48:30 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:07:52 2016 -0700

----------------------------------------------------------------------
 mgmt/mgmt/include/mgmt/mgmt.h                   |  5 +-
 mgmt/mgmt/src/mgmt.c                            |  9 --
 mgmt/newtmgr/include/newtmgr/newtmgr.h          |  2 +
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c           | 10 +-
 mgmt/newtmgr/pkg.yml                            |  3 +-
 mgmt/newtmgr/src/newtmgr.c                      | 96 ++++++++------------
 mgmt/newtmgr/syscfg.yml                         |  7 --
 mgmt/newtmgr/transport/ble/pkg.yml              |  1 +
 mgmt/newtmgr/transport/ble/src/newtmgr_ble.c    | 46 +++-------
 .../newtmgr/transport/nmgr_uart/src/nmgr_uart.c |  2 +-
 10 files changed, 64 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/mgmt/include/mgmt/mgmt.h
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/include/mgmt/mgmt.h b/mgmt/mgmt/include/mgmt/mgmt.h
index 6101936..9622e6b 100644
--- a/mgmt/mgmt/include/mgmt/mgmt.h
+++ b/mgmt/mgmt/include/mgmt/mgmt.h
@@ -87,10 +87,7 @@ void mgmt_cbuf_setoerr(struct mgmt_cbuf *njb, int errcode);
 const struct mgmt_handler *mgmt_find_handler(uint16_t group_id,
   uint16_t handler_id);
 
-struct os_event;
-struct os_eventq;
-void mgmt_cb_init(struct os_event *ev, void (*func)(struct os_event *));
-extern struct os_eventq *g_mgmt_evq;
+struct os_eventq *mgmt_evq_get(void);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/mgmt/src/mgmt.c
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/src/mgmt.c b/mgmt/mgmt/src/mgmt.c
index dd28806..4ac232a 100644
--- a/mgmt/mgmt/src/mgmt.c
+++ b/mgmt/mgmt/src/mgmt.c
@@ -25,7 +25,6 @@
 static struct os_mutex mgmt_group_lock;
 static STAILQ_HEAD(, mgmt_group) mgmt_group_list =
     STAILQ_HEAD_INITIALIZER(mgmt_group_list);
-struct os_eventq *mgmt_evq;
 
 static int
 mgmt_group_list_lock(void)
@@ -149,11 +148,3 @@ mgmt_cbuf_setoerr(struct mgmt_cbuf *cb, int errcode)
     g_err |= cbor_encode_int(&rsp, errcode);
     g_err |= cbor_encoder_close_container(penc, &rsp);
 }
-
-void
-mgmt_cb_init(struct os_event *ev, void (*func)(struct os_event *))
-{
-    memset(ev, 0, sizeof(*ev));
-    ev->ev_type = OS_EVENT_T_CB;
-    ev->ev_arg = func;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/include/newtmgr/newtmgr.h b/mgmt/newtmgr/include/newtmgr/newtmgr.h
index 16591e3..7cb6f84 100644
--- a/mgmt/newtmgr/include/newtmgr/newtmgr.h
+++ b/mgmt/newtmgr/include/newtmgr/newtmgr.h
@@ -67,6 +67,8 @@ struct nmgr_transport {
     nmgr_transport_get_mtu_func_t nt_get_mtu;
 };
 
+void nmgr_evq_set(struct os_eventq *evq);
+void nmgr_event_put(struct os_event *ev);
 int nmgr_task_init(void);
 int nmgr_transport_init(struct nmgr_transport *nt,
         nmgr_transport_out_func_t output_func,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index c845c75..ae8cd4e 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -36,7 +36,7 @@
 #include <tinycbor/cbor.h>
 #include <cborattr/cborattr.h>
 
-static struct os_callout_func nmgr_reset_callout;
+static struct os_callout nmgr_reset_callout;
 
 static int nmgr_def_echo(struct mgmt_cbuf *);
 static int nmgr_def_console_echo(struct mgmt_cbuf *);
@@ -313,7 +313,7 @@ out:
 }
 
 static void
-nmgr_reset_tmo(void *arg)
+nmgr_reset_tmo(struct os_event *ev)
 {
     system_reset();
 }
@@ -321,8 +321,10 @@ nmgr_reset_tmo(void *arg)
 static int
 nmgr_reset(struct mgmt_cbuf *cb)
 {
+    os_callout_init(&nmgr_reset_callout, mgmt_evq_get(), nmgr_reset_tmo, NULL);
+
     log_reboot(SOFT_REBOOT);
-    os_callout_reset(&nmgr_reset_callout.cf_c, OS_TICKS_PER_SEC / 4);
+    os_callout_reset(&nmgr_reset_callout, OS_TICKS_PER_SEC / 4);
 
     mgmt_cbuf_setoerr(cb, OS_OK);
 
@@ -332,8 +334,6 @@ nmgr_reset(struct mgmt_cbuf *cb)
 int
 nmgr_os_groups_register(void)
 {
-    os_callout_func_init(&nmgr_reset_callout, g_mgmt_evq, nmgr_reset_tmo, NULL);
-
     return mgmt_group_register(&nmgr_def_group);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/pkg.yml b/mgmt/newtmgr/pkg.yml
index c5b0581..a289dc3 100644
--- a/mgmt/newtmgr/pkg.yml
+++ b/mgmt/newtmgr/pkg.yml
@@ -24,8 +24,9 @@ pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.deps:
-    - kernel/os
     - encoding/cborattr
+    - kernel/os
+    - mgmt/mgmt
     - mgmt/newtmgr/nmgr_os
 
 pkg.deps.NEWTMGR_BLE_HOST:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/src/newtmgr.c b/mgmt/newtmgr/src/newtmgr.c
index 56e031e..f54d552 100644
--- a/mgmt/newtmgr/src/newtmgr.c
+++ b/mgmt/newtmgr/src/newtmgr.c
@@ -25,20 +25,17 @@
 #include "os/os.h"
 #include "os/endian.h"
 
-#include <mgmt/mgmt.h>
+#include "mgmt/mgmt.h"
 
 #include "newtmgr/newtmgr.h"
 #include "nmgr_os/nmgr_os.h"
 
-#include <tinycbor/cbor.h>
-#include <tinycbor/cbor_mbuf_writer.h>
-#include <tinycbor/cbor_mbuf_reader.h>
+#include "tinycbor/cbor.h"
+#include "tinycbor/cbor_mbuf_writer.h"
+#include "tinycbor/cbor_mbuf_reader.h"
 
-os_stack_t newtmgr_stack[OS_STACK_ALIGN(MYNEWT_VAL(NEWTMGR_STACK_SIZE))];
-
-static struct os_eventq nmgr_evq;
-struct os_eventq *g_mgmt_evq = &nmgr_evq;
-static struct os_task g_nmgr_task;
+/* Shared queue that newtmgr uses for work items. */
+struct os_eventq *nmgr_evq;
 
 /*
  * cbor buffer for newtmgr
@@ -50,6 +47,19 @@ static struct nmgr_cbuf {
     struct os_mbuf *n_out_m;
 } nmgr_task_cbuf;
 
+struct os_eventq *
+mgmt_evq_get(void)
+{
+    os_eventq_ensure(&nmgr_evq, NULL);
+    return nmgr_evq;
+}
+
+void
+nmgr_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&nmgr_evq, evq, NULL);
+}
+
 static int
 nmgr_cbuf_init(struct nmgr_cbuf *njb)
 {
@@ -57,7 +67,7 @@ nmgr_cbuf_init(struct nmgr_cbuf *njb)
     return (0);
 }
 
-static struct nmgr_hdr*
+static struct nmgr_hdr *
 nmgr_init_rsp(struct os_mbuf *m, struct nmgr_hdr *src)
 {
     struct nmgr_hdr *hdr;
@@ -99,8 +109,8 @@ nmgr_send_err_rsp(struct nmgr_transport *nt, struct os_mbuf *m,
 static int
 nmgr_send_rspfrag(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
                   struct os_mbuf *rsp, struct os_mbuf *req, uint16_t len,
-                  uint16_t *offset) {
-
+                  uint16_t *offset)
+{
     struct os_mbuf *rspfrag;
     int rc;
 
@@ -113,7 +123,8 @@ nmgr_send_rspfrag(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
     }
 
     /* Copy the request packet header into the response. */
-    memcpy(OS_MBUF_USRHDR(rspfrag), OS_MBUF_USRHDR(req), OS_MBUF_USRHDR_LEN(req));
+    memcpy(OS_MBUF_USRHDR(rspfrag), OS_MBUF_USRHDR(req),
+           OS_MBUF_USRHDR_LEN(req));
 
     if (os_mbuf_append(rspfrag, rsp_hdr, sizeof(struct nmgr_hdr))) {
         rc = MGMT_ERR_ENOMEM;
@@ -129,7 +140,8 @@ nmgr_send_rspfrag(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
 
     len = htons(len);
 
-    if (os_mbuf_copyinto(rspfrag, offsetof(struct nmgr_hdr, nh_len), &len, sizeof(len))) {
+    if (os_mbuf_copyinto(rspfrag, offsetof(struct nmgr_hdr, nh_len), &len,
+                         sizeof(len))) {
         rc = MGMT_ERR_ENOMEM;
         goto err;
     }
@@ -146,8 +158,8 @@ err:
 
 static int
 nmgr_rsp_fragment(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
-                  struct os_mbuf *rsp, struct os_mbuf *req) {
-
+                  struct os_mbuf *rsp, struct os_mbuf *req)
+{
     uint16_t offset;
     uint16_t len;
     uint16_t mtu;
@@ -235,7 +247,8 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         }
 
         cbor_mbuf_reader_init(&nmgr_task_cbuf.reader, req, sizeof(hdr));
-        cbor_parser_init(&nmgr_task_cbuf.reader.r, 0, &nmgr_task_cbuf.n_b.parser, &nmgr_task_cbuf.n_b.it);
+        cbor_parser_init(&nmgr_task_cbuf.reader.r, 0,
+                         &nmgr_task_cbuf.n_b.parser, &nmgr_task_cbuf.n_b.it);
 
         if (hdr.nh_op == NMGR_OP_READ) {
             if (handler->mh_read) {
@@ -257,7 +270,8 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
             goto err;
         }
 
-        rsp_hdr->nh_len += cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
+        rsp_hdr->nh_len +=
+            cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
         off += sizeof(hdr) + OS_ALIGN(hdr.nh_len, 4);
         rc = nmgr_rsp_fragment(nt, rsp_hdr, rsp, req);
         if (rc) {
@@ -280,7 +294,7 @@ err_norsp:
 }
 
 
-void
+static void
 nmgr_process(struct nmgr_transport *nt)
 {
     struct os_mbuf *m;
@@ -295,33 +309,10 @@ nmgr_process(struct nmgr_transport *nt)
     }
 }
 
-void
-nmgr_task(void *arg)
+static void
+nmgr_event_data_in(struct os_event *ev)
 {
-    struct nmgr_transport *nt;
-    struct os_event *ev;
-    struct os_callout_func *ocf;
-    os_event_cb_func cb_func;
-
-    nmgr_cbuf_init(&nmgr_task_cbuf);
-
-    while (1) {
-        ev = os_eventq_get(&nmgr_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_MQUEUE_DATA:
-            nt = (struct nmgr_transport *) ev->ev_arg;
-            nmgr_process(nt);
-            break;
-        case OS_EVENT_T_TIMER:
-            ocf = (struct os_callout_func *)ev;
-            ocf->cf_func(CF_ARG(ocf));
-            break;
-        case OS_EVENT_T_CB:
-            cb_func = (os_event_cb_func)ev->ev_arg;
-            cb_func(ev);
-            break;
-        }
-    }
+    nmgr_process(ev->ev_arg);
 }
 
 int
@@ -334,7 +325,7 @@ nmgr_transport_init(struct nmgr_transport *nt,
     nt->nt_output = output_func;
     nt->nt_get_mtu = get_mtu_func;
 
-    rc = os_mqueue_init(&nt->nt_imq, nt);
+    rc = os_mqueue_init(&nt->nt_imq, nmgr_event_data_in, nt);
     if (rc != 0) {
         goto err;
     }
@@ -360,7 +351,7 @@ nmgr_rx_req(struct nmgr_transport *nt, struct os_mbuf *req)
 {
     int rc;
 
-    rc = os_mqueue_put(&nt->nt_imq, &nmgr_evq, req);
+    rc = os_mqueue_put(&nt->nt_imq, mgmt_evq_get(), req);
     if (rc != 0) {
         os_mbuf_free_chain(req);
     }
@@ -373,20 +364,13 @@ nmgr_task_init(void)
 {
     int rc;
 
-    os_eventq_init(&nmgr_evq);
-
-    rc = os_task_init(&g_nmgr_task, "newtmgr", nmgr_task, NULL,
-      MYNEWT_VAL(NEWTMGR_TASK_PRIO), OS_WAIT_FOREVER,
-      newtmgr_stack, OS_STACK_ALIGN(MYNEWT_VAL(NEWTMGR_STACK_SIZE)));
-    if (rc != 0) {
-        goto err;
-    }
-
     rc = nmgr_os_groups_register();
     if (rc != 0) {
         goto err;
     }
 
+    nmgr_cbuf_init(&nmgr_task_cbuf);
+
     return (0);
 err:
     return (rc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/syscfg.yml b/mgmt/newtmgr/syscfg.yml
index 07a7f1a..05d07cd 100644
--- a/mgmt/newtmgr/syscfg.yml
+++ b/mgmt/newtmgr/syscfg.yml
@@ -1,13 +1,6 @@
 # Package: mgmt/newtmgr
 
 syscfg.defs:
-    NEWTMGR_TASK_PRIO:
-        description: 'TBD'
-        type: 'task_priority'
-        value: 'any'
-    NEWTMGR_STACK_SIZE:
-        description: 'TBD'
-        value: 512
     NEWTMGR_BLE_HOST:
         description: 'TBD'
         value: 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/transport/ble/pkg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/ble/pkg.yml b/mgmt/newtmgr/transport/ble/pkg.yml
index 27a0b10..54c0ba5 100644
--- a/mgmt/newtmgr/transport/ble/pkg.yml
+++ b/mgmt/newtmgr/transport/ble/pkg.yml
@@ -27,6 +27,7 @@ pkg.keywords:
 
 pkg.deps:
     - kernel/os
+    - mgmt/mgmt
     - mgmt/newtmgr
     - net/nimble/host
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
index 7db683d..7e8e749 100644
--- a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
+++ b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
@@ -22,12 +22,13 @@
 #include <string.h>
 #include "sysinit/sysinit.h"
 #include "host/ble_hs.h"
+#include "mgmt/mgmt.h"
 #include "newtmgr/newtmgr.h"
 #include "os/endian.h"
 #include "console/console.h"
 
 /* nmgr ble mqueue */
-struct os_mqueue ble_nmgr_mq;
+struct os_mqueue nmgr_ble_mq;
 
 /* ble nmgr transport */
 struct nmgr_transport ble_nt;
@@ -170,49 +171,26 @@ nmgr_ble_get_mtu(struct os_mbuf *req) {
  * @return 0 on success; non-zero on failure
  */
 
-int
-nmgr_ble_proc_mq_evt(struct os_event *ev)
+static void
+nmgr_ble_event_data_in(struct os_event *ev)
 {
     struct os_mbuf *m_resp;
     uint16_t conn_handle;
-    int rc;
-
-    rc = 0;
-    switch (ev->ev_type) {
-        case OS_EVENT_T_MQUEUE_DATA:
-            if (ev->ev_arg != &ble_nmgr_mq) {
-                rc = -1;
-                goto done;
-            }
-
-            while (1) {
-                m_resp = os_mqueue_get(&ble_nmgr_mq);
-                if (!m_resp) {
-                    break;
-                }
-                assert(OS_MBUF_USRHDR_LEN(m_resp) >= sizeof (conn_handle));
-                memcpy(&conn_handle, OS_MBUF_USRHDR(m_resp),
-                       sizeof (conn_handle));
-                ble_gattc_notify_custom(conn_handle, g_ble_nmgr_attr_handle,
-                                        m_resp);
-            }
-            break;
 
-        default:
-            rc = -1;
-            goto done;
+    while ((m_resp = os_mqueue_get(&nmgr_ble_mq)) != NULL) {
+        assert(OS_MBUF_USRHDR_LEN(m_resp) >= sizeof (conn_handle));
+        memcpy(&conn_handle, OS_MBUF_USRHDR(m_resp), sizeof (conn_handle));
+        ble_gattc_notify_custom(conn_handle, g_ble_nmgr_attr_handle,
+                                m_resp);
     }
-
-done:
-    return rc;
 }
 
 static int
-nmgr_ble_out(struct nmgr_transport *nt, struct os_mbuf *m)
+nmgr_ble_out(struct nmgr_transport *nt, struct os_mbuf *om)
 {
     int rc;
 
-    rc = os_mqueue_put(&ble_nmgr_mq, ble_hs_cfg.parent_evq, m);
+    rc = os_mqueue_put(&nmgr_ble_mq, mgmt_evq_get(), om);
     if (rc != 0) {
         goto err;
     }
@@ -243,7 +221,7 @@ nmgr_ble_gatt_svr_init(void)
         return rc;
     }
 
-    os_mqueue_init(&ble_nmgr_mq, &ble_nmgr_mq);
+    os_mqueue_init(&nmgr_ble_mq, &nmgr_ble_event_data_in, NULL);
 
     rc = nmgr_transport_init(&ble_nt, nmgr_ble_out, nmgr_ble_get_mtu);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c85e728/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
index 21b8db6..17c7b8e 100644
--- a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
+++ b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
@@ -365,5 +365,5 @@ nmgr_uart_pkg_init(void)
       (struct uart_dev *)os_dev_open(MYNEWT_VAL(NMGR_UART), 0, &uc);
     assert(nus->nus_dev);
 
-    mgmt_cb_init(&nus->nus_cb_ev, nmgr_uart_rx_frame);
+    nus->nus_cb_ev.ev_cb = nmgr_uart_rx_frame;
 }


[10/11] incubator-mynewt-core git commit: mn_socket - Fix strict aliasing warning.

Posted by cc...@apache.org.
mn_socket - Fix strict aliasing warning.

aka effective type rule violation.


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

Branch: refs/heads/develop
Commit: dd5082d78b83764b589f269974733e70457f19e6
Parents: 7cf94f6
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Oct 30 14:49:44 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:48 2016 -0700

----------------------------------------------------------------------
 net/ip/mn_socket/src/mn_socket_aconv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd5082d7/net/ip/mn_socket/src/mn_socket_aconv.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/src/mn_socket_aconv.c b/net/ip/mn_socket/src/mn_socket_aconv.c
index b64b9b8..dc005c6 100644
--- a/net/ip/mn_socket/src/mn_socket_aconv.c
+++ b/net/ip/mn_socket/src/mn_socket_aconv.c
@@ -65,6 +65,7 @@ mn_inet_ntop(int af, const void *src_v, void *dst, int len)
 {
     const unsigned char *src = src_v;
     const struct mn_in6_addr *a6;
+    uint16_t u16;
     int rc;
     int i;
 
@@ -81,8 +82,9 @@ mn_inet_ntop(int af, const void *src_v, void *dst, int len)
         rc = 0;
 
         for (i = 0; i < sizeof(*a6); i += 2) {
-            rc += snprintf(dst + rc, len - rc, "%x",
-              htons(*(uint16_t *)&a6->s_addr[i]));
+            memcpy(&u16, &a6->s_addr[i], 2);
+            u16 = htons(u16);
+            rc += snprintf(dst + rc, len - rc, "%x", 16);
             if (rc >= len) {
                 return NULL;
             }


[05/11] incubator-mynewt-core git commit: OIC: Event codes -> callbacks

Posted by cc...@apache.org.
OIC: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: 98c990f14c3a28e496220c7949dd356f7be491a2
Parents: 6c85e72
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Oct 30 14:41:45 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:07:59 2016 -0700

----------------------------------------------------------------------
 mgmt/oicmgr/src/oicmgr.c                 | 93 +++++++++++++++------------
 net/oic/src/port/mynewt/adaptor.c        | 36 +----------
 net/oic/src/port/mynewt/adaptor.h        |  4 --
 net/oic/src/port/mynewt/ble_adaptor.c    | 12 +++-
 net/oic/src/port/mynewt/ip_adaptor.c     | 16 ++++-
 net/oic/src/port/mynewt/serial_adaptor.c | 12 +++-
 6 files changed, 89 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index 3011ebd..63b7419 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -37,6 +37,7 @@
 
 #define OMGR_OC_EVENT	(OS_EVENT_T_PERUSER)
 #define OMGR_OC_TIMER	(OS_EVENT_T_PERUSER + 1)
+#define OMGR_OC_START	(OS_EVENT_T_PERUSER + 2)
 #define OICMGR_STACK_SZ	OS_STACK_ALIGN(MYNEWT_VAL(OICMGR_STACK_SIZE))
 
 struct omgr_cbuf {
@@ -52,18 +53,33 @@ struct omgr_state {
     struct omgr_cbuf os_cbuf;		/* CBOR buffer for NMGR task */
 };
 
+static void omgr_event_start(struct os_event *ev);
+static void omgr_event_oc_ev(struct os_event *ev);
+
 static struct omgr_state omgr_state = {
-  .os_oc_event.ev_type = OMGR_OC_EVENT,
-  .os_oc_timer.c_ev.ev_type = OMGR_OC_TIMER,
-  .os_oc_timer.c_evq = &omgr_state.os_evq
+    .os_oc_event.ev_cb = omgr_event_oc_ev,
 };
-struct os_eventq *g_mgmt_evq = &omgr_state.os_evq;
 
-static os_stack_t oicmgr_stack[OICMGR_STACK_SZ];
+static struct os_event omgr_ev_start = {
+    .ev_cb = omgr_event_start,
+};
 
 static void omgr_oic_get(oc_request_t *request, oc_interface_mask_t interface);
 static void omgr_oic_put(oc_request_t *request, oc_interface_mask_t interface);
 
+struct os_eventq *
+mgmt_evq_get(void)
+{
+    os_eventq_ensure(&omgr_state.os_evq;, NULL);
+    return &omgr_state.os_evq;
+}
+
+void
+omgr_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&omgr_state.os_evq, evq, NULL);
+}
+
 static const struct mgmt_handler *
 omgr_oic_find_handler(const char *q, int qlen)
 {
@@ -119,11 +135,13 @@ omgr_oic_op(oc_request_t *req, oc_interface_mask_t mask, int isset)
     cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser, &o->os_cbuf.ob_mj.it);
 
     /* start generating the CBOR OUTPUT */
-    /* this is worth a quick note.  We are encoding CBOR within CBOR, so we need
-     * to use the same encoder as ocf stack.  We are using their global encoder
-     * g_encoder which they intialized before this function is called. Byt we can't
-     * call their macros here as it won't use the right mape encoder (ob_mj) */
-    cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder, CborIndefiniteLength);
+    /* this is worth a quick note.  We are encoding CBOR within CBOR, so we
+     * need to use the same encoder as ocf stack.  We are using their global
+     * encoder g_encoder which they intialized before this function is called.
+     * But we can't call their macros here as it won't use the right mape
+     * encoder (ob_mj) */
+    cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder,
+                            CborIndefiniteLength);
 
     switch (mask) {
     case OC_IF_BASELINE:
@@ -217,52 +235,45 @@ oc_signal_main_loop(void)
 {
     struct omgr_state *o = &omgr_state;
 
-    os_eventq_put(&o->os_evq, &o->os_oc_event);
+    os_childq_put(&o->os_cq, &o->os_oc_event);
 }
 
-void
-omgr_oic_task(void *arg)
+static void
+omgr_oic_process_oc_event(struct os_event *ev)
 {
     struct omgr_state *o = &omgr_state;
-    struct os_event *ev;
-    struct os_callout_func *ocf;
     os_time_t next_event;
 
-    oc_main_init((oc_handler_t *)&omgr_oc_handler);
-    while (1) {
-        ev = os_eventq_get(&o->os_evq);
-        switch (ev->ev_type) {
-        case OMGR_OC_EVENT:
-        case OMGR_OC_TIMER:
-            next_event = oc_main_poll();
-            if (next_event) {
-                os_callout_reset(&o->os_oc_timer, next_event - os_time_get());
-            } else {
-                os_callout_stop(&o->os_oc_timer);
-            }
-            break;
-        case OS_EVENT_T_TIMER:
-            ocf = (struct os_callout_func *)ev;
-            ocf->cf_func(CF_ARG(ocf));
-            break;
-        }
+    next_event = oc_main_poll();
+    if (next_event) {
+        os_callout_reset(&o->os_oc_timer.cf_c, next_event - os_time_get());
+    } else {
+        os_callout_stop(&o->os_oc_timer.cf_c);
     }
 }
 
+static void
+omgr_oic_event_start(struct os_event *ev)
+{
+    oc_main_init((oc_handler_t *)&omgr_oc_handler);
+    os_callout_init(&omgr_state.os_oc_timer, mgmt_evq_get(),
+                    omgr_oic_process_oc_event, NULL);
+}
+
+static void
+omgr_oic_event_oc_ev(struct os_event *ev)
+{
+    omgr_oic_process_oc_event(NULL);
+}
+
 int
 oicmgr_init(void)
 {
     struct omgr_state *o = &omgr_state;
     int rc;
 
-    os_eventq_init(&o->os_evq);
-
-    rc = os_task_init(&o->os_task, "oicmgr", omgr_oic_task, NULL,
-      MYNEWT_VAL(OICMGR_TASK_PRIO), OS_WAIT_FOREVER,
-      oicmgr_stack, OICMGR_STACK_SZ);
-    if (rc != 0) {
-        goto err;
-    }
+    os_childq_init(&o->os_cq);
+    o->os_cq.cq_ev_cb = omgr_oic_handle_event;
 
     rc = nmgr_os_groups_register();
     if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index e4b1cd6..1ca90f2 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -113,41 +113,7 @@ void
 oc_task_handler(void *arg)
 {
     while (1) {
-        struct os_callout_func *cf;
-        oc_message_t *pmsg;
-        (void) pmsg;    /* to avoid unused */
-        struct os_event *evt = os_eventq_get(&oc_event_q);
-
-        switch(evt->ev_type) {
-#if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)
-            case OC_ADATOR_EVENT_IP:
-                while ((pmsg = oc_attempt_rx_ip()) != NULL) {
-                    oc_network_event(pmsg);
-                }
-                break;
-#endif
-#if (MYNEWT_VAL(OC_TRANSPORT_SERIAL) == 1)
-            case OC_ADATOR_EVENT_SERIAL:
-                while ((pmsg = oc_attempt_rx_serial()) != NULL) {
-                    oc_network_event(pmsg);
-                }
-                break;
-#endif
-#if (MYNEWT_VAL(OC_TRANSPORT_GATT) == 1)
-            case OC_ADATOR_EVENT_GATT:
-                while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
-                    oc_network_event(pmsg);
-                }
-                break;
-#endif
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)evt;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-            default:
-                ERROR("oc_task_handler: Unidentified event %d\n", evt->ev_type);
-        }
+        os_eventq_run(&oc_event_q);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index 9378f49..6a0d246 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -24,10 +24,6 @@
 extern "C" {
 #endif
 
-#define OC_ADATOR_EVENT_IP      (OS_EVENT_T_PERUSER + 0)
-#define OC_ADATOR_EVENT_SERIAL  (OS_EVENT_T_PERUSER + 1)
-#define OC_ADATOR_EVENT_GATT    (OS_EVENT_T_PERUSER + 2)
-
 extern struct os_eventq oc_event_q;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 13b0ba6..634a20b 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -201,11 +201,21 @@ ble_coap_gatt_srv_init(struct os_eventq **out)
     return 0;
 }
 
+static void
+oc_event_gatt(struct os_event *ev)
+{
+    oc_message_t *pmsg;
+
+    while ((pmsg = oc_attempt_rx_gatt()) != NULL) {
+        oc_network_event(pmsg);
+    }
+}
+
 int
 oc_connectivity_init_gatt(void)
 {
     os_mqueue_init(&ble_coap_mq, NULL);
-    ble_coap_mq.mq_ev.ev_type = OC_ADATOR_EVENT_GATT;
+    ble_coap_mq.mq_ev.ev_cb = oc_event_gatt;
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 22f063d..3585c51 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -31,8 +31,10 @@
 #include "../oc_log.h"
 #include "adaptor.h"
 
+static void oc_event_ip(struct os_event *ev);
+
 struct os_event oc_sock_read_event = {
-    .ev_type = OC_ADATOR_EVENT_IP,
+    .ev_cb = oc_event_ip,
 };
 
 #ifdef OC_SECURITY
@@ -226,6 +228,16 @@ oc_connectivity_shutdown_ip(void)
 
 }
 
+static void
+oc_event_ip(struct os_event *ev)
+{
+    oc_message_t *pmsg;
+
+    while ((pmsg = oc_attempt_rx_ip()) != NULL) {
+        oc_network_event(pmsg);
+    }
+}
+
 int
 oc_connectivity_init_ip(void)
 {
@@ -312,4 +324,4 @@ oc_connectivity_init_err:
     return rc;
 }
 
-#endif
\ No newline at end of file
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98c990f1/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index d67c7f5..15f95e0 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -41,6 +41,16 @@ oc_connectivity_shutdown_serial(void) {
     shell_nlip_input_register(NULL, NULL);
 }
 
+static void
+oc_event_serial(struct os_event *ev)
+{
+    oc_message_t *pmsg;
+
+    while ((pmsg = oc_attempt_rx_serial()) != NULL) {
+        oc_network_event(pmsg);
+    }
+}
+
 int
 oc_connectivity_init_serial(void) {
     int rc;
@@ -55,7 +65,7 @@ oc_connectivity_init_serial(void) {
         goto err;
     }
     /* override the eventq type */
-    oc_serial_mqueue.mq_ev.ev_type = OC_ADATOR_EVENT_SERIAL;
+    oc_serial_mqueue.mq_ev.ev_cb = oc_event_serial;
     return 0;
 
 err:


[03/11] incubator-mynewt-core git commit: Shell: Event codes -> callbacks

Posted by cc...@apache.org.
Shell: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: f0b8cbd8161e8728e87a49b3015e6f87c7e263c6
Parents: 17eded9
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 17:47:09 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:07:05 2016 -0700

----------------------------------------------------------------------
 sys/shell/include/shell/shell.h |  4 +-
 sys/shell/src/shell.c           | 92 ++++++++++++++++--------------------
 sys/shell/syscfg.yml            |  7 ---
 3 files changed, 45 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f0b8cbd8/sys/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/sys/shell/include/shell/shell.h b/sys/shell/include/shell/shell.h
index e7bfb9e..d5473c2 100644
--- a/sys/shell/include/shell/shell.h
+++ b/sys/shell/include/shell/shell.h
@@ -25,6 +25,8 @@
 extern "C" {
 #endif
 
+struct os_eventq;
+
 typedef int (*shell_cmd_func_t)(int argc, char **argv);
 struct shell_cmd {
     char *sc_cmd;
@@ -43,7 +45,7 @@ typedef int (*shell_nlip_input_func_t)(struct os_mbuf *, void *arg);
 int shell_nlip_input_register(shell_nlip_input_func_t nf, void *arg);
 int shell_nlip_output(struct os_mbuf *m);
 
-void shell_console_rx_cb(void);
+void shell_evq_set(struct os_eventq *evq);
 void shell_init(void);
 
 int shell_cmd_list_lock(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f0b8cbd8/sys/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index ad7691c..7482f9b 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -41,12 +41,15 @@ static struct os_mqueue g_shell_nlip_mq;
 #define SHELL_HELP_PER_LINE     6
 #define SHELL_MAX_ARGS          20
 
-static os_stack_t shell_stack[OS_STACK_ALIGN(MYNEWT_VAL(SHELL_STACK_SIZE))];
-
 static int shell_echo_cmd(int argc, char **argv);
 static int shell_help_cmd(int argc, char **argv);
 int shell_prompt_cmd(int argc, char **argv);
 
+static void shell_event_console_rdy(struct os_event *ev);
+
+/* Shared queue that the shell uses for work items. */
+static struct os_eventq *shell_evq;
+
 static struct shell_cmd g_shell_echo_cmd = {
     .sc_cmd = "echo",
     .sc_cmd_func = shell_echo_cmd
@@ -72,9 +75,9 @@ static struct shell_cmd g_shell_os_date_cmd = {
     .sc_cmd_func = shell_os_date_cmd
 };
 
-static struct os_task shell_task;
-static struct os_eventq shell_evq;
-static struct os_event console_rdy_ev;
+static struct os_event shell_console_rdy_ev = {
+    .ev_cb = shell_event_console_rdy,
+};
 
 static struct os_mutex g_shell_cmd_list_lock;
 
@@ -88,6 +91,19 @@ static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
 static struct os_mbuf *g_nlip_mbuf;
 static uint16_t g_nlip_expected_len;
 
+static struct os_eventq *
+shell_evq_get(void)
+{
+    os_eventq_ensure(&shell_evq, NULL);
+    return shell_evq;
+}
+
+void
+shell_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&shell_evq, evq, NULL);
+}
+
 int
 shell_cmd_list_lock(void)
 {
@@ -209,7 +225,6 @@ shell_process_command(char *line, int len)
     return (0);
 }
 
-
 static int
 shell_nlip_process(char *data, int len)
 {
@@ -374,26 +389,6 @@ err:
     return (rc);
 }
 
-static void
-shell_nlip_mqueue_process(void)
-{
-    struct os_mbuf *m;
-
-    /* Copy data out of the mbuf 12 bytes at a time and write it to
-     * the console.
-     */
-    while (1) {
-        m = os_mqueue_get(&g_shell_nlip_mq);
-        if (!m) {
-            break;
-        }
-
-        (void) shell_nlip_mtx(m);
-
-        os_mbuf_free_chain(m);
-    }
-}
-
 int
 shell_nlip_input_register(shell_nlip_input_func_t nf, void *arg)
 {
@@ -408,7 +403,7 @@ shell_nlip_output(struct os_mbuf *m)
 {
     int rc;
 
-    rc = os_mqueue_put(&g_shell_nlip_mq, &shell_evq, m);
+    rc = os_mqueue_put(&g_shell_nlip_mq, shell_evq_get(), m);
     if (rc != 0) {
         goto err;
     }
@@ -456,25 +451,29 @@ shell_read_console(void)
     }
 }
 
+static void
+shell_event_console_rdy(struct os_event *ev)
+{
+    shell_read_console();
+}
 
 static void
-shell_task_func(void *arg)
+shell_event_data_in(struct os_event *ev)
 {
-    struct os_event *ev;
+    struct os_mbuf *m;
 
+    /* Copy data out of the mbuf 12 bytes at a time and write it to
+     * the console.
+     */
     while (1) {
-        ev = os_eventq_get(&shell_evq);
-        assert(ev != NULL);
-
-        switch (ev->ev_type) {
-            case OS_EVENT_T_CONSOLE_RDY:
-                // Read and process all available lines on the console.
-                shell_read_console();
-                break;
-            case OS_EVENT_T_MQUEUE_DATA:
-                shell_nlip_mqueue_process();
-                break;
+        m = os_mqueue_get(&g_shell_nlip_mq);
+        if (!m) {
+            break;
         }
+
+        (void) shell_nlip_mtx(m);
+
+        os_mbuf_free_chain(m);
     }
 }
 
@@ -483,10 +482,10 @@ shell_task_func(void *arg)
  * to be read.  This is either a full line, or when the
  * console buffer (default = 128) is full.
  */
-void
+static void
 shell_console_rx_cb(void)
 {
-    os_eventq_put(&shell_evq, &console_rdy_ev);
+    os_eventq_put(shell_evq_get(), &shell_console_rdy_ev);
 }
 
 static int
@@ -567,13 +566,6 @@ shell_init(void)
     rc = shell_cmd_register(&g_shell_os_date_cmd);
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    os_eventq_init(&shell_evq);
-    os_mqueue_init(&g_shell_nlip_mq, NULL);
-    console_rdy_ev.ev_type = OS_EVENT_T_CONSOLE_RDY;
+    os_mqueue_init(&g_shell_nlip_mq, shell_event_data_in, NULL);
     console_init(shell_console_rx_cb);
-
-    rc = os_task_init(&shell_task, "shell", shell_task_func,
-      NULL, MYNEWT_VAL(SHELL_TASK_PRIO), OS_WAIT_FOREVER, shell_stack,
-      OS_STACK_ALIGN(MYNEWT_VAL(SHELL_STACK_SIZE)));
-    SYSINIT_PANIC_ASSERT(rc == 0);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f0b8cbd8/sys/shell/syscfg.yml
----------------------------------------------------------------------
diff --git a/sys/shell/syscfg.yml b/sys/shell/syscfg.yml
index 18581f0..2198fca 100644
--- a/sys/shell/syscfg.yml
+++ b/sys/shell/syscfg.yml
@@ -4,13 +4,6 @@ syscfg.defs:
     SHELL_TASK:
         description: 'TBD'
         value: 0
-    SHELL_TASK_PRIO:
-        description: 'TBD'
-        type: 'task_priority'
-        value: 'any'
-    SHELL_STACK_SIZE:
-        description: 'TBD'
-        value: 512
     SHELL_MAX_INPUT_LEN:
         description: 'TBD'
         value: 256


[08/11] incubator-mynewt-core git commit: Wifi: Event codes -> callbacks

Posted by cc...@apache.org.
Wifi: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: 146da29ec8e1aaa1b810ed24b581df11a52f98cc
Parents: d6f98b4
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 31 18:53:06 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:27 2016 -0700

----------------------------------------------------------------------
 .../wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h     |  2 +-
 net/wifi/wifi_mgmt/src/wifi.c                   | 45 ++++++++++----------
 2 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/146da29e/net/wifi/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h
----------------------------------------------------------------------
diff --git a/net/wifi/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h b/net/wifi/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h
index b7e2935..e78adec 100644
--- a/net/wifi/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h
+++ b/net/wifi/wifi_mgmt/include/wifi_mgmt/wifi_mgmt.h
@@ -59,7 +59,7 @@ struct wifi_if {
     } wi_state, wi_tgt;
     struct os_mutex wi_mtx;
     struct os_event wi_event;
-    struct os_callout_func wi_timer;
+    struct os_callout wi_timer;
     const struct wifi_if_ops *wi_ops;
 
     uint8_t wi_scan_cnt;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/146da29e/net/wifi/wifi_mgmt/src/wifi.c
----------------------------------------------------------------------
diff --git a/net/wifi/wifi_mgmt/src/wifi.c b/net/wifi/wifi_mgmt/src/wifi.c
index 1b1c459..f0be059 100644
--- a/net/wifi/wifi_mgmt/src/wifi.c
+++ b/net/wifi/wifi_mgmt/src/wifi.c
@@ -30,16 +30,29 @@
 #include "wifi_mgmt/wifi_mgmt_if.h"
 #include "wifi_priv.h"
 
-#define WIFI_EV_STATE           OS_EVENT_T_PERUSER
-
 static struct os_task wifi_os_task;
-struct os_eventq wifi_evq;
+struct os_eventq *wifi_evq;
 
 static struct wifi_ap *wifi_find_ap(struct wifi_if *wi, char *ssid);
 static void wifi_events(void *arg);
 
+static void wifi_event_state(struct os_event *ev);
+
 static struct wifi_if *wifi_if;
 
+static struct os_eventq *
+wifi_evq_get(void)
+{
+    os_eventq_ensure(&wifi_evq, NULL);
+    return wifi_evq;
+}
+
+void
+wifi_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&wifi_evq, evq, NULL);
+}
+
 /*
  * Looks up interface based on port number.
  */
@@ -63,8 +76,8 @@ wifi_if_register(struct wifi_if *wi, const struct wifi_if_ops *ops)
 
     wi->wi_ops = ops;
     os_mutex_init(&wi->wi_mtx);
-    os_callout_func_init(&wi->wi_timer, &wifi_evq, wifi_events, wi);
-    wi->wi_event.ev_type = WIFI_EV_STATE;
+    os_callout_init(&wi->wi_timer, &wifi_evq, wifi_events, wi);
+    wi->wi_event.ev_cb = wifi_event_state;
     wi->wi_event.ev_arg = wi;
 
     return 0;
@@ -311,27 +324,13 @@ wifi_step(struct wifi_if *wi)
 }
 
 static void
-wifi_task(void *arg)
+wifi_event_state(struct os_event *ev)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
     struct wifi_if *wi;
 
-    while ((ev = os_eventq_get(&wifi_evq))) {
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            cf->cf_func(CF_ARG(cf));
-            break;
-        case WIFI_EV_STATE:
-            wi = (struct wifi_if *)ev->ev_arg;
-            while (wi->wi_state != wi->wi_tgt) {
-                wifi_step(wi);
-            }
-            break;
-        default:
-            break;
-        }
+    wi = (struct wifi_if *)ev->ev_arg;
+    while (wi->wi_state != wi->wi_tgt) {
+        wifi_step(wi);
     }
 }
 


[11/11] incubator-mynewt-core git commit: mn_socket - add missing include.

Posted by cc...@apache.org.
mn_socket - add missing include.


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

Branch: refs/heads/develop
Commit: 1242fdddef6fa61e809dc6f9ba3ca9e88c9ac1cc
Parents: dd5082d
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Oct 30 15:43:30 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:48 2016 -0700

----------------------------------------------------------------------
 net/ip/mn_socket/src/mn_socket_aconv.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1242fddd/net/ip/mn_socket/src/mn_socket_aconv.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/src/mn_socket_aconv.c b/net/ip/mn_socket/src/mn_socket_aconv.c
index dc005c6..d88bb2c 100644
--- a/net/ip/mn_socket/src/mn_socket_aconv.c
+++ b/net/ip/mn_socket/src/mn_socket_aconv.c
@@ -18,6 +18,7 @@
  */
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
 #include <os/endian.h>
 #include "mn_socket/mn_socket.h"
 


[02/11] incubator-mynewt-core git commit: BLE Host: Event codes -> callbacks

Posted by cc...@apache.org.
BLE Host: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: 17eded92b71b4ca80a38553cc7938200595094e9
Parents: 918811f
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 16:10:21 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:06:43 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs.h       |   3 +-
 net/nimble/host/pkg.yml                     |   1 -
 net/nimble/host/src/ble_hs.c                | 148 ++++++++++++-----------
 net/nimble/host/src/ble_hs_cfg.c            |   2 -
 net/nimble/host/src/ble_hs_priv.h           |   1 +
 net/nimble/host/test/src/ble_hs_test_util.c |   4 +-
 net/nimble/host/test/src/ble_os_test.c      |  19 +--
 7 files changed, 84 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/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 ca6bf01..34400f1 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -98,8 +98,6 @@ typedef void ble_hs_reset_fn(int reason);
 typedef void ble_hs_sync_fn(void);
 
 struct ble_hs_cfg {
-    struct os_eventq *parent_evq;
-
     /*** GATT server settings. */
     /**
      * An optional callback that gets executed upon registration of each GATT
@@ -155,6 +153,7 @@ extern struct ble_hs_cfg ble_hs_cfg;
 
 int ble_hs_synced(void);
 int ble_hs_start(void);
+void ble_hs_evq_set(struct os_eventq *evq);
 void ble_hs_init(void);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/net/nimble/host/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/pkg.yml b/net/nimble/host/pkg.yml
index 57170f3..377a3a7 100644
--- a/net/nimble/host/pkg.yml
+++ b/net/nimble/host/pkg.yml
@@ -30,7 +30,6 @@ pkg.deps:
     - net/nimble
     - sys/log
     - sys/stats
-    - util/childq
 
 pkg.deps.BLE_SM:
     - crypto/mbedtls

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/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 3974acc..63b04ed 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -19,12 +19,12 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <string.h>
 #include "sysinit/sysinit.h"
 #include "syscfg/syscfg.h"
 #include "bsp/bsp.h"
 #include "stats/stats.h"
 #include "os/os.h"
-#include "childq/childq.h"
 #include "nimble/ble_hci_trans.h"
 #include "ble_hs_priv.h"
 
@@ -32,11 +32,10 @@
     (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) +     \
      MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
 
-/**
- * The maximum number of events the host will process in a row before returning
- * control to the parent task.
- */
-#define BLE_HS_MAX_EVS_IN_A_ROW 2
+static void ble_hs_event_rx_hci_ev(struct os_event *ev);
+static void ble_hs_event_tx_notify(struct os_event *ev);
+static void ble_hs_event_reset(struct os_event *ev);
+static void ble_hs_event_start(struct os_event *ev);
 
 struct os_mempool ble_hs_hci_ev_pool;
 static os_membuf_t ble_hs_hci_os_event_buf[
@@ -44,15 +43,17 @@ static os_membuf_t ble_hs_hci_os_event_buf[
 ];
 
 /** OS event - triggers tx of pending notifications and indications. */
-static struct os_event ble_hs_event_tx_notifications = {
-    .ev_type = BLE_HS_EVENT_TX_NOTIFICATIONS,
-    .ev_arg = NULL,
+static struct os_event ble_hs_ev_tx_notifications = {
+    .ev_cb = ble_hs_event_tx_notify,
 };
 
 /** OS event - triggers a full reset. */
-static struct os_event ble_hs_event_reset = {
-    .ev_type = BLE_HS_EVENT_RESET,
-    .ev_arg = NULL,
+static struct os_event ble_hs_ev_reset = {
+    .ev_cb = ble_hs_event_reset,
+};
+
+static struct os_event ble_hs_ev_start = {
+    .ev_cb = ble_hs_event_start,
 };
 
 uint8_t ble_hs_sync_state;
@@ -69,10 +70,10 @@ static struct os_task *ble_hs_parent_task;
  * Handles unresponsive timeouts and periodic retries in case of resource
  * shortage.
  */
-static struct os_callout_func ble_hs_heartbeat_timer;
+static struct os_callout ble_hs_heartbeat_timer;
 
-/* Queue for host-specific OS events. */
-static struct childq ble_hs_cq;
+/* Shared queue that the host uses for work items. */
+static struct os_eventq *ble_hs_evq;
 
 static struct os_mqueue ble_hs_rx_q;
 static struct os_mqueue ble_hs_tx_q;
@@ -104,6 +105,19 @@ STATS_NAME_START(ble_hs_stats)
     STATS_NAME(ble_hs_stats, sync)
 STATS_NAME_END(ble_hs_stats)
 
+static struct os_eventq *
+ble_hs_evq_get(void)
+{
+    os_eventq_ensure(&ble_hs_evq, &ble_hs_ev_start);
+    return ble_hs_evq;
+}
+
+void
+ble_hs_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&ble_hs_evq, evq, &ble_hs_ev_start);
+}
+
 int
 ble_hs_locked_by_cur_task(void)
 {
@@ -200,7 +214,7 @@ ble_hs_heartbeat_timer_reset(uint32_t ticks)
 {
     int rc;
 
-    rc = os_callout_reset(&ble_hs_heartbeat_timer.cf_c, ticks);
+    rc = os_callout_reset(&ble_hs_heartbeat_timer, ticks);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 }
 
@@ -214,8 +228,8 @@ ble_hs_heartbeat_sched(int32_t ticks_from_now)
     /* Reset heartbeat timer if it is not currently scheduled or if the
      * specified time is sooner than the current expiration time.
      */
-    if (!os_callout_queued(&ble_hs_heartbeat_timer.cf_c) ||
-        OS_TIME_TICK_LT(ticks_from_now, ble_hs_heartbeat_timer.cf_c.c_ticks)) {
+    if (!os_callout_queued(&ble_hs_heartbeat_timer) ||
+        OS_TIME_TICK_LT(ticks_from_now, ble_hs_heartbeat_timer.c_ticks)) {
 
         ble_hs_heartbeat_timer_reset(ticks_from_now);
     }
@@ -305,7 +319,7 @@ ble_hs_reset(void)
  * timeouts and periodic retries in case of resource shortage.
  */
 static void
-ble_hs_heartbeat(void *unused)
+ble_hs_heartbeat(struct os_event *ev)
 {
     int32_t ticks_until_next;
 
@@ -335,52 +349,41 @@ ble_hs_heartbeat(void *unused)
 }
 
 static void
-ble_hs_event_handle(struct os_event *ev)
+ble_hs_event_rx_hci_ev(struct os_event *ev)
 {
-    struct os_callout_func *cf;
     uint8_t *hci_evt;
     int rc;
 
-    switch (ev->ev_type) {
-    case OS_EVENT_T_TIMER:
-        cf = (struct os_callout_func *)ev;
-        assert(cf->cf_func);
-        cf->cf_func(ev->ev_arg);
-        break;
-
-    case BLE_HOST_HCI_EVENT_CTLR_EVENT:
-        hci_evt = ev->ev_arg;
-        rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
-        BLE_HS_DBG_ASSERT_EVAL(rc == 0);
-
-        ble_hs_hci_evt_process(hci_evt);
-        break;
+    hci_evt = ev->ev_arg;
+    rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
+    BLE_HS_DBG_ASSERT_EVAL(rc == 0);
 
-    case BLE_HS_EVENT_TX_NOTIFICATIONS:
-        BLE_HS_DBG_ASSERT(ev == &ble_hs_event_tx_notifications);
-        ble_gatts_tx_notifications();
-        break;
+    ble_hs_hci_evt_process(hci_evt);
+}
 
-    case OS_EVENT_T_MQUEUE_DATA:
-        ble_hs_process_tx_data_queue();
-        ble_hs_process_rx_data_queue();
-        break;
+static void
+ble_hs_event_tx_notify(struct os_event *ev)
+{
+    ble_gatts_tx_notifications();
+}
 
-    case BLE_HS_EVENT_RESET:
-        BLE_HS_DBG_ASSERT(ev == &ble_hs_event_reset);
-        ble_hs_reset();
-        break;
+static void
+ble_hs_event_data(struct os_event *ev)
+{
+    ble_hs_process_tx_data_queue();
+    ble_hs_process_rx_data_queue();
+}
 
-    default:
-        BLE_HS_DBG_ASSERT(0);
-        break;
-    }
+static void
+ble_hs_event_reset(struct os_event *ev)
+{
+    ble_hs_reset();
 }
 
-void
-ble_hs_event_enqueue(struct os_event *ev)
+static void
+ble_hs_event_start(struct os_event *ev)
 {
-    childq_put(&ble_hs_cq, ev);
+    ble_hs_start();
 }
 
 void
@@ -393,9 +396,9 @@ ble_hs_enqueue_hci_event(uint8_t *hci_evt)
         ble_hci_trans_buf_free(hci_evt);
     } else {
         ev->ev_queued = 0;
-        ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_EVENT;
+        ev->ev_cb = ble_hs_event_rx_hci_ev,
         ev->ev_arg = hci_evt;
-        ble_hs_event_enqueue(ev);
+        os_eventq_put(ble_hs_evq_get(), ev);
     }
 }
 
@@ -413,7 +416,7 @@ ble_hs_notifications_sched(void)
     }
 #endif
 
-    ble_hs_event_enqueue(&ble_hs_event_tx_notifications);
+    os_eventq_put(ble_hs_evq_get(), &ble_hs_ev_tx_notifications);
 }
 
 void
@@ -422,7 +425,7 @@ ble_hs_sched_reset(int reason)
     BLE_HS_DBG_ASSERT(ble_hs_reset_reason == 0);
 
     ble_hs_reset_reason = reason;
-    ble_hs_event_enqueue(&ble_hs_event_reset);
+    os_eventq_put(ble_hs_evq_get(), &ble_hs_ev_reset);
 }
 
 void
@@ -449,14 +452,10 @@ ble_hs_start(void)
 {
     int rc;
 
-    if (ble_hs_cfg.parent_evq == NULL) {
-        return BLE_HS_EINVAL;
-    }
-
     ble_hs_parent_task = os_sched_get_current_task();
 
-    os_callout_func_init(&ble_hs_heartbeat_timer, ble_hs_cfg.parent_evq,
-                         ble_hs_heartbeat, NULL);
+    os_callout_init(&ble_hs_heartbeat_timer, ble_hs_evq_get(),
+                    ble_hs_heartbeat, NULL);
 
     rc = ble_att_svr_start();
     if (rc != 0) {
@@ -490,7 +489,7 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
 {
     int rc;
 
-    rc = childq_put_mqueue(&ble_hs_cq, &ble_hs_rx_q, om);
+    rc = os_mqueue_put(&ble_hs_rx_q, ble_hs_evq_get(), om);
     if (rc != 0) {
         os_mbuf_free_chain(om);
         return BLE_HS_EOS;
@@ -513,7 +512,7 @@ ble_hs_tx_data(struct os_mbuf *om)
 {
     int rc;
 
-    rc = childq_put_mqueue(&ble_hs_cq, &ble_hs_tx_q, om);
+    rc = os_mqueue_put(&ble_hs_tx_q, ble_hs_evq_get(), om);
     if (rc != 0) {
         os_mbuf_free_chain(om);
         return BLE_HS_EOS;
@@ -542,7 +541,18 @@ ble_hs_init(void)
                          "ble_hs_hci_ev_pool");
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    childq_init(&ble_hs_cq, ble_hs_cfg.parent_evq, ble_hs_event_handle);
+    /* These get initialized here to allow unit tests to run without a zeroed
+     * bss.
+     */
+    ble_hs_ev_tx_notifications = (struct os_event) {
+        .ev_cb = ble_hs_event_tx_notify,
+    };
+    ble_hs_ev_reset = (struct os_event) {
+        .ev_cb = ble_hs_event_reset,
+    };
+    ble_hs_ev_start = (struct os_event) {
+        .ev_cb = ble_hs_event_start,
+    };
 
     ble_hs_hci_init();
 
@@ -567,8 +577,8 @@ ble_hs_init(void)
     rc = ble_gatts_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    os_mqueue_init(&ble_hs_rx_q, NULL);
-    os_mqueue_init(&ble_hs_tx_q, NULL);
+    os_mqueue_init(&ble_hs_rx_q, ble_hs_event_data, NULL);
+    os_mqueue_init(&ble_hs_tx_q, ble_hs_event_data, NULL);
 
     rc = stats_init_and_reg(
         STATS_HDR(ble_hs_stats), STATS_SIZE_INIT_PARMS(ble_hs_stats,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/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 b8d19f9..a46a604 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -21,8 +21,6 @@
 #include "host/ble_hs.h"
 
 struct ble_hs_cfg ble_hs_cfg = {
-    .parent_evq = NULL,
-
     /** Security manager settings. */
     .sm_io_cap = MYNEWT_VAL(BLE_SM_IO_CAP),
     .sm_oob_data_flag = MYNEWT_VAL(BLE_SM_OOB_DATA_FLAG),

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 723c164..1aa4d5d 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -57,6 +57,7 @@ struct os_event;
 #define BLE_HOST_HCI_EVENT_CTLR_EVENT   (OS_EVENT_T_PERUSER + 0)
 #define BLE_HS_EVENT_TX_NOTIFICATIONS   (OS_EVENT_T_PERUSER + 1)
 #define BLE_HS_EVENT_RESET              (OS_EVENT_T_PERUSER + 2)
+#define BLE_HS_EVENT_START              (OS_EVENT_T_PERUSER + 3)
 
 #define BLE_HS_SYNC_STATE_BAD           0
 #define BLE_HS_SYNC_STATE_BRINGUP       1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 9cb58e5..9afd660 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1551,8 +1551,6 @@ ble_hs_test_util_hci_txed(uint8_t *cmdbuf, void *arg)
 void
 ble_hs_test_util_init_no_start(void)
 {
-    ble_hs_cfg.parent_evq = &ble_hs_test_util_evq;
-
     tu_init();
 
     os_eventq_init(&ble_hs_test_util_evq);
@@ -1571,6 +1569,8 @@ ble_hs_test_util_init_no_start(void)
     ble_hs_max_attrs = 64;
 
     ble_hs_test_util_prev_hci_tx_clear();
+
+    ble_hs_evq_set(&ble_hs_test_util_evq);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17eded92/net/nimble/host/test/src/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_os_test.c b/net/nimble/host/test/src/ble_os_test.c
index 7afd02c..067f0ac 100644
--- a/net/nimble/host/test/src/ble_os_test.c
+++ b/net/nimble/host/test/src/ble_os_test.c
@@ -349,25 +349,8 @@ ble_gap_terminate_test_task_handler(void *arg)
 static void
 ble_os_test_app_task_handler(void *arg)
 {
-    struct os_callout_func *cf;
-    struct os_event *ev;
-    int rc;
-
-    rc = ble_hs_start();
-    TEST_ASSERT(rc == 0);
-
     while (1) {
-        ev = os_eventq_get(&ble_hs_test_util_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&ble_hs_test_util_evq);
     }
 }
 


[07/11] incubator-mynewt-core git commit: OS unit tests: Event codes -> callbacks

Posted by cc...@apache.org.
OS unit tests: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: d6f98b4406db88691b86bb1379c0a9f5efb9a301
Parents: cf38f1f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 31 18:52:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:16 2016 -0700

----------------------------------------------------------------------
 kernel/os/test/src/callout_test.c               | 78 ++++++++++----------
 kernel/os/test/src/callout_test.h               | 14 ++--
 kernel/os/test/src/eventq_test.c                | 18 ++---
 kernel/os/test/src/os_test.c                    |  1 +
 .../test/src/testcases/event_test_poll_0timo.c  |  1 -
 .../src/testcases/event_test_poll_single_sr.c   |  3 +-
 .../src/testcases/event_test_poll_timeout_sr.c  |  1 -
 kernel/os/test/src/testcases/os_callout_test.c  |  3 +-
 .../test/src/testcases/os_callout_test_speak.c  | 12 +--
 .../test/src/testcases/os_callout_test_stop.c   | 13 ++--
 10 files changed, 69 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.c b/kernel/os/test/src/callout_test.c
index 8ad3dc0..ff15357 100644
--- a/kernel/os/test/src/callout_test.c
+++ b/kernel/os/test/src/callout_test.c
@@ -28,8 +28,8 @@ os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
 struct os_task callout_task_struct_receive;
 os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
 
-/* Delearing variables for callout_func */
-struct os_callout_func callout_func_test;
+/* Declaring variables for callout */
+struct os_callout callout_test_c;
 
 /* The event to be sent*/
 struct os_eventq callout_evq;
@@ -43,7 +43,7 @@ struct os_task callout_task_struct_stop_receive;
 os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
 
 /* Delearing variables for callout_stop_func */
-struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+struct os_callout callout_stop_test[MULTI_SIZE];
 
 /* The event to be sent*/
 struct os_eventq callout_stop_evq[MULTI_SIZE];
@@ -57,7 +57,7 @@ os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
 struct os_task callout_task_struct_listen;
 os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
 
-struct os_callout_func callout_func_speak;
+struct os_callout callout_speak;
 
 /* Global variables to be used by the callout functions */
 int p;
@@ -66,39 +66,39 @@ int t;
 
 /* This is the function for callout_init*/
 void
-my_callout_func(void *arg)
+my_callout(struct os_event *ev)
 {
     p = 4;
 }
 
 /* This is the function for callout_init of stop test_case*/
 void
-my_callout_stop_func(void *arg)
+my_callout_stop_func(struct os_event *ev)
 {
     q = 1;
 }
 /* This is the function for callout_init for speak test_case*/
 void
-my_callout_speak_func(void *arg)
+my_callout_speak_func(struct os_event *ev)
 {
     t = 2;
 }
 
 /* This is a callout task to send data */
 void
-callout_task_send(void *arg )
+callout_task_send(void *arg)
 {
    int i;
     /* Should say whether callout is armed or not */
-    i= os_callout_queued(&callout_func_test.cf_c);
+    i= os_callout_queued(&callout_test_c);
     TEST_ASSERT(i == 0);
 
     /* Arm the callout */
-    i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
+    i = os_callout_reset(&callout_test_c, OS_TICKS_PER_SEC/ 50);
     TEST_ASSERT_FATAL(i == 0);
 
     /* Should say whether callout is armed or not */
-    i = os_callout_queued(&callout_func_test.cf_c);
+    i = os_callout_queued(&callout_test_c);
     TEST_ASSERT(i == 1);
 
     /* Send the callout */ 
@@ -107,23 +107,23 @@ callout_task_send(void *arg )
 
 /* This is the callout to receive data */
 void
-callout_task_receive( void *arg)
+callout_task_receive(void *arg)
 {
     int i;
     struct os_event *event;
-    struct os_callout_func *callout;
+    struct os_callout *callout;
     os_time_t now;
     os_time_t tm;
     os_sr_t sr; 
+
     /* Recieve using the os_eventq_poll */
-    event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
-    TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
+    event = os_eventq_poll(&callout_test_c.c_evq, 1, OS_WAIT_FOREVER);
     TEST_ASSERT(event->ev_arg == NULL);
-    callout = (struct os_callout_func *)event;
-    TEST_ASSERT(callout->cf_func == my_callout_func);
+    callout = (struct os_callout *)event;
+    TEST_ASSERT(callout->c_ev.ev_cb == my_callout);
 
     /* Should say whether callout is armed or not */
-    i = os_callout_queued(&callout_func_test.cf_c);
+    i = os_callout_queued(&callout_test_c);
     TEST_ASSERT(i == 0);
 
     OS_ENTER_CRITICAL(sr);
@@ -139,26 +139,26 @@ callout_task_receive( void *arg)
 
 /* This is callout to send the stop_callout */
 void
-callout_task_stop_send( void *arg)
+callout_task_stop_send(void *arg)
 {
     int k;
     int j;    
      /* Should say whether callout is armed or not */
     for(k = 0; k<MULTI_SIZE; k++){
-        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        j = os_callout_queued(&callout_stop_test[k]);
         TEST_ASSERT(j == 0);
     }
 
 
     /* Show that  callout is not armed after calling callout_stop */
     for(k = 0; k<MULTI_SIZE; k++){
-        os_callout_stop(&callout_func_stop_test[k].cf_c);
-        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        os_callout_stop(&callout_stop_test[k]);
+        j = os_callout_queued(&callout_stop_test[k]);
         TEST_ASSERT(j == 0);
     }
     /* Arm the callout */
     for(k = 0; k<MULTI_SIZE; k++){
-        j = os_callout_reset(&callout_func_stop_test[k].cf_c, OS_TICKS_PER_SEC/ 50);
+        j = os_callout_reset(&callout_stop_test[k], OS_TICKS_PER_SEC/ 50);
         TEST_ASSERT_FATAL(j == 0);
     }
     os_time_delay( OS_TICKS_PER_SEC );
@@ -166,26 +166,25 @@ callout_task_stop_send( void *arg)
 
 /* This is the callout to receive stop_callout data */
 void
-callout_task_stop_receive( void *arg )
+callout_task_stop_receive(void *arg)
 {
     int k;
     struct os_event *event;
-    struct os_callout_func *callout;
+    struct os_callout *callout;
     /* Recieving using the os_eventq_poll */
     for(k=0; k<MULTI_SIZE; k++){
-        event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
+        event = os_eventq_poll(&callout_stop_test[k].c_evq, 1,
            OS_WAIT_FOREVER);
-        TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
         TEST_ASSERT(event->ev_arg == NULL);
-        callout = (struct os_callout_func *)event;
-        TEST_ASSERT(callout->cf_func == my_callout_stop_func);
+        callout = (struct os_callout *)event;
+        TEST_ASSERT(callout->c_ev.ev_cb == my_callout_stop_func);
 
 
      }
      
     /* Show that event is removed from the queued after calling callout_stop */
     for(k=0; k<MULTI_SIZE; k++){
-        os_callout_stop(&callout_func_stop_test[k].cf_c);
+        os_callout_stop(&callout_stop_test[k]);
         /* Testing that the event has been removed from queue */
         TEST_ASSERT_FATAL(1); 
      }
@@ -196,18 +195,18 @@ callout_task_stop_receive( void *arg )
 
 /* This is a callout task to send data */
 void
-callout_task_stop_speak( void *arg )
+callout_task_stop_speak(void *arg)
 {
     int i;
     /* Arm the callout */
-    i = os_callout_reset(&callout_func_speak.cf_c, OS_TICKS_PER_SEC/ 50);
+    i = os_callout_reset(&callout_speak, OS_TICKS_PER_SEC/ 50);
     TEST_ASSERT_FATAL(i == 0);
 
     /* should say whether callout is armed or not */
-    i = os_callout_queued(&callout_func_speak.cf_c);
+    i = os_callout_queued(&callout_speak);
     TEST_ASSERT(i == 1);
 
-    os_callout_stop(&callout_func_speak.cf_c);
+    os_callout_stop(&callout_speak);
     
     /* Send the callout */ 
     os_time_delay(OS_TICKS_PER_SEC/ 100 );
@@ -216,14 +215,15 @@ callout_task_stop_speak( void *arg )
 }
 
 void
-callout_task_stop_listen( void *arg )
+callout_task_stop_listen(void *arg)
 {
     struct os_event *event;
-    struct os_callout_func *callout;
-    event = os_eventq_get(callout_func_speak.cf_c.c_evq);
+    struct os_callout *callout;
+
+    event = os_eventq_get(callout_speak.c_evq);
     TEST_ASSERT_FATAL(0);
-    callout = (struct os_callout_func *)event;
-    TEST_ASSERT(callout->cf_func == my_callout_speak_func);
+    callout = (struct os_callout *)event;
+    TEST_ASSERT(callout->c_ev.ev_cb == my_callout_speak_func);
 
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/callout_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.h b/kernel/os/test/src/callout_test.h
index ea85962..494251d 100644
--- a/kernel/os/test/src/callout_test.h
+++ b/kernel/os/test/src/callout_test.h
@@ -38,9 +38,6 @@ extern os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
 extern struct os_task callout_task_struct_receive;
 extern os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
 
-/* Delearing variables for callout_func */
-extern struct os_callout_func callout_func_test;
-
 /* The event to be sent*/
 extern struct os_eventq callout_evq;
 extern struct os_event callout_ev;
@@ -56,7 +53,7 @@ extern os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
 
 /* Delearing variables for callout_stop_func */
 #define MULTI_SIZE    (2)
-extern struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+extern struct os_callout callout_stop_test[MULTI_SIZE];
 
 /* The event to be sent*/
 extern struct os_eventq callout_stop_evq[MULTI_SIZE];
@@ -72,16 +69,17 @@ extern os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
 extern struct os_task callout_task_struct_listen;
 extern os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
 
-extern struct os_callout_func callout_func_speak;
+extern struct os_callout callout_speak;
+extern struct os_callout callout_test_c;
 
 /* Global variables to be used by the callout functions */
 extern int p;
 extern int q;
 extern int t;
 
-void my_callout_func(void *arg);
-void my_callout_stop_func(void *arg);
-void my_callout_speak_func(void *arg);
+void my_callout(struct os_event *ev);
+void my_callout_stop_func(struct os_event *ev);
+void my_callout_speak_func(struct os_event *ev);
 void callout_task_send(void *arg);
 void callout_task_receive(void *arg);
 void callout_task_stop_send(void *arg);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/eventq_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.c b/kernel/os/test/src/eventq_test.c
index f741613..5696645 100644
--- a/kernel/os/test/src/eventq_test.c
+++ b/kernel/os/test/src/eventq_test.c
@@ -47,6 +47,7 @@ struct os_event g_event;
 struct os_event m_event[SIZE_MULTI_EVENT];
 
 /* Setting the event to send and receive multiple data */
+
 uint8_t my_event_type = 1;
 
 /* Setting up data for the poll */
@@ -95,16 +96,14 @@ eventq_task_send(void *arg)
     int i;
 
     g_event.ev_queued = 0;
-    g_event.ev_type = my_event_type;
-    g_event.ev_arg = NULL;
+    g_event.ev_arg = (void *)(intptr_t)my_event_type;
 
     os_eventq_put(&my_eventq, &g_event);
 
     os_time_delay(OS_TICKS_PER_SEC / 2);
 
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        m_event[i].ev_type = i + 2;
-        m_event[i].ev_arg = NULL;
+        m_event[i].ev_arg = (void *)(intptr_t)(i + 2);
 
         /* Put and send */
         os_eventq_put(&multi_eventq[i], &m_event[i]);
@@ -123,12 +122,12 @@ eventq_task_receive(void *arg)
     int i;
 
     event = os_eventq_get(&my_eventq);
-    TEST_ASSERT(event->ev_type == my_event_type);
+    TEST_ASSERT((intptr_t)event->ev_arg == my_event_type);
 
     /* Receiving multi event from the send task */
     for (i = 0; i < SIZE_MULTI_EVENT; i++) {
         event = os_eventq_get(&multi_eventq[i]);
-        TEST_ASSERT(event->ev_type == i + 2);
+        TEST_ASSERT((intptr_t)event->ev_arg == i + 2);
     }
 
     /* Finishes the test when OS has been started */
@@ -146,8 +145,7 @@ eventq_task_poll_send(void *arg)
     }
 
     for (i = 0; i < SIZE_MULTI_EVENT; i++){
-        m_event[i].ev_type = i + 10;
-        m_event[i].ev_arg = NULL;
+        m_event[i].ev_arg = (void *)(intptr_t)(i + 10);
 
         /* Put and send */
         os_eventq_put(eventqs[i], &m_event[i]);
@@ -172,7 +170,7 @@ eventq_task_poll_receive(void *arg)
     /* Recieving using the os_eventq_poll*/
     for (i = 0; i < SIZE_MULTI_EVENT; i++) {
         event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
-        TEST_ASSERT(event->ev_type == i +10);
+        TEST_ASSERT((intptr_t)event->ev_arg == i +10);
     }
 
     /* Finishes the test when OS has been started */
@@ -261,7 +259,7 @@ eventq_task_poll_single_receive(void *arg)
 
     /* Recieving using the os_eventq_poll*/
     event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
-    TEST_ASSERT(event->ev_type == 20);
+    TEST_ASSERT((intptr_t)event->ev_arg == 20);
 
     /* Finishes the test when OS has been started */
     os_test_restart();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/os_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c
index eaf1535..1e817a7 100644
--- a/kernel/os/test/src/os_test.c
+++ b/kernel/os/test/src/os_test.c
@@ -76,6 +76,7 @@ int
 main(int argc, char **argv)
 {
     ts_config.ts_print_results = 1;
+    tu_parse_args(argc, argv);
     tu_init();
 
     os_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_0timo.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_0timo.c b/kernel/os/test/src/testcases/event_test_poll_0timo.c
index a1b52bb..5e86395 100644
--- a/kernel/os/test/src/testcases/event_test_poll_0timo.c
+++ b/kernel/os/test/src/testcases/event_test_poll_0timo.c
@@ -44,7 +44,6 @@ TEST_CASE(event_test_poll_0timo)
 
     /* 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);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_single_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_single_sr.c b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
index 92c0677..8abf755 100644
--- a/kernel/os/test/src/testcases/event_test_poll_single_sr.c
+++ b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
@@ -39,8 +39,7 @@ TEST_CASE(event_test_poll_single_sr)
     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;
+        m_event[i].ev_arg = (void *)(intptr_t)(10 * i);
     }
 
     /* Does not return until OS_restart is called */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
index 958c69f..9ce3481 100644
--- a/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
+++ b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
@@ -39,7 +39,6 @@ TEST_CASE(event_test_poll_timeout_sr)
     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;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test.c b/kernel/os/test/src/testcases/os_callout_test.c
index 8d6739d..6fc01c7 100644
--- a/kernel/os/test/src/testcases/os_callout_test.c
+++ b/kernel/os/test/src/testcases/os_callout_test.c
@@ -38,8 +38,7 @@ TEST_CASE(callout_test)
     os_eventq_init(&callout_evq);
     
     /* Initialize the callout function */
-    os_callout_func_init(&callout_func_test, &callout_evq,
-        my_callout_func, NULL);
+    os_callout_init(&callout_test_c, &callout_evq, my_callout, NULL);
 
     /* Does not return until OS_restart is called */
     os_start();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test_speak.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_speak.c b/kernel/os/test/src/testcases/os_callout_test_speak.c
index dda02e7..11dd3d2 100644
--- a/kernel/os/test/src/testcases/os_callout_test_speak.c
+++ b/kernel/os/test/src/testcases/os_callout_test_speak.c
@@ -26,20 +26,20 @@ TEST_CASE(callout_test_speak)
     
     /* Initialize the sending task */
     os_task_init(&callout_task_struct_speak, "callout_task_speak",
-        callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
-        callout_task_stack_speak, CALLOUT_STACK_SIZE);
+        callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO,
+        OS_WAIT_FOREVER, callout_task_stack_speak, CALLOUT_STACK_SIZE);
 
     /* Initialize the receive task */
     os_task_init(&callout_task_struct_listen, "callout_task_listen",
-        callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
-        callout_task_stack_listen, CALLOUT_STACK_SIZE);
+        callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO,
+        OS_WAIT_FOREVER, callout_task_stack_listen, CALLOUT_STACK_SIZE);
 
     os_eventq_init(&callout_evq);
     
     /* Initialize the callout function */
-    os_callout_func_init(&callout_func_speak, &callout_evq,
+    os_callout_init(&callout_speak, &callout_evq,
         my_callout_speak_func, NULL);    
+
     /* Does not return until OS_restart is called */
     os_start();
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test_stop.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_stop.c b/kernel/os/test/src/testcases/os_callout_test_stop.c
index b4e92b4..da7674d 100644
--- a/kernel/os/test/src/testcases/os_callout_test_stop.c
+++ b/kernel/os/test/src/testcases/os_callout_test_stop.c
@@ -27,13 +27,14 @@ TEST_CASE(callout_test_stop)
 
     /* Initialize the sending task */
     os_task_init(&callout_task_struct_stop_send, "callout_task_stop_send",
-        callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
-        callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
+        callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO,
+        OS_WAIT_FOREVER, callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
 
     /* Initialize the receiving task */
-    os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive",
-        callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO,
-        OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
+    os_task_init(&callout_task_struct_stop_receive,
+        "callout_task_stop_receive", callout_task_stop_receive, NULL,
+        RECEIVE_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
 
     for(k = 0; k< MULTI_SIZE; k++){
         os_eventq_init(&callout_stop_evq[k]);
@@ -41,7 +42,7 @@ TEST_CASE(callout_test_stop)
     
     /* Initialize the callout function */
     for(k = 0; k<MULTI_SIZE; k++){
-        os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
+        os_callout_init(&callout_stop_test[k], &callout_stop_evq[k],
            my_callout_stop_func, NULL);
     }
 


[09/11] incubator-mynewt-core git commit: Sample apps: Event codes -> callbacks

Posted by cc...@apache.org.
Sample apps: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: 7cf94f6111b6de3c73a7926878dd87ff57e60e2d
Parents: 146da29
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 18:11:05 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:36 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c    | 33 ++++++++-----------------------
 apps/bleprph/src/main.c    | 39 ++++++++----------------------------
 apps/bletest/src/main.c    | 33 +++++++++++--------------------
 apps/bletiny/src/main.c    | 41 +++++++++++++-------------------------
 apps/bleuart/src/main.c    | 35 ++++++--------------------------
 apps/ocf_sample/src/main.c |  7 -------
 apps/slinky/src/main.c     | 44 ++++++++++++++++++++++++++++++++++-------
 7 files changed, 84 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index a65b724..4d52a0f 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -461,29 +461,8 @@ blecent_on_sync(void)
 static void
 blecent_task_handler(void *unused)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
-    int rc;
-
-    /* Activate the host.  This causes the host to synchronize with the
-     * controller.
-     */
-    rc = ble_hs_start();
-    assert(rc == 0);
-
     while (1) {
-        ev = os_eventq_get(&blecent_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&blecent_evq);
     }
 }
 
@@ -505,7 +484,8 @@ main(void)
     sysinit();
 
     /* Initialize the blecent log. */
-    log_register("blecent", &blecent_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+    log_register("blecent", &blecent_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
 
     /* Initialize the eventq for the application task. */
     os_eventq_init(&blecent_evq);
@@ -518,8 +498,8 @@ main(void)
                  blecent_stack, BLECENT_STACK_SIZE);
 
     /* Configure the host. */
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-    ble_hs_cfg.parent_evq = &blecent_evq;
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
     ble_hs_cfg.reset_cb = blecent_on_reset;
     ble_hs_cfg.sync_cb = blecent_on_sync;
     ble_hs_cfg.store_read_cb = ble_store_ram_read;
@@ -533,6 +513,9 @@ main(void)
     rc = ble_svc_gap_device_name_set("nimble-blecent");
     assert(rc == 0);
 
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&blecent_evq);
+
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index e9a99e0..3e0a818 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -253,34 +253,8 @@ bleprph_on_sync(void)
 static void
 bleprph_task_handler(void *unused)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
-    int rc;
-
-    /* Activate the host.  This causes the host to synchronize with the
-     * controller.
-     */
-    rc = ble_hs_start();
-
     while (1) {
-        ev = os_eventq_get(&bleprph_evq);
-
-        /* Check if the event is a nmgr ble mqueue event */
-        rc = nmgr_ble_proc_mq_evt(ev);
-        if (!rc) {
-            continue;
-        }
-
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&bleprph_evq);
     }
 }
 
@@ -301,13 +275,12 @@ main(void)
     /* Set initial BLE device address. */
     memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
 
-    ble_hs_cfg.parent_evq = &bleprph_evq;
-
     /* Initialize OS */
     sysinit();
 
     /* Initialize the bleprph log. */
-    log_register("bleprph", &bleprph_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+    log_register("bleprph", &bleprph_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
 
     /* Initialize eventq */
     os_eventq_init(&bleprph_evq);
@@ -320,7 +293,8 @@ main(void)
                  bleprph_stack, BLEPRPH_STACK_SIZE);
 
     /* Initialize the NimBLE host configuration. */
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;
     ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
@@ -332,6 +306,9 @@ main(void)
     rc = ble_svc_gap_device_name_set("nimble-bleprph");
     assert(rc == 0);
 
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&bleprph_evq);
+
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 92b3c0d..8f3f52b 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -120,7 +120,7 @@ uint8_t g_host_adv_len;
 uint32_t g_next_os_time;
 int g_bletest_state;
 struct os_eventq g_bletest_evq;
-struct os_callout_func g_bletest_timer;
+struct os_callout g_bletest_timer;
 struct os_task bletest_task;
 bssnz_t os_stack_t bletest_stack[BLETEST_STACK_SIZE];
 uint32_t g_bletest_conn_end;
@@ -853,13 +853,13 @@ bletest_execute(void)
  * @param arg
  */
 void
-bletest_timer_cb(void *arg)
+bletest_timer_cb(struct os_event *ev)
 {
     /* Call the bletest code */
     bletest_execute();
 
     /* Re-start the timer (run every 10 msecs) */
-    os_callout_reset(&g_bletest_timer.cf_c, OS_TICKS_PER_SEC / 100);
+    os_callout_reset(&g_bletest_timer, OS_TICKS_PER_SEC / 100);
 }
 
 /**
@@ -873,8 +873,6 @@ bletest_task_handler(void *arg)
     int rc;
     uint64_t rand64;
     uint64_t event_mask;
-    struct os_event *ev;
-    struct os_callout_func *cf;
 
     /* Set LED blink rate */
     g_bletest_led_rate = OS_TICKS_PER_SEC / 20;
@@ -883,8 +881,8 @@ bletest_task_handler(void *arg)
     os_time_delay(OS_TICKS_PER_SEC);
 
     /* Initialize the host timer */
-    os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
-                         NULL);
+    os_callout_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
+                    NULL);
 
     ble_hs_dbg_set_sync_state(BLE_HS_SYNC_STATE_GOOD);
 
@@ -999,17 +997,7 @@ bletest_task_handler(void *arg)
     bletest_timer_cb(NULL);
 
     while (1) {
-        ev = os_eventq_get(&g_bletest_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&g_bletest_evq);
     }
 }
 
@@ -1061,10 +1049,8 @@ main(void)
     g_bletest_cur_peer_addr[5] = 0x08;
 #endif
 
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-
-    /* Set the NimBLE host's parent event queue. */
-    ble_hs_cfg.parent_evq = &g_bletest_evq;
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
 
     /* Set the led pin as an output */
     g_led_pin = LED_BLINK_PIN;
@@ -1078,6 +1064,9 @@ main(void)
                       BLETEST_STACK_SIZE);
     assert(rc == 0);
 
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&g_bletest_evq);
+
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 7ee26e8..048a3c7 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -105,7 +105,7 @@ static struct os_mempool bletiny_chr_pool;
 static void *bletiny_dsc_mem;
 static struct os_mempool bletiny_dsc_pool;
 
-static struct os_callout_func bletiny_tx_timer;
+static struct os_callout bletiny_tx_timer;
 struct bletiny_tx_data_s
 {
     uint16_t tx_num;
@@ -1029,7 +1029,7 @@ bletiny_on_l2cap_update(uint16_t conn_handle, int status, void *arg)
 }
 
 static void
-bletiny_tx_timer_cb(void *arg)
+bletiny_tx_timer_cb(struct os_event *ev)
 {
     int i;
     uint8_t len;
@@ -1081,7 +1081,7 @@ bletiny_tx_timer_cb(void *arg)
     if (bletiny_tx_data.tx_num) {
         timeout = (int32_t)bletiny_tx_data.tx_rate;
         timeout = (timeout * OS_TICKS_PER_SEC) / 1000;
-        os_callout_reset(&bletiny_tx_timer.cf_c, timeout);
+        os_callout_reset(&bletiny_tx_timer, timeout);
     }
 }
 
@@ -1523,7 +1523,7 @@ bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate, uint16_t num)
     bletiny_tx_data.tx_len = len;
     bletiny_tx_data.tx_handle = handle;
 
-    os_callout_reset(&bletiny_tx_timer.cf_c, 0);
+    os_callout_reset(&bletiny_tx_timer, 0);
 
     return 0;
 }
@@ -1555,25 +1555,8 @@ bletiny_on_reset(int reason)
 static void
 bletiny_task_handler(void *arg)
 {
-    struct os_callout_func *cf;
-    struct os_event *ev;
-    int rc;
-
-    rc = ble_hs_start();
-    assert(rc == 0);
-
     while (1) {
-        ev = os_eventq_get(&bletiny_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&bletiny_evq);
     }
 }
 
@@ -1623,7 +1606,8 @@ main(void)
     assert(rc == 0);
 
     /* Initialize the logging system. */
-    log_register("bletiny", &bletiny_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+    log_register("bletiny", &bletiny_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
 
     /* Initialize eventq for the application task. */
     os_eventq_init(&bletiny_evq);
@@ -1636,8 +1620,8 @@ main(void)
                  bletiny_stack, BLETINY_STACK_SIZE);
 
     /* Initialize the NimBLE host configuration. */
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-    ble_hs_cfg.parent_evq = &bletiny_evq;
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
     ble_hs_cfg.reset_cb = bletiny_on_reset;
     ble_hs_cfg.store_read_cb = ble_store_ram_read;
     ble_hs_cfg.store_write_cb = ble_store_ram_write;
@@ -1656,8 +1640,11 @@ main(void)
     /* Create a callout (timer).  This callout is used by the "tx" bletiny
      * command to repeatedly send packets of sequential data bytes.
      */
-    os_callout_func_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
-                         NULL);
+    os_callout_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
+                    NULL);
+
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&bletiny_evq);
 
     /* Start the OS */
     os_start();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 4f6369a..d6fed4d 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -193,33 +193,7 @@ bleuart_on_sync(void)
 static void
 bleuart_task_handler(void *unused)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
-    int rc;
-
-    rc = ble_hs_start();
-    assert(rc == 0);
-
-    while (1) {
-        ev = os_eventq_get(&bleuart_evq);
-
-        /* Check if the event is a nmgr ble mqueue event */
-        rc = nmgr_ble_proc_mq_evt(ev);
-        if (!rc) {
-            continue;
-        }
-
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(CF_ARG(cf));
-            break;
-        default:
-            assert(0);
-            break;
-        }
-    }
+    os_eventq_run(&bleuart_evq);
 }
 
 /**
@@ -244,8 +218,8 @@ main(void)
                  bleuart_stack, bleuart_STACK_SIZE);
 
     /* Initialize the BLE host. */
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-    ble_hs_cfg.parent_evq = &bleuart_evq;
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+                 LOG_SYSLEVEL);
     ble_hs_cfg.sync_cb = bleuart_on_sync;
     ble_hs_cfg.store_read_cb = ble_store_ram_read;
     ble_hs_cfg.store_write_cb = ble_store_ram_write;
@@ -260,6 +234,9 @@ main(void)
     rc = ble_svc_gap_device_name_set("Mynewt_BLEuart");
     assert(rc == 0);
 
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&bleuart_evq);
+
     /* Start the OS */
     os_start();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index c1f1b4c..d9888f7 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -233,13 +233,6 @@ oc_signal_main_loop(void)
 void
 ocf_task_handler(void *arg)
 {
-#if MYNEWT_VAL(OC_TRANSPORT_GATT)
-    int rc;
-
-    rc = ble_hs_start();
-    assert(rc == 0);
-#endif
-
     os_sem_init(&ocf_main_loop_sem, 1);
 
     while (1) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 143690f..cb808de 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -52,7 +52,6 @@
 
 /* Init all tasks */
 static volatile int tasks_initialized;
-int init_tasks(void);
 
 /* Task 1 */
 #define TASK1_PRIO (8)
@@ -63,9 +62,14 @@ static volatile int g_task1_loops;
 
 /* Task 2 */
 #define TASK2_PRIO (9)
-#define TASK2_STACK_SIZE    OS_STACK_ALIGN(128)
+#define TASK2_STACK_SIZE    OS_STACK_ALIGN(64)
 static struct os_task task2;
 
+/* Task 3 */
+#define TASK3_PRIO (10)
+#define TASK3_STACK_SIZE    OS_STACK_ALIGN(384)
+static struct os_task task3;
+
 static struct log my_log;
 
 static volatile int g_task2_loops;
@@ -106,6 +110,8 @@ static char test_str[32];
 static uint32_t cbmem_buf[MAX_CBMEM_BUF];
 static struct cbmem cbmem;
 
+static struct os_eventq slinky_evq;
+
 static char *
 test_conf_get(int argc, char **argv, char *buf, int max_len)
 {
@@ -151,7 +157,7 @@ test_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt)
     return 0;
 }
 
-void
+static void
 task1_handler(void *arg)
 {
     struct os_task *t;
@@ -191,7 +197,7 @@ task1_handler(void *arg)
     }
 }
 
-void
+static void
 task2_handler(void *arg)
 {
     struct os_task *t;
@@ -210,6 +216,18 @@ task2_handler(void *arg)
 }
 
 /**
+ * This task serves as a container for the shell and newtmgr packages.  These
+ * packages enqueue timer events when they need this task to do work.
+ */
+static void
+task3_handler(void *arg)
+{
+    while (1) {
+        os_eventq_run(&slinky_evq);
+    }
+}
+
+/**
  * init_tasks
  *
  * Called by main.c after sysinit(). This function performs initializations
@@ -217,7 +235,7 @@ task2_handler(void *arg)
  *
  * @return int 0 success; error otherwise.
  */
-int
+static void
 init_tasks(void)
 {
     os_stack_t *pstack;
@@ -236,8 +254,20 @@ init_tasks(void)
     os_task_init(&task2, "task2", task2_handler, NULL,
             TASK2_PRIO, OS_WAIT_FOREVER, pstack, TASK2_STACK_SIZE);
 
+    pstack = malloc(sizeof(os_stack_t)*TASK3_STACK_SIZE);
+    assert(pstack);
+
+    os_task_init(&task3, "task3", task3_handler, NULL,
+            TASK3_PRIO, OS_WAIT_FOREVER, pstack, TASK3_STACK_SIZE);
+
+    /* Initialize eventq and designate it as the default.  Packages that need
+     * to schedule work items will piggyback on this eventq.  Example packages
+     * which do this are sys/shell and mgmt/newtmgr.
+     */
+    os_eventq_init(&slinky_evq);
+    os_eventq_dflt_set(&slinky_evq);
+
     tasks_initialized = 1;
-    return 0;
 }
 
 /**
@@ -288,7 +318,7 @@ main(int argc, char **argv)
     }
 #endif
 
-    rc = init_tasks();
+    init_tasks();
 
     os_start();
 


[06/11] incubator-mynewt-core git commit: BLE Controller: Event codes -> callbacks

Posted by cc...@apache.org.
BLE Controller: Event codes -> callbacks


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

Branch: refs/heads/develop
Commit: cf38f1ff6fc2946e3e4caafb37c521890fcfc251
Parents: 98c990f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 31 17:43:27 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:12 2016 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll.h      | 12 +--
 .../controller/include/controller/ble_ll_adv.h  |  3 -
 .../controller/include/controller/ble_ll_conn.h |  4 +-
 .../controller/include/controller/ble_ll_hci.h  |  3 -
 .../controller/include/controller/ble_ll_scan.h |  3 -
 net/nimble/controller/src/ble_ll.c              | 83 ++++++++------------
 net/nimble/controller/src/ble_ll_adv.c          | 20 +++--
 net/nimble/controller/src/ble_ll_conn.c         | 38 +++++----
 net/nimble/controller/src/ble_ll_conn_hci.c     |  2 +-
 net/nimble/controller/src/ble_ll_conn_priv.h    |  2 -
 net/nimble/controller/src/ble_ll_ctrl.c         | 19 ++---
 net/nimble/controller/src/ble_ll_hci.c          |  6 +-
 net/nimble/controller/src/ble_ll_resolv.c       | 24 +++---
 net/nimble/controller/src/ble_ll_scan.c         |  8 +-
 14 files changed, 99 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index 875665f..e349d71 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -85,7 +85,7 @@ struct ble_ll_obj
     struct os_event ll_dbuf_overflow_ev;
 
     /* HW error callout */
-    struct os_callout_func ll_hw_err_timer;
+    struct os_callout ll_hw_err_timer;
 };
 extern struct ble_ll_obj g_ble_ll_data;
 
@@ -132,16 +132,6 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats;
 #define BLE_LL_STATE_INITIATING     (3)
 #define BLE_LL_STATE_CONNECTION     (4)
 
-/* BLE LL Task Events */
-#define BLE_LL_EVENT_HCI_CMD        (OS_EVENT_T_PERUSER)
-#define BLE_LL_EVENT_ADV_EV_DONE    (OS_EVENT_T_PERUSER + 1)
-#define BLE_LL_EVENT_RX_PKT_IN      (OS_EVENT_T_PERUSER + 2)
-#define BLE_LL_EVENT_SCAN           (OS_EVENT_T_PERUSER + 3)
-#define BLE_LL_EVENT_CONN_SPVN_TMO  (OS_EVENT_T_PERUSER + 4)
-#define BLE_LL_EVENT_CONN_EV_END    (OS_EVENT_T_PERUSER + 5)
-#define BLE_LL_EVENT_TX_PKT_IN      (OS_EVENT_T_PERUSER + 6)
-#define BLE_LL_EVENT_DBUF_OVERFLOW  (OS_EVENT_T_PERUSER + 7)
-
 /* LL Features */
 #define BLE_LL_FEAT_LE_ENCRYPTION   (0x01)
 #define BLE_LL_FEAT_CONN_PARM_REQ   (0x02)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/include/controller/ble_ll_adv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_adv.h b/net/nimble/controller/include/controller/ble_ll_adv.h
index 0f46f18..613efc0 100644
--- a/net/nimble/controller/include/controller/ble_ll_adv.h
+++ b/net/nimble/controller/include/controller/ble_ll_adv.h
@@ -129,9 +129,6 @@ uint8_t *ble_ll_adv_get_local_rpa(void);
 /* Returns peer resolvable private address */
 uint8_t *ble_ll_adv_get_peer_rpa(void);
 
-/* Called when advertising event done posted to LL task */
-void ble_ll_adv_event_done(void *arg);
-
 /* Called to initialize advertising functionality. */
 void ble_ll_adv_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index f7dd1ae..6e6688c 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -231,13 +231,13 @@ struct ble_ll_conn_sm
     };
 
     /* LL control procedure response timer */
-    struct os_callout_func ctrl_proc_rsp_timer;
+    struct os_callout ctrl_proc_rsp_timer;
 
     /* For scheduling connections */
     struct ble_ll_sched_item conn_sch;
 
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING) == 1)
-    struct os_callout_func auth_pyld_timer;
+    struct os_callout auth_pyld_timer;
 #endif
 
     /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/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 a272aa6..05f0be6 100644
--- a/net/nimble/controller/include/controller/ble_ll_hci.h
+++ b/net/nimble/controller/include/controller/ble_ll_hci.h
@@ -40,9 +40,6 @@ extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
 /* Initialize LL HCI */
 void ble_ll_hci_init(void);
 
-/* HCI command processing function */
-void ble_ll_hci_cmd_proc(struct os_event *ev);
-
 /* Used to determine if the LE event is enabled/disabled */
 uint8_t ble_ll_hci_is_le_event_enabled(int subev);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/include/controller/ble_ll_scan.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_scan.h b/net/nimble/controller/include/controller/ble_ll_scan.h
index 91357a6..f9689f0 100644
--- a/net/nimble/controller/include/controller/ble_ll_scan.h
+++ b/net/nimble/controller/include/controller/ble_ll_scan.h
@@ -90,9 +90,6 @@ int ble_ll_scan_set_scan_params(uint8_t *cmd);
 int ble_ll_scan_set_enable(uint8_t *cmd);
 
 /*--- Controller Internal API ---*/
-/* Process scan window end event */
-void ble_ll_scan_event_proc(void *arg);
-
 /* Initialize the scanner */
 void ble_ll_scan_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/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 f694b6d..3504b60 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -181,6 +181,10 @@ STATS_NAME_START(ble_ll_stats)
     STATS_NAME(ble_ll_stats, scan_rsp_txg)
 STATS_NAME_END(ble_ll_stats)
 
+static void ble_ll_event_rx_pkt(struct os_event *ev);
+static void ble_ll_event_tx_pkt(struct os_event *ev);
+static void ble_ll_event_dbuf_overflow(struct os_event *ev);
+
 /* The BLE LL task data structure */
 #define BLE_LL_STACK_SIZE   (80)
 struct os_task g_ble_ll_task;
@@ -744,7 +748,7 @@ ble_ll_data_buffer_overflow(void)
 void
 ble_ll_hw_error(void)
 {
-    os_callout_reset(&g_ble_ll_data.ll_hw_err_timer.cf_c, 0);
+    os_callout_reset(&g_ble_ll_data.ll_hw_err_timer, 0);
 }
 
 /**
@@ -753,7 +757,7 @@ ble_ll_hw_error(void)
  * @param arg
  */
 static void
-ble_ll_hw_err_timer_cb(void *arg)
+ble_ll_hw_err_timer_cb(struct os_event *ev)
 {
     if (ble_ll_hci_ev_hw_err(BLE_HW_ERR_HCI_SYNC_LOSS)) {
         /*
@@ -761,7 +765,7 @@ ble_ll_hw_err_timer_cb(void *arg)
          * event every 50 milliseconds (or each OS tick if a tick is longer
          * than 100 msecs).
          */
-        os_callout_reset(&g_ble_ll_data.ll_hw_err_timer.cf_c,
+        os_callout_reset(&g_ble_ll_data.ll_hw_err_timer,
                          OS_TICKS_PER_SEC / 20);
     }
 }
@@ -953,6 +957,24 @@ ble_ll_rx_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
     return rc;
 }
 
+static void
+ble_ll_event_rx_pkt(struct os_event *ev)
+{
+    ble_ll_rx_pkt_in();
+}
+
+static void
+ble_ll_event_tx_pkt(struct os_event *ev)
+{
+    ble_ll_tx_pkt_in();
+}
+
+static void
+ble_ll_event_dbuf_overflow(struct os_event *ev)
+{
+    ble_ll_hci_ev_databuf_overflow();
+}
+
 /**
  * Link Layer task.
  *
@@ -963,9 +985,6 @@ ble_ll_rx_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
 void
 ble_ll_task(void *arg)
 {
-    struct os_event *ev;
-    struct os_callout_func *cf;
-
     /* Init ble phy */
     ble_phy_init();
 
@@ -977,44 +996,8 @@ ble_ll_task(void *arg)
 
     ble_ll_rand_start();
 
-    /* Wait for an event */
     while (1) {
-        ev = os_eventq_get(&g_ble_ll_data.ll_evq);
-        switch (ev->ev_type) {
-        case OS_EVENT_T_TIMER:
-            cf = (struct os_callout_func *)ev;
-            assert(cf->cf_func);
-            cf->cf_func(ev->ev_arg);
-            break;
-        case BLE_LL_EVENT_HCI_CMD:
-            /* Process HCI command */
-            ble_ll_hci_cmd_proc(ev);
-            break;
-        case BLE_LL_EVENT_ADV_EV_DONE:
-            ble_ll_adv_event_done(ev->ev_arg);
-            break;
-        case BLE_LL_EVENT_SCAN:
-            ble_ll_scan_event_proc(ev->ev_arg);
-            break;
-        case BLE_LL_EVENT_RX_PKT_IN:
-            ble_ll_rx_pkt_in();
-            break;
-        case BLE_LL_EVENT_TX_PKT_IN:
-            ble_ll_tx_pkt_in();
-            break;
-        case BLE_LL_EVENT_DBUF_OVERFLOW:
-            ble_ll_hci_ev_databuf_overflow();
-            break;
-        case BLE_LL_EVENT_CONN_SPVN_TMO:
-            ble_ll_conn_spvn_timeout(ev->ev_arg);
-            break;
-        case BLE_LL_EVENT_CONN_EV_END:
-            ble_ll_conn_event_end(ev->ev_arg);
-            break;
-        default:
-            assert(0);
-            break;
-        }
+        os_eventq_run(&g_ble_ll_data.ll_evq);
     }
 }
 
@@ -1244,15 +1227,15 @@ ble_ll_init(void)
     STAILQ_INIT(&lldata->ll_rx_pkt_q);
 
     /* Initialize transmit (from host) and receive packet (from phy) event */
-    lldata->ll_rx_pkt_ev.ev_type = BLE_LL_EVENT_RX_PKT_IN;
-    lldata->ll_tx_pkt_ev.ev_type = BLE_LL_EVENT_TX_PKT_IN;
-    lldata->ll_dbuf_overflow_ev.ev_type = BLE_LL_EVENT_DBUF_OVERFLOW;
+    lldata->ll_rx_pkt_ev.ev_cb = ble_ll_event_rx_pkt;
+    lldata->ll_tx_pkt_ev.ev_cb = ble_ll_event_tx_pkt;
+    lldata->ll_dbuf_overflow_ev.ev_cb = ble_ll_event_dbuf_overflow;
 
     /* Initialize the HW error timer */
-    os_callout_func_init(&g_ble_ll_data.ll_hw_err_timer,
-                         &g_ble_ll_data.ll_evq,
-                         ble_ll_hw_err_timer_cb,
-                         NULL);
+    os_callout_init(&g_ble_ll_data.ll_hw_err_timer,
+                    &g_ble_ll_data.ll_evq,
+                    ble_ll_hw_err_timer_cb,
+                    NULL);
 
     /* Initialize wait for response timer */
     os_cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c
index 856b8af..a4c59c6 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -104,6 +104,8 @@ struct ble_ll_adv_sm
 /* The advertising state machine global object */
 struct ble_ll_adv_sm g_ble_ll_adv_sm;
 
+static void ble_ll_adv_done(struct ble_ll_adv_sm *advsm);
+
 /*
  * Worst case time needed for scheduled advertising item. This is the longest
  * possible time to receive a scan request and send a scan response (with the
@@ -122,7 +124,6 @@ struct ble_ll_adv_sm g_ble_ll_adv_sm;
 #define BLE_LL_ADV_SCHED_MAX_USECS          (852)
 #define BLE_LL_ADV_DIRECT_SCHED_MAX_USECS   (502)
 
-
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
 /**
  * Called to change advertisers ADVA and INITA (for directed advertisements)
@@ -1194,7 +1195,7 @@ ble_ll_adv_rx_pkt_in(uint8_t ptype, uint8_t *rxbuf, struct ble_mbuf_hdr *hdr)
     }
 
     if (adv_event_over) {
-        ble_ll_adv_event_done(&g_ble_ll_adv_sm);
+        ble_ll_adv_done(&g_ble_ll_adv_sm);
     }
 }
 
@@ -1257,18 +1258,15 @@ ble_ll_adv_rx_isr_start(uint8_t pdu_type)
  *
  * @param arg Pointer to advertising state machine.
  */
-void
-ble_ll_adv_event_done(void *arg)
+static void
+ble_ll_adv_done(struct ble_ll_adv_sm *advsm)
 {
     uint8_t mask;
     uint8_t final_adv_chan;
     int32_t delta_t;
     uint32_t itvl;
     uint32_t start_time;
-    struct ble_ll_adv_sm *advsm;
 
-    /* Stop advertising event */
-    advsm = (struct ble_ll_adv_sm *)arg;
     assert(advsm->enabled);
 
     /* Remove the element from the schedule if it is still there. */
@@ -1377,6 +1375,12 @@ ble_ll_adv_event_done(void *arg)
     }
 }
 
+static void
+ble_ll_adv_event_done(struct os_event *ev)
+{
+    ble_ll_adv_done(ev->ev_arg);
+}
+
 /**
  * Checks if the controller can change the whitelist. If advertising is enabled
  * and is using the whitelist the controller is not allowed to change the
@@ -1511,7 +1515,7 @@ ble_ll_adv_init(void)
     advsm->adv_chanmask = BLE_HCI_ADV_CHANMASK_DEF;
 
     /* Initialize advertising tx done event */
-    advsm->adv_txdone_ev.ev_type = BLE_LL_EVENT_ADV_EV_DONE;
+    advsm->adv_txdone_ev.ev_cb = ble_ll_adv_event_done;
     advsm->adv_txdone_ev.ev_arg = advsm;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/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 ab04e7f..ec61fa4 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -216,6 +216,9 @@ STATS_NAME_START(ble_ll_conn_stats)
     STATS_NAME(ble_ll_conn_stats, mic_failures)
 STATS_NAME_END(ble_ll_conn_stats)
 
+static void ble_ll_conn_spvn_timeout(struct os_event *ev);
+static void ble_ll_conn_event_end(struct os_event *ev);
+
 /**
  * Get the event buffer allocated to send the connection complete event
  * when we are initiating.
@@ -1300,11 +1303,11 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime)
  * @param arg
  */
 void
-ble_ll_conn_auth_pyld_timer_cb(void *arg)
+ble_ll_conn_auth_pyld_timer_cb(struct os_event *ev)
 {
     struct ble_ll_conn_sm *connsm;
 
-    connsm = (struct ble_ll_conn_sm *)arg;
+    connsm = (struct ble_ll_conn_sm *)ev->ev_arg;
     ble_ll_auth_pyld_tmo_event_send(connsm);
     ble_ll_ctrl_proc_start(connsm, BLE_LL_CTRL_PROC_LE_PING);
     ble_ll_conn_auth_pyld_timer_start(connsm);
@@ -1322,7 +1325,7 @@ ble_ll_conn_auth_pyld_timer_start(struct ble_ll_conn_sm *connsm)
 
     /* Timeout in is in 10 msec units */
     tmo = (int32_t)BLE_LL_CONN_AUTH_PYLD_OS_TMO(connsm->auth_pyld_tmo);
-    os_callout_reset(&connsm->auth_pyld_timer.cf_c, tmo);
+    os_callout_reset(&connsm->auth_pyld_timer, tmo);
 }
 #endif
 
@@ -1458,12 +1461,12 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
     /* Initialize event */
     connsm->conn_spvn_ev.ev_arg = connsm;
     connsm->conn_spvn_ev.ev_queued = 0;
-    connsm->conn_spvn_ev.ev_type = BLE_LL_EVENT_CONN_SPVN_TMO;
+    connsm->conn_spvn_ev.ev_cb = ble_ll_conn_spvn_timeout;
 
     /* Connection end event */
     connsm->conn_ev_end.ev_arg = connsm;
     connsm->conn_ev_end.ev_queued = 0;
-    connsm->conn_ev_end.ev_type = BLE_LL_EVENT_CONN_EV_END;
+    connsm->conn_ev_end.ev_cb = ble_ll_conn_event_end;
 
     /* Initialize transmit queue and ack/flow control elements */
     STAILQ_INIT(&connsm->conn_txq);
@@ -1498,10 +1501,10 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING)
     connsm->auth_pyld_tmo = BLE_LL_CONN_DEF_AUTH_PYLD_TMO;
     CONN_F_LE_PING_SUPP(connsm) = 1;
-    os_callout_func_init(&connsm->auth_pyld_timer,
-                         &g_ble_ll_data.ll_evq,
-                         ble_ll_conn_auth_pyld_timer_cb,
-                         connsm);
+    os_callout_init(&connsm->auth_pyld_timer,
+                    &g_ble_ll_data.ll_evq,
+                    ble_ll_conn_auth_pyld_timer_cb,
+                    connsm);
 #endif
 
     /* Add to list of active connections */
@@ -1582,10 +1585,10 @@ ble_ll_conn_end(struct ble_ll_conn_sm *connsm, uint8_t ble_err)
     os_cputime_timer_stop(&connsm->conn_spvn_timer);
 
     /* Stop any control procedures that might be running */
-    os_callout_stop(&connsm->ctrl_proc_rsp_timer.cf_c);
+    os_callout_stop(&connsm->ctrl_proc_rsp_timer);
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING)
-    os_callout_stop(&connsm->auth_pyld_timer.cf_c);
+    os_callout_stop(&connsm->auth_pyld_timer);
 #endif
 
     /* Remove from the active connection list */
@@ -1882,14 +1885,14 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, uint32_t endtime)
  * @param void *arg Pointer to connection state machine
  *
  */
-void
-ble_ll_conn_event_end(void *arg)
+static void
+ble_ll_conn_event_end(struct os_event *ev)
 {
     uint8_t ble_err;
     struct ble_ll_conn_sm *connsm;
 
     /* Better be a connection state machine! */
-    connsm = (struct ble_ll_conn_sm *)arg;
+    connsm = (struct ble_ll_conn_sm *)ev->ev_arg;
     assert(connsm);
 
     /* Check if we need to resume scanning */
@@ -2449,10 +2452,11 @@ ble_ll_conn_timeout(struct ble_ll_conn_sm *connsm, uint8_t ble_err)
  *
  * @param arg Pointer to connection state machine.
  */
-void
-ble_ll_conn_spvn_timeout(void *arg)
+static void
+ble_ll_conn_spvn_timeout(struct os_event *ev)
 {
-    ble_ll_conn_timeout((struct ble_ll_conn_sm *)arg, BLE_ERR_CONN_SPVN_TMO);
+    ble_ll_conn_timeout((struct ble_ll_conn_sm *)ev->ev_arg,
+                        BLE_ERR_CONN_SPVN_TMO);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index d961b90..0ce49f8 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -1182,7 +1182,7 @@ ble_ll_conn_hci_wr_auth_pyld_tmo(uint8_t *cmdbuf, uint8_t *rsp, uint8_t *rsplen)
         rc = BLE_ERR_INV_HCI_CMD_PARMS;
     } else {
         connsm->auth_pyld_tmo = tmo;
-        if (os_callout_queued(&connsm->auth_pyld_timer.cf_c)) {
+        if (os_callout_queued(&connsm->auth_pyld_timer)) {
             ble_ll_conn_auth_pyld_timer_start(connsm);
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/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 9e393b5..f1abbdc 100644
--- a/net/nimble/controller/src/ble_ll_conn_priv.h
+++ b/net/nimble/controller/src/ble_ll_conn_priv.h
@@ -110,9 +110,7 @@ int ble_ll_conn_slave_start(uint8_t *rxbuf, uint32_t conn_req_end, uint8_t pat);
 void ble_ll_conn_module_init(void);
 void ble_ll_conn_set_global_chanmap(uint8_t num_used_chans, uint8_t *chanmap);
 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);
 int ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa);
 int ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr);
 void ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index 8e79f10..4231e40 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -308,7 +308,7 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
     case BLE_LL_CTRL_PING_REQ:
         CONN_F_LE_PING_SUPP(connsm) = 0;
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_PING) == 1)
-        os_callout_stop(&connsm->auth_pyld_timer.cf_c);
+        os_callout_stop(&connsm->auth_pyld_timer);
 #endif
         ctrl_proc = BLE_LL_CTRL_PROC_LE_PING;
         break;
@@ -1232,10 +1232,11 @@ ble_ll_ctrl_rx_chanmap_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
  * @param arg Pointer to connection state machine.
  */
 void
-ble_ll_ctrl_proc_rsp_timer_cb(void *arg)
+ble_ll_ctrl_proc_rsp_timer_cb(struct os_event *ev)
 {
     /* Control procedure has timed out. Kill the connection */
-    ble_ll_conn_timeout((struct ble_ll_conn_sm *)arg, BLE_ERR_LMP_LL_RSP_TMO);
+    ble_ll_conn_timeout((struct ble_ll_conn_sm *)ev->ev_arg,
+                        BLE_ERR_LMP_LL_RSP_TMO);
 }
 
 /**
@@ -1365,7 +1366,7 @@ void
 ble_ll_ctrl_proc_stop(struct ble_ll_conn_sm *connsm, int ctrl_proc)
 {
     if (connsm->cur_ctrl_proc == ctrl_proc) {
-        os_callout_stop(&connsm->ctrl_proc_rsp_timer.cf_c);
+        os_callout_stop(&connsm->ctrl_proc_rsp_timer);
         connsm->cur_ctrl_proc = BLE_LL_CTRL_PROC_IDLE;
     }
     CLR_PENDING_CTRL_PROC(connsm, ctrl_proc);
@@ -1428,13 +1429,13 @@ ble_ll_ctrl_proc_start(struct ble_ll_conn_sm *connsm, int ctrl_proc)
 
             /* Initialize the procedure response timeout */
             if (ctrl_proc != BLE_LL_CTRL_PROC_CHAN_MAP_UPD) {
-                os_callout_func_init(&connsm->ctrl_proc_rsp_timer,
-                                     &g_ble_ll_data.ll_evq,
-                                     ble_ll_ctrl_proc_rsp_timer_cb,
-                                     connsm);
+                os_callout_init(&connsm->ctrl_proc_rsp_timer,
+                                &g_ble_ll_data.ll_evq,
+                                ble_ll_ctrl_proc_rsp_timer_cb,
+                                connsm);
 
                 /* Re-start timer. Control procedure timeout is 40 seconds */
-                os_callout_reset(&connsm->ctrl_proc_rsp_timer.cf_c,
+                os_callout_reset(&connsm->ctrl_proc_rsp_timer,
                                  OS_TICKS_PER_SEC * BLE_LL_CTRL_PROC_TIMEOUT);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/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 f3624c1..7b549ad 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -34,6 +34,8 @@
 #include "controller/ble_ll_resolv.h"
 #include "ble_ll_conn_priv.h"
 
+static void ble_ll_hci_cmd_proc(struct os_event *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];
@@ -906,7 +908,7 @@ ble_ll_hci_status_params_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen
  *
  * @param ev Pointer to os event containing a pointer to command buffer
  */
-void
+static void
 ble_ll_hci_cmd_proc(struct os_event *ev)
 {
     int rc;
@@ -1009,7 +1011,7 @@ ble_ll_hci_cmd_rx(uint8_t *cmd, void *arg)
 
     /* Fill out the event and post to Link Layer */
     ev->ev_queued = 0;
-    ev->ev_type = BLE_LL_EVENT_HCI_CMD;
+    ev->ev_cb = ble_ll_hci_cmd_proc;
     ev->ev_arg = cmd;
     os_eventq_put(&g_ble_ll_data.ll_evq, ev);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/src/ble_ll_resolv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_resolv.c b/net/nimble/controller/src/ble_ll_resolv.c
index 7fb5859..975f271 100644
--- a/net/nimble/controller/src/ble_ll_resolv.c
+++ b/net/nimble/controller/src/ble_ll_resolv.c
@@ -38,7 +38,7 @@ struct ble_ll_resolv_data
     uint8_t rl_size;
     uint8_t rl_cnt;
     uint32_t rpa_tmo;
-    struct os_callout_func rpa_timer;
+    struct os_callout rpa_timer;
 };
 struct ble_ll_resolv_data g_ble_ll_resolv_data;
 
@@ -70,11 +70,9 @@ ble_ll_resolv_list_chg_allowed(void)
 /**
  * Called when the Resolvable private address timer expires. This timer
  * is used to regenerate local RPA's in the resolving list.
- *
- * @param arg
  */
 void
-ble_ll_resolv_rpa_timer_cb(void *arg)
+ble_ll_resolv_rpa_timer_cb(struct os_event *ev)
 {
     int i;
     os_sr_t sr;
@@ -89,7 +87,7 @@ ble_ll_resolv_rpa_timer_cb(void *arg)
         OS_EXIT_CRITICAL(sr);
         ++rl;
     }
-    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c,
+    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
                      (int32_t)g_ble_ll_resolv_data.rpa_tmo);
 }
 
@@ -319,9 +317,9 @@ ble_ll_resolv_enable_cmd(uint8_t *cmdbuf)
             if ((enabled ^ g_ble_ll_resolv_data.addr_res_enabled) != 0) {
                 if (enabled) {
                     tmo = (int32_t)g_ble_ll_resolv_data.rpa_tmo;
-                    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c, tmo);
+                    os_callout_reset(&g_ble_ll_resolv_data.rpa_timer, tmo);
                 } else {
-                    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer.cf_c);
+                    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer);
                 }
                 g_ble_ll_resolv_data.addr_res_enabled = enabled;
             }
@@ -363,7 +361,7 @@ ble_ll_resolv_set_rpa_tmo(uint8_t *cmdbuf)
     if ((tmo_secs > 0) && (tmo_secs <= 0xA1B8)) {
         g_ble_ll_resolv_data.rpa_tmo = tmo_secs * OS_TICKS_PER_SEC;
         if (g_ble_ll_resolv_data.addr_res_enabled) {
-            os_callout_reset(&g_ble_ll_resolv_data.rpa_timer.cf_c,
+            os_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
                              (int32_t)g_ble_ll_resolv_data.rpa_tmo);
         }
     } else {
@@ -543,7 +541,7 @@ void
 ble_ll_resolv_list_reset(void)
 {
     g_ble_ll_resolv_data.addr_res_enabled = 0;
-    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer.cf_c);
+    os_callout_stop(&g_ble_ll_resolv_data.rpa_timer);
     ble_ll_resolv_list_clr();
     ble_ll_resolv_init();
 }
@@ -562,10 +560,10 @@ ble_ll_resolv_init(void)
     }
     g_ble_ll_resolv_data.rl_size = hw_size;
 
-    os_callout_func_init(&g_ble_ll_resolv_data.rpa_timer,
-                         &g_ble_ll_data.ll_evq,
-                         ble_ll_resolv_rpa_timer_cb,
-                         NULL);
+    os_callout_init(&g_ble_ll_resolv_data.rpa_timer,
+                    &g_ble_ll_data.ll_evq,
+                    ble_ll_resolv_rpa_timer_cb,
+                    NULL);
 }
 
 #endif  /* if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1 */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cf38f1ff/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 808d090..01b8b1b 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -744,8 +744,8 @@ ble_ll_scan_sm_start(struct ble_ll_scan_sm *scansm)
  *
  * @param arg
  */
-void
-ble_ll_scan_event_proc(void *arg)
+static void
+ble_ll_scan_event_proc(struct os_event *ev)
 {
     os_sr_t sr;
     int rxstate;
@@ -763,7 +763,7 @@ ble_ll_scan_event_proc(void *arg)
      * Get the scanning state machine. If not enabled (this is possible), just
      * leave and do nothing (just make sure timer is stopped).
      */
-    scansm = (struct ble_ll_scan_sm *)arg;
+    scansm = (struct ble_ll_scan_sm *)ev->ev_arg;
     if (!scansm->scan_enabled) {
         os_cputime_timer_stop(&scansm->scan_timer);
         return;
@@ -1473,7 +1473,7 @@ ble_ll_scan_init(void)
     memset(scansm, 0, sizeof(struct ble_ll_scan_sm));
 
     /* Initialize scanning window end event */
-    scansm->scan_sched_ev.ev_type = BLE_LL_EVENT_SCAN;
+    scansm->scan_sched_ev.ev_cb = ble_ll_scan_event_proc;
     scansm->scan_sched_ev.ev_arg = scansm;
 
     /* Set all non-zero default parameters */