diff --git a/nimble/host/mesh/include/mesh/glue.h b/nimble/host/mesh/include/mesh/glue.h index 66c381813..b1050d8c6 100644 --- a/nimble/host/mesh/include/mesh/glue.h +++ b/nimble/host/mesh/include/mesh/glue.h @@ -287,6 +287,7 @@ 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_delayed_work_add_arg(struct k_delayed_work *w, void *arg); diff --git a/nimble/host/mesh/src/adv.c b/nimble/host/mesh/src/adv.c index f5a032cd2..3dce81c9e 100644 --- a/nimble/host/mesh/src/adv.c +++ b/nimble/host/mesh/src/adv.c @@ -1,6 +1,7 @@ /* Bluetooth Mesh */ /* + * Copyright (c) 2018 Nordic Semiconductor ASA * Copyright (c) 2017 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 @@ -23,20 +24,22 @@ #include "prov.h" #include "proxy.h" -/* Window and Interval are equal for continuous scanning */ -#define MESH_SCAN_INTERVAL 0x10 -#define MESH_SCAN_WINDOW 0x10 - /* Convert from ms to 0.625ms units */ -#define ADV_INT(_ms) ((_ms) * 8 / 5) +#define ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5) + +/* Window and Interval are equal for continuous scanning */ +#define MESH_SCAN_INTERVAL_MS 10 +#define MESH_SCAN_WINDOW_MS 10 +#define MESH_SCAN_INTERVAL ADV_SCAN_UNIT(MESH_SCAN_INTERVAL_MS) +#define MESH_SCAN_WINDOW ADV_SCAN_UNIT(MESH_SCAN_WINDOW_MS) /* Pre-5.0 controllers enforce a minimum interval of 100ms * whereas 5.0+ controllers can go down to 20ms. */ -#define ADV_INT_DEFAULT K_MSEC(100) -#define ADV_INT_FAST K_MSEC(20) +#define ADV_INT_DEFAULT_MS 100 +#define ADV_INT_FAST_MS 20 -static s32_t adv_int_min = ADV_INT_DEFAULT; +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. @@ -97,7 +100,7 @@ static inline void adv_send(struct os_mbuf *buf) int err; adv_int = max(adv_int_min, adv->adv_int); - duration = (adv->count + 1) * (adv_int + 10); + duration = MESH_SCAN_WINDOW_MS + (adv->count + 1) * (adv_int + 10); BT_DBG("buf %p, type %u len %u:", buf, adv->type, buf->om_len); @@ -108,7 +111,7 @@ static inline void adv_send(struct os_mbuf *buf) ad.data_len = buf->om_len; ad.data = buf->om_data; - param.itvl_min = ADV_INT(adv_int); + param.itvl_min = ADV_SCAN_UNIT(adv_int); param.itvl_max = param.itvl_min; param.conn_mode = BLE_GAP_CONN_MODE_NON; @@ -122,7 +125,7 @@ static inline void adv_send(struct os_mbuf *buf) BT_DBG("Advertising started. Sleeping %u ms", duration); - os_time_delay(OS_TICKS_PER_SEC * duration / 1000); + k_sleep(K_MSEC(duration)); err = bt_le_adv_stop(); adv_send_end(err, cb, cb_data); @@ -315,7 +318,7 @@ void bt_mesh_adv_init(void) /* For BT5 controllers we can have fast advertising interval */ if (ble_hs_hci_get_hci_version() >= BLE_HCI_VER_BCS_5_0) { - adv_int_min = ADV_INT_FAST; + adv_int_min = ADV_INT_FAST_MS; } } diff --git a/nimble/host/mesh/src/glue.c b/nimble/host/mesh/src/glue.c index 086edaf8c..b93d9dbb9 100644 --- a/nimble/host/mesh/src/glue.c +++ b/nimble/host/mesh/src/glue.c @@ -391,6 +391,11 @@ u32_t k_uptime_get_32(void) return k_uptime_get(); } +void k_sleep(int32_t duration) +{ + os_time_delay(OS_TICKS_PER_SEC * duration / 1000); +} + static uint8_t pub[64]; static uint8_t priv[32]; static bool has_pub = false;