mesh: Use Nimble Porting Layer

This commit is contained in:
Michał Narajowski
2018-05-09 14:17:33 +02:00
parent b029b909d4
commit 0fd550bb6c
15 changed files with 81 additions and 83 deletions
+15 -16
View File
@@ -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
+2 -2
View File
@@ -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;
+13 -15
View File
@@ -51,7 +51,7 @@ OS_TASK_STACK_DEFINE(g_blemesh_stack, ADV_STACK_SIZE);
struct os_task adv_task;
#endif
static struct os_eventq adv_queue;
static struct ble_npl_eventq adv_queue;
extern u8_t g_mesh_addr_type;
static os_membuf_t adv_buf_mem[OS_MEMPOOL_SIZE(
@@ -144,39 +144,38 @@ static inline void adv_send(struct os_mbuf *buf)
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) {
@@ -184,17 +183,17 @@ mesh_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,
@@ -220,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;
}
@@ -240,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));
}
@@ -310,7 +308,7 @@ 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);
#if MYNEWT
os_task_init(&adv_task, "mesh_adv", mesh_adv_thread, NULL,
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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()) {
+2 -2
View File
@@ -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;
+4 -4
View File
@@ -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,
+27 -27
View File
@@ -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];
+2 -2
View File
@@ -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) {
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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 @@ done:
os_mbuf_free_chain(buf);
}
static void ivu_complete(struct os_event *work)
static void ivu_complete(struct ble_npl_event *work)
{
BT_DBG("");
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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;
+5 -4
View File
@@ -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];
+4 -4
View File
@@ -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);