michal-narajowski closed pull request #98: Update Mesh to use NPL
URL: https://github.com/apache/mynewt-nimble/pull/98
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/mesh/include/mesh/glue.h 
b/nimble/host/mesh/include/mesh/glue.h
index bcea0a7c..d45cfbcf 100644
--- a/nimble/host/mesh/include/mesh/glue.h
+++ b/nimble/host/mesh/include/mesh/glue.h
@@ -24,10 +24,9 @@
 #include <errno.h>
 
 #include "syscfg/syscfg.h"
+#include "nimble/nimble_npl.h"
 
 #include "os/os_mbuf.h"
-#include "os/os_callout.h"
-#include "os/os_eventq.h"
 #include "os/queue.h"
 
 #include "atomic.h"
@@ -170,7 +169,7 @@
 
 typedef ble_addr_t bt_addr_le_t;
 
-#define k_fifo_init(queue) os_eventq_init(queue)
+#define k_fifo_init(queue) ble_npl_eventq_init(queue)
 #define net_buf_simple_tailroom(buf) OS_MBUF_TRAILINGSPACE(buf)
 #define net_buf_tailroom(buf) net_buf_simple_tailroom(buf)
 #define net_buf_headroom(buf) ((buf)->om_data - 
&(buf)->om_databuf[buf->om_pkthdr_len])
@@ -207,7 +206,7 @@ static inline void net_buf_simple_init(struct os_mbuf *buf,
     buf->om_len = 0;
 }
 
-void net_buf_put(struct os_eventq *fifo, struct os_mbuf *buf);
+void net_buf_put(struct ble_npl_eventq *fifo, struct os_mbuf *buf);
 void * net_buf_ref(struct os_mbuf *om);
 void net_buf_unref(struct os_mbuf *om);
 uint16_t net_buf_simple_pull_le16(struct os_mbuf *om);
@@ -224,8 +223,8 @@ void net_buf_simple_push_be16(struct os_mbuf *om, uint16_t 
val);
 void net_buf_simple_push_u8(struct os_mbuf *om, uint8_t val);
 void *net_buf_simple_pull(struct os_mbuf *om, uint8_t len);
 void *net_buf_simple_add(struct os_mbuf *om, uint8_t len);
-bool k_fifo_is_empty(struct os_eventq *q);
-void * net_buf_get(struct os_eventq *fifo,s32_t t);
+bool k_fifo_is_empty(struct ble_npl_eventq *q);
+void *net_buf_get(struct ble_npl_eventq *fifo,s32_t t);
 uint8_t *net_buf_simple_push(struct os_mbuf *om, uint8_t len);
 void net_buf_reserve(struct os_mbuf *om, size_t reserve);
 
@@ -279,18 +278,18 @@ int bt_le_adv_start(const struct ble_gap_adv_params 
*param,
                     const struct bt_data *sd, size_t sd_len);
 
 struct k_delayed_work {
-    struct os_callout work;
+    struct ble_npl_callout work;
 };
 
-void k_work_init(struct os_callout *work, os_event_fn handler);
-void k_delayed_work_init(struct k_delayed_work *w, os_event_fn *f);
+void k_work_init(struct ble_npl_callout *work, ble_npl_event_fn handler);
+void k_delayed_work_init(struct k_delayed_work *w, ble_npl_event_fn *f);
 void k_delayed_work_cancel(struct k_delayed_work *w);
 void k_delayed_work_submit(struct k_delayed_work *w, uint32_t ms);
 int64_t k_uptime_get(void);
 u32_t k_uptime_get_32(void);
 void k_sleep(int32_t duration);
-void k_work_submit(struct os_callout *w);
-void k_work_add_arg(struct os_callout *w, void *arg);
+void k_work_submit(struct ble_npl_callout *w);
+void k_work_add_arg(struct ble_npl_callout *w, void *arg);
 void k_delayed_work_add_arg(struct k_delayed_work *w, void *arg);
 uint32_t k_delayed_work_remaining_get(struct k_delayed_work *w);
 
@@ -367,25 +366,25 @@ static inline unsigned int find_msb_set(u32_t op)
        ((type *)(((char *)(ptr)) - offsetof(type, field)))
 
 
-#define k_sem os_sem
+#define k_sem ble_npl_sem
 
 static inline void k_sem_init(struct k_sem *sem, unsigned int initial_count,
                              unsigned int limit)
 {
-       os_sem_init(sem, initial_count);
+       ble_npl_sem_init(sem, initial_count);
 }
 
 static inline int k_sem_take(struct k_sem *sem, s32_t timeout)
 {
        uint32_t ticks;
 
-       os_time_ms_to_ticks(timeout, &ticks);
-       return - os_sem_pend(sem,  ticks);
+       ble_npl_time_ms_to_ticks(timeout, &ticks);
+       return - ble_npl_sem_pend(sem,  ticks);
 }
 
 static inline void k_sem_give(struct k_sem *sem)
 {
-       os_sem_release(sem);
+       ble_npl_sem_release(sem);
 }
 
 /* Helpers to access the storage array, since we don't have access to its
diff --git a/nimble/host/mesh/include/mesh/porting.h 
b/nimble/host/mesh/include/mesh/porting.h
new file mode 100644
index 00000000..eed8a208
--- /dev/null
+++ b/nimble/host/mesh/include/mesh/porting.h
@@ -0,0 +1,19 @@
+/** @file
+ *  @brief Bluetooth Mesh Porting APIs.
+ */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#ifndef __BT_MESH_PORTING_H
+#define __BT_MESH_PORTING_H
+
+void mesh_adv_thread(void *args);
+
+/**
+ * @}
+ */
+
+#endif /* __BT_MESH_PORTING_H */
diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c
index b79467ca..0850bcb0 100644
--- a/nimble/host/mesh/src/access.c
+++ b/nimble/host/mesh/src/access.c
@@ -184,9 +184,9 @@ static int publish_retransmit(struct bt_mesh_model *mod)
        return bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod);
 }
 
-static void mod_publish(struct os_event *work)
+static void mod_publish(struct ble_npl_event *work)
 {
-       struct bt_mesh_model_pub *pub = work->ev_arg;
+       struct bt_mesh_model_pub *pub = ble_npl_event_get_arg(work);
        s32_t period_ms;
        int err;
 
diff --git a/nimble/host/mesh/src/adv.c b/nimble/host/mesh/src/adv.c
index 0b84bae1..f30a2a3e 100644
--- a/nimble/host/mesh/src/adv.c
+++ b/nimble/host/mesh/src/adv.c
@@ -16,6 +16,7 @@
 #include "host/ble_hs_adv.h"
 #include "host/ble_gap.h"
 #include "nimble/hci_common.h"
+#include "mesh/porting.h"
 
 #include "adv.h"
 #include "foundation.h"
@@ -44,11 +45,13 @@ static s32_t adv_int_min =  ADV_INT_DEFAULT_MS;
 /* TinyCrypt PRNG consumes a lot of stack space, so we need to have
  * an increased call stack whenever it's used.
  */
+#if MYNEWT
 #define ADV_STACK_SIZE 768
 OS_TASK_STACK_DEFINE(g_blemesh_stack, ADV_STACK_SIZE);
-
 struct os_task adv_task;
-static struct os_eventq adv_queue;
+#endif
+
+static struct ble_npl_eventq adv_queue;
 extern u8_t g_mesh_addr_type;
 
 static os_membuf_t adv_buf_mem[OS_MEMPOOL_SIZE(
@@ -138,42 +141,41 @@ static inline void adv_send(struct os_mbuf *buf)
        BT_DBG("Advertising stopped");
 }
 
-static void
-adv_thread(void *args)
+void
+mesh_adv_thread(void *args)
 {
-       static struct os_event *ev;
+       static struct ble_npl_event *ev;
        struct os_mbuf *buf;
 #if (MYNEWT_VAL(BLE_MESH_PROXY))
        s32_t timeout;
-       struct os_eventq *eventq_pool = &adv_queue;
 #endif
 
        BT_DBG("started");
 
        while (1) {
 #if (MYNEWT_VAL(BLE_MESH_PROXY))
-               ev = os_eventq_get_no_wait(&adv_queue);
+               ev = ble_npl_eventq_get_tmo(&adv_queue, 0);
                while (!ev) {
                        timeout = bt_mesh_proxy_adv_start();
                        BT_DBG("Proxy Advertising up to %d ms", timeout);
 
                        // FIXME: should we redefine K_SECONDS macro instead in 
glue?
                        if (timeout != K_FOREVER) {
-                               timeout = os_time_ms_to_ticks32(timeout);
+                               timeout = ble_npl_time_ms_to_ticks32(timeout);
                        }
 
-                       ev = os_eventq_poll(&eventq_pool, 1, timeout);
+                       ev = ble_npl_eventq_get_tmo(&adv_queue, timeout);
                        bt_mesh_proxy_adv_stop();
                }
 #else
-               ev = os_eventq_get(&adv_queue);
+               ev = ble_npl_eventq_get(&adv_queue);
 #endif
 
-               if (!ev || !ev->ev_arg) {
+               if (!ev || !ble_npl_event_get_arg(ev)) {
                        continue;
                }
 
-               buf = ev->ev_arg;
+               buf = ble_npl_event_get_arg(ev);
 
                /* busy == 0 means this was canceled */
                if (BT_MESH_ADV(buf)->busy) {
@@ -181,17 +183,17 @@ adv_thread(void *args)
                        adv_send(buf);
                }
 
-               os_sched(NULL);
+               /* os_sched(NULL); */
        }
 }
 
 void bt_mesh_adv_update(void)
 {
-       static struct os_event ev = { };
+       static struct ble_npl_event ev = { };
 
        BT_DBG("");
 
-       os_eventq_put(&adv_queue, &ev);
+       ble_npl_eventq_put(&adv_queue, &ev);
 }
 
 struct os_mbuf *bt_mesh_adv_create_from_pool(struct os_mbuf_pool *pool,
@@ -217,7 +219,7 @@ struct os_mbuf *bt_mesh_adv_create_from_pool(struct 
os_mbuf_pool *pool,
        adv->count        = xmit_count;
        adv->adv_int      = xmit_int;
        adv->ref_cnt = 1;
-       adv->ev.ev_arg = buf;
+       ble_npl_event_set_arg(&adv->ev, buf);
        return buf;
 }
 
@@ -237,7 +239,6 @@ void bt_mesh_adv_send(struct os_mbuf *buf, const struct 
bt_mesh_send_cb *cb,
        BT_MESH_ADV(buf)->cb = cb;
        BT_MESH_ADV(buf)->cb_data = cb_data;
        BT_MESH_ADV(buf)->busy = 1;
-       BT_MESH_ADV(buf)->ev.ev_cb = NULL; /* does not matter */
 
        net_buf_put(&adv_queue, net_buf_ref(buf));
 }
@@ -307,11 +308,13 @@ void bt_mesh_adv_init(void)
                               MYNEWT_VAL(BLE_MESH_ADV_BUF_COUNT));
        assert(rc == 0);
 
-       os_eventq_init(&adv_queue);
+       ble_npl_eventq_init(&adv_queue);
 
-       os_task_init(&adv_task, "mesh_adv", adv_thread, NULL,
+#if MYNEWT
+       os_task_init(&adv_task, "mesh_adv", mesh_adv_thread, NULL,
                     MYNEWT_VAL(BLE_MESH_ADV_TASK_PRIO), OS_WAIT_FOREVER,
                     g_blemesh_stack, ADV_STACK_SIZE);
+#endif
 
        /* For BT5 controllers we can have fast advertising interval */
        if (ble_hs_hci_get_hci_version() >= BLE_HCI_VER_BCS_5_0) {
diff --git a/nimble/host/mesh/src/adv.h b/nimble/host/mesh/src/adv.h
index e40d6673..564e3657 100644
--- a/nimble/host/mesh/src/adv.h
+++ b/nimble/host/mesh/src/adv.h
@@ -53,7 +53,7 @@ struct bt_mesh_adv {
        };
 
        int ref_cnt;
-       struct os_event ev;
+       struct ble_npl_event ev;
 };
 
 typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
diff --git a/nimble/host/mesh/src/beacon.c b/nimble/host/mesh/src/beacon.c
index 34ea6b82..38990ec8 100644
--- a/nimble/host/mesh/src/beacon.c
+++ b/nimble/host/mesh/src/beacon.c
@@ -232,7 +232,7 @@ static void update_beacon_observation(void)
        }
 }
 
-static void beacon_send(struct os_event *work)
+static void beacon_send(struct ble_npl_event *work)
 {
        /* Don't send anything if we have an active provisioning link */
        if ((MYNEWT_VAL(BLE_MESH_PROV)) && bt_prov_active()) {
diff --git a/nimble/host/mesh/src/cfg_srv.c b/nimble/host/mesh/src/cfg_srv.c
index 8645e03a..0ce3af84 100644
--- a/nimble/host/mesh/src/cfg_srv.c
+++ b/nimble/host/mesh/src/cfg_srv.c
@@ -3110,9 +3110,9 @@ const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = {
        BT_MESH_MODEL_OP_END,
 };
 
-static void hb_publish(struct os_event *work)
+static void hb_publish(struct ble_npl_event *work)
 {
-       struct bt_mesh_cfg_srv *cfg = work->ev_arg;
+       struct bt_mesh_cfg_srv *cfg = ble_npl_event_get_arg(work);
        struct bt_mesh_model *model = cfg->model;
        struct bt_mesh_subnet *sub;
        u16_t period_ms;
diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index 42c9384b..ac106f36 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -656,9 +656,9 @@ static void send_friend_clear(struct bt_mesh_friend *frnd)
                         sizeof(req), NULL, &clear_sent_cb, frnd);
 }
 
-static void clear_timeout(struct os_event *work)
+static void clear_timeout(struct ble_npl_event *work)
 {
-       struct bt_mesh_friend *frnd = work->ev_arg;
+       struct bt_mesh_friend *frnd = ble_npl_event_get_arg(work);
        u32_t duration;
 
        BT_DBG("LPN 0x%04x (old) Friend 0x%04x", frnd->lpn, frnd->clear.frnd);
@@ -997,9 +997,9 @@ static void buf_send_end(int err, void *user_data)
        }
 }
 
-static void friend_timeout(struct os_event *work)
+static void friend_timeout(struct ble_npl_event *work)
 {
-       struct bt_mesh_friend *frnd = work->ev_arg;
+       struct bt_mesh_friend *frnd = ble_npl_event_get_arg(work);
        static const struct bt_mesh_send_cb buf_sent_cb = {
                .start = buf_send_start,
                .end = buf_send_end,
diff --git a/nimble/host/mesh/src/glue.c b/nimble/host/mesh/src/glue.c
index 9b0f0fc9..d210f90f 100644
--- a/nimble/host/mesh/src/glue.c
+++ b/nimble/host/mesh/src/glue.c
@@ -49,16 +49,16 @@ bt_hex(const void *buf, size_t len)
 }
 
 void
-net_buf_put(struct os_eventq *fifo, struct os_mbuf *om)
+net_buf_put(struct ble_npl_eventq *fifo, struct os_mbuf *om)
 {
-    struct os_event *ev;
+    struct ble_npl_event *ev;
 
     assert(OS_MBUF_IS_PKTHDR(om));
     ev = &BT_MESH_ADV(om)->ev;
     assert(ev);
-    assert(ev->ev_arg);
+    assert(ble_npl_event_get_arg(ev));
 
-    os_eventq_put(fifo, ev);
+    ble_npl_eventq_put(fifo, ev);
 }
 
 void *
@@ -281,17 +281,17 @@ net_buf_simple_add(struct os_mbuf *om, uint8_t len)
 }
 
 bool
-k_fifo_is_empty(struct os_eventq *q)
+k_fifo_is_empty(struct ble_npl_eventq *q)
 {
-    return STAILQ_EMPTY(&q->evq_list);
+    return ble_npl_eventq_is_empty(q);
 }
 
-void * net_buf_get(struct os_eventq *fifo, s32_t t)
+void * net_buf_get(struct ble_npl_eventq *fifo, s32_t t)
 {
-    struct os_event *ev = os_eventq_get_no_wait(fifo);
+    struct ble_npl_event *ev = ble_npl_eventq_get_tmo(fifo, 0);
 
     if (ev) {
-        return ev->ev_arg;
+        return ble_npl_event_get_arg(ev);
     }
 
     return NULL;
@@ -318,21 +318,21 @@ net_buf_reserve(struct os_mbuf *om, size_t reserve)
 }
 
 void
-k_work_init(struct os_callout *work, os_event_fn handler)
+k_work_init(struct ble_npl_callout *work, ble_npl_event_fn handler)
 {
-    os_callout_init(work, os_eventq_dflt_get(), handler, NULL);
+    ble_npl_callout_init(work, ble_npl_eventq_dflt_get(), handler, NULL);
 }
 
 void
-k_delayed_work_init(struct k_delayed_work *w, os_event_fn *f)
+k_delayed_work_init(struct k_delayed_work *w, ble_npl_event_fn *f)
 {
-    os_callout_init(&w->work, os_eventq_dflt_get(), f, NULL);
+    ble_npl_callout_init(&w->work, ble_npl_eventq_dflt_get(), f, NULL);
 }
 
 void
 k_delayed_work_cancel(struct k_delayed_work *w)
 {
-    os_callout_stop(&w->work);
+    ble_npl_callout_stop(&w->work);
 }
 
 void
@@ -340,49 +340,49 @@ k_delayed_work_submit(struct k_delayed_work *w, uint32_t 
ms)
 {
     uint32_t ticks;
 
-    if (os_time_ms_to_ticks(ms, &ticks) != 0) {
+    if (ble_npl_time_ms_to_ticks(ms, &ticks) != 0) {
         assert(0);
     }
-    os_callout_reset(&w->work, ticks);
+    ble_npl_callout_reset(&w->work, ticks);
 }
 
 void
-k_work_submit(struct os_callout *w)
+k_work_submit(struct ble_npl_callout *w)
 {
-    os_callout_reset(w, 0);
+    ble_npl_callout_reset(w, 0);
 }
 
 void
-k_work_add_arg(struct os_callout *w, void *arg)
+k_work_add_arg(struct ble_npl_callout *w, void *arg)
 {
-    w->c_ev.ev_arg = arg;
+    ble_npl_callout_set_arg(w, arg);
 }
 
 void
 k_delayed_work_add_arg(struct k_delayed_work *w, void *arg)
 {
-    w->work.c_ev.ev_arg = arg;
+    k_work_add_arg(&w->work, arg);
 }
 
 uint32_t
 k_delayed_work_remaining_get (struct k_delayed_work *w)
 {
     int sr;
-    os_time_t t;
+    ble_npl_time_t t;
 
     OS_ENTER_CRITICAL(sr);
 
-    t = os_callout_remaining_ticks(&w->work, os_time_get());
+    t = ble_npl_callout_remaining_ticks(&w->work, ble_npl_time_get());
 
     OS_EXIT_CRITICAL(sr);
 
-    return os_time_ticks_to_ms32(t);
+    return ble_npl_time_ticks_to_ms32(t);
 }
 
 int64_t k_uptime_get(void)
 {
     /* We should return ms */
-    return os_get_uptime_usec() / 1000;
+    return ble_npl_time_ticks_to_ms32(ble_npl_time_get());
 }
 
 u32_t k_uptime_get_32(void)
@@ -394,9 +394,9 @@ void k_sleep(int32_t duration)
 {
     uint32_t ticks;
 
-    ticks = os_time_ms_to_ticks32(duration);
+    ticks = ble_npl_time_ms_to_ticks32(duration);
 
-    os_time_delay(ticks);
+    ble_npl_time_delay(ticks);
 }
 
 static uint8_t pub[64];
diff --git a/nimble/host/mesh/src/health_srv.c 
b/nimble/host/mesh/src/health_srv.c
index 642e6163..32c2443b 100644
--- a/nimble/host/mesh/src/health_srv.c
+++ b/nimble/host/mesh/src/health_srv.c
@@ -366,9 +366,9 @@ int bt_mesh_fault_update(struct bt_mesh_elem *elem)
        return bt_mesh_model_publish(mod);
 }
 
-static void attention_off(struct os_event *work)
+static void attention_off(struct ble_npl_event *work)
 {
-       struct bt_mesh_health_srv *srv = work->ev_arg;
+       struct bt_mesh_health_srv *srv = ble_npl_event_get_arg(work);
        BT_DBG("");
 
        if (srv->cb && srv->cb->attn_off) {
diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c
index 0cc46229..e4565020 100644
--- a/nimble/host/mesh/src/lpn.c
+++ b/nimble/host/mesh/src/lpn.c
@@ -721,7 +721,7 @@ static void update_timeout(struct bt_mesh_lpn *lpn)
        }
 }
 
-static void lpn_timeout(struct os_event *work)
+static void lpn_timeout(struct ble_npl_event *work)
 {
        struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
 
diff --git a/nimble/host/mesh/src/net.c b/nimble/host/mesh/src/net.c
index 9bd79681..c4034d35 100644
--- a/nimble/host/mesh/src/net.c
+++ b/nimble/host/mesh/src/net.c
@@ -773,7 +773,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct 
os_mbuf *buf,
        return 0;
 }
 
-static void bt_mesh_net_local(struct os_event *work)
+static void bt_mesh_net_local(struct ble_npl_event *work)
 {
        struct os_mbuf *buf;
 
@@ -1337,7 +1337,7 @@ void bt_mesh_net_recv(struct os_mbuf *data, s8_t rssi,
     os_mbuf_free_chain(buf);
 }
 
-static void ivu_complete(struct os_event *work)
+static void ivu_complete(struct ble_npl_event *work)
 {
        BT_DBG("");
 
diff --git a/nimble/host/mesh/src/net.h b/nimble/host/mesh/src/net.h
index 5e11aa27..f3264947 100644
--- a/nimble/host/mesh/src/net.h
+++ b/nimble/host/mesh/src/net.h
@@ -200,7 +200,7 @@ struct bt_mesh_net {
        s64_t last_update;       /* Time since last IV Update change */
 
        /* Local network interface */
-       struct os_callout local_work;
+       struct ble_npl_callout local_work;
        struct net_buf_slist_t local_queue;
 
 #if MYNEWT_VAL(BLE_MESH_FRIEND)
diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c
index a5a18fcf..f4239e3c 100644
--- a/nimble/host/mesh/src/prov.c
+++ b/nimble/host/mesh/src/prov.c
@@ -1137,7 +1137,7 @@ static void close_link(u8_t err, u8_t reason)
 }
 
 #if (MYNEWT_VAL(BLE_MESH_PB_ADV))
-static void prov_retransmit(struct os_event *work)
+static void prov_retransmit(struct ble_npl_event *work)
 {
        int i;
 
diff --git a/nimble/host/mesh/src/proxy.c b/nimble/host/mesh/src/proxy.c
index 4ec2cbe3..55148cd4 100644
--- a/nimble/host/mesh/src/proxy.c
+++ b/nimble/host/mesh/src/proxy.c
@@ -97,7 +97,7 @@ static const struct ble_gap_adv_params fast_adv_param = {
 static bool proxy_adv_enabled;
 
 #if (MYNEWT_VAL(BLE_MESH_GATT_PROXY))
-static void proxy_send_beacons(struct os_event *work);
+static void proxy_send_beacons(struct ble_npl_event *work);
 #endif
 
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
@@ -115,7 +115,7 @@ static struct bt_mesh_proxy_client {
        } filter_type;
        u8_t msg_type;
 #if (MYNEWT_VAL(BLE_MESH_GATT_PROXY))
-       struct os_callout send_beacons;
+       struct ble_npl_callout send_beacons;
 #endif
        struct os_mbuf    *buf;
 } clients[MYNEWT_VAL(BLE_MAX_CONNECTIONS)] = {
@@ -384,12 +384,13 @@ static int beacon_send(uint16_t conn_handle, struct 
bt_mesh_subnet *sub)
        return rc;
 }
 
-static void proxy_send_beacons(struct os_event *work)
+static void proxy_send_beacons(struct ble_npl_event *work)
 {
        struct bt_mesh_proxy_client *client;
        int i;
 
-       client = work->ev_arg;
+
+       client = ble_npl_event_get_arg(work);
 
        for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
                struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c
index 918af1fe..e7f658e9 100644
--- a/nimble/host/mesh/src/transport.c
+++ b/nimble/host/mesh/src/transport.c
@@ -272,9 +272,9 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
        }
 }
 
-static void seg_retransmit(struct os_event *work)
+static void seg_retransmit(struct ble_npl_event *work)
 {
-       struct seg_tx *tx = work->ev_arg;
+       struct seg_tx *tx = ble_npl_event_get_arg(work);
        seg_tx_send_unacked(tx);
 }
 
@@ -1001,9 +1001,9 @@ static void seg_rx_reset(struct seg_rx *rx, bool 
full_reset)
        }
 }
 
-static void seg_ack(struct os_event *work)
+static void seg_ack(struct ble_npl_event *work)
 {
-       struct seg_rx *rx = work->ev_arg;
+       struct seg_rx *rx = ble_npl_event_get_arg(work);
 
        BT_DBG("rx %p", rx);
 
diff --git a/nimble/host/src/ble_hs_hci_cmd.c b/nimble/host/src/ble_hs_hci_cmd.c
index c68479f4..e5acd71a 100644
--- a/nimble/host/src/ble_hs_hci_cmd.c
+++ b/nimble/host/src/ble_hs_hci_cmd.c
@@ -179,8 +179,9 @@ ble_hs_hci_cmd_body_le_set_adv_params(const struct 
hci_adv_params *adv,
     itvl = BLE_HCI_ADV_ITVL_MIN;
 #else
     /* Make sure interval is valid for advertising type. */
-    if ((adv->adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) ||
-        (adv->adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND)) {
+    if (((adv->adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) ||
+        (adv->adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND)) &&
+        ble_hs_hci_get_hci_version() < BLE_HCI_VER_BCS_5_0) {
         itvl = BLE_HCI_ADV_ITVL_NONCONN_MIN;
     } else {
         itvl = BLE_HCI_ADV_ITVL_MIN;
diff --git a/nimble/include/nimble/nimble_npl.h 
b/nimble/include/nimble/nimble_npl.h
index 21d4c1e5..77e11f57 100644
--- a/nimble/include/nimble/nimble_npl.h
+++ b/nimble/include/nimble/nimble_npl.h
@@ -68,6 +68,9 @@ struct ble_npl_eventq *ble_npl_eventq_dflt_get(void);
 
 void ble_npl_eventq_init(struct ble_npl_eventq *evq);
 
+struct ble_npl_event *ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq,
+                                             ble_npl_time_t tmo);
+
 struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq);
 
 void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev);
@@ -86,6 +89,8 @@ void *ble_npl_event_get_arg(struct ble_npl_event *ev);
 
 void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg);
 
+int ble_npl_eventq_is_empty(struct ble_npl_eventq *evq);
+
 /*
  * Mutexes
  */
@@ -125,6 +130,11 @@ int ble_npl_callout_queued(struct ble_npl_callout *co);
 
 uint32_t ble_npl_callout_get_ticks(struct ble_npl_callout *co);
 
+uint32_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
+                                         ble_npl_time_t time);
+
+void ble_npl_callout_set_arg(struct ble_npl_callout *co,
+                             void *arg);
 /*
  * Time functions
  */
@@ -139,6 +149,8 @@ ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms);
 
 uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks);
 
+void ble_npl_time_delay(ble_npl_time_t ticks);
+
 /*
  * Hardware-specific
  *
diff --git a/porting/nimble/Makefile.defs b/porting/nimble/Makefile.defs
index 5b13ba91..347c1080 100644
--- a/porting/nimble/Makefile.defs
+++ b/porting/nimble/Makefile.defs
@@ -93,4 +93,8 @@ ifneq (,$(NIMBLE_CFG_TINYCRYPT))
 include $(NIMBLE_ROOT)/porting/nimble/Makefile.tinycrypt
 endif
 
+ifneq (,$(NIMBLE_CFG_MESH))
+include $(NIMBLE_ROOT)/porting/nimble/Makefile.mesh
+endif
+
 NIMBLE_OBJ := $(NIMBLE_SRC:.c=.o)
diff --git a/porting/nimble/Makefile.mesh b/porting/nimble/Makefile.mesh
new file mode 100644
index 00000000..ef64e214
--- /dev/null
+++ b/porting/nimble/Makefile.mesh
@@ -0,0 +1,25 @@
+NIMBLE_INCLUDE += \
+       $(NIMBLE_ROOT)/nimble/host/mesh/include \
+
+NIMBLE_SRC += \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/access.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/adv.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/beacon.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/cfg_cli.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/cfg_srv.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/crypto.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/friend.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/glue.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/health_cli.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/health_srv.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/light_model.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/lpn.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/mesh.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/model_cli.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/model_srv.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/net.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/prov.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/proxy.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/shell.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/testing.c \
+       $(NIMBLE_ROOT)/nimble/host/mesh/src/transport.c \
diff --git a/porting/npl/freertos/include/nimble/nimble_npl_os.h 
b/porting/npl/freertos/include/nimble/nimble_npl_os.h
index 2b24556a..cea2bc54 100644
--- a/porting/npl/freertos/include/nimble/nimble_npl_os.h
+++ b/porting/npl/freertos/include/nimble/nimble_npl_os.h
@@ -99,6 +99,12 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
     evq->q = xQueueCreate(32, sizeof(struct ble_npl_eventq *));
 }
 
+static inline struct ble_npl_event *
+ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
+{
+    return npl_freertos_eventq_get_tmo(evq, tmo);
+}
+
 static inline struct ble_npl_event *
 ble_npl_eventq_get(struct ble_npl_eventq *evq)
 {
@@ -128,6 +134,12 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
     ev->fn(ev);
 }
 
+static inline int
+ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
+{
+    return xQueueIsQueueEmptyFromISR(evq->q);
+}
+
 static inline void
 ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
                    void *arg)
@@ -228,6 +240,19 @@ ble_npl_callout_get_ticks(struct ble_npl_callout *co)
     return xTimerGetExpiryTime(co->handle);
 }
 
+static inline uint32_t
+ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
+                                ble_npl_time_t time)
+{
+    return npl_freertos_callout_remaining_ticks(co, time);
+}
+
+static inline void
+ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
+{
+    co->ev.arg = arg;
+}
+
 static inline uint32_t
 ble_npl_time_get(void)
 {
@@ -258,6 +283,12 @@ ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
     return ticks * 1000 / configTICK_RATE_HZ;
 }
 
+static inline void
+ble_npl_time_delay(ble_npl_time_t ticks)
+{
+    vTaskDelay(ticks);
+}
+
 #if NIMBLE_CFG_CONTROLLER
 static inline void
 ble_npl_hw_set_isr(int irqn, uint32_t addr)
diff --git a/porting/npl/freertos/include/nimble/npl_freertos.h 
b/porting/npl/freertos/include/nimble/npl_freertos.h
index e9a2f336..f1197684 100644
--- a/porting/npl/freertos/include/nimble/npl_freertos.h
+++ b/porting/npl/freertos/include/nimble/npl_freertos.h
@@ -26,6 +26,8 @@ extern "C" {
 
 struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void);
 
+struct ble_npl_event *npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, 
ble_npl_time_t tmo);
+
 struct ble_npl_event *npl_freertos_eventq_get(struct ble_npl_eventq *evq);
 
 void npl_freertos_eventq_put(struct ble_npl_eventq *evq,
@@ -55,6 +57,9 @@ void npl_freertos_callout_init(struct ble_npl_callout *co,
 int npl_freertos_callout_reset(struct ble_npl_callout *co,
                                ble_npl_time_t ticks);
 
+ble_npl_time_t npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
+                                                   ble_npl_time_t now);
+
 ble_npl_error_t npl_freertos_time_ms_to_ticks(uint32_t ms,
                                               ble_npl_time_t *out_ticks);
 
diff --git a/porting/npl/freertos/src/npl_os_freertos.c 
b/porting/npl/freertos/src/npl_os_freertos.c
index 226ad650..00606430 100644
--- a/porting/npl/freertos/src/npl_os_freertos.c
+++ b/porting/npl/freertos/src/npl_os_freertos.c
@@ -42,19 +42,27 @@ npl_freertos_eventq_dflt_get(void)
 }
 
 struct ble_npl_event *
-npl_freertos_eventq_get(struct ble_npl_eventq *evq)
+npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
 {
-    struct ble_npl_event *ev;
+    struct ble_npl_event *ev = NULL;
     BaseType_t ret;
 
-    ret = xQueueReceive(evq->q, &ev, portMAX_DELAY);
-    assert(ret == pdPASS);
+    ret = xQueueReceive(evq->q, &ev, tmo);
+    assert(ret == pdPASS || ret == errQUEUE_EMPTY);
 
-    ev->queued = false;
+    if (ev) {
+        ev->queued = false;
+    }
 
     return ev;
 }
 
+struct ble_npl_event *
+npl_freertos_eventq_get(struct ble_npl_eventq *evq)
+{
+    return npl_freertos_eventq_get_tmo(evq, portMAX_DELAY);
+}
+
 void
 npl_freertos_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
 {
@@ -281,6 +289,26 @@ npl_freertos_callout_reset(struct ble_npl_callout *co, 
ble_npl_time_t ticks)
     return BLE_NPL_OK;
 }
 
+ble_npl_time_t
+npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
+                                     ble_npl_time_t now)
+{
+    ble_npl_time_t rt;
+    uint32_t exp = xTimerGetExpiryTime(co->handle);
+
+    taskENTER_CRITICAL();
+
+    if (exp > now) {
+        rt = exp - now;
+    } else {
+        return 0;
+    }
+
+    taskEXIT_CRITICAL();
+
+    return rt;
+}
+
 ble_npl_error_t
 npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
 {
diff --git a/porting/npl/mynewt/include/nimble/nimble_npl_os.h 
b/porting/npl/mynewt/include/nimble/nimble_npl_os.h
index 9b825dde..f7a47dd5 100644
--- a/porting/npl/mynewt/include/nimble/nimble_npl_os.h
+++ b/porting/npl/mynewt/include/nimble/nimble_npl_os.h
@@ -82,6 +82,12 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
     os_eventq_init(&evq->evq);
 }
 
+static inline struct ble_npl_event *
+ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
+{
+    return (struct ble_npl_event *)os_eventq_poll((struct os_eventq **)&evq, 
1, tmo);
+}
+
 static inline struct ble_npl_event *
 ble_npl_eventq_get(struct ble_npl_eventq *evq)
 {
@@ -107,6 +113,12 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
     os_eventq_run(&evq->evq);
 }
 
+static inline int
+ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
+{
+    return STAILQ_EMPTY(&evq->evq.evq_list);
+}
+
 static inline void
 ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
                    void *arg)
@@ -208,6 +220,20 @@ ble_npl_callout_get_ticks(struct ble_npl_callout *co)
     return co->co.c_ticks;
 }
 
+static inline ble_npl_time_t
+ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
+                                ble_npl_time_t time)
+{
+    return os_callout_remaining_ticks(&co->co, time);
+}
+
+static inline void
+ble_npl_callout_set_arg(struct ble_npl_callout *co,
+                        void *arg)
+{
+    co->co.c_ev.ev_arg = arg;
+}
+
 static inline uint32_t
 ble_npl_time_get(void)
 {
@@ -238,6 +264,12 @@ ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
     return os_time_ticks_to_ms32(ticks);
 }
 
+static inline void
+ble_npl_time_delay(ble_npl_time_t ticks)
+{
+    return os_time_delay(ticks);
+}
+
 static inline uint32_t
 ble_npl_hw_enter_critical(void)
 {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to