Merge pull request #98 from michal-narajowski/mesh-npl

Update Mesh to use NPL
This commit is contained in:
Michał Narajowski
2018-05-15 16:14:03 +02:00
committed by GitHub
24 changed files with 254 additions and 94 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,
int bt_le_adv_stop(void);
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
+19
View File
@@ -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 */
+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;
+22 -19
View File
@@ -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) {
+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
@@ -70,16 +70,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 *
@@ -302,17 +302,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;
@@ -339,21 +339,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
@@ -361,49 +361,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)
@@ -415,9 +415,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);
+3 -2
View File
@@ -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;
+12
View File
@@ -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
*
+4
View File
@@ -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)
+25
View File
@@ -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 \
@@ -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)
@@ -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);
+33 -5
View File
@@ -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)
{
@@ -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)
{