Bluetooth: mesh: Convert bluetooth mesh to using k_timeout struct

Convert bluetooth mesh to using k_timeout struct. Many of the mesh
modules uses timeout calculations, so it is most practical to keep
the s32_t type and only initialize a k_timeout_t struct when
calling the kernel.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-04-06 13:56:14 +02:00 committed by Johan Hedberg
commit 87d9eadf50
20 changed files with 120 additions and 122 deletions

View file

@ -832,7 +832,7 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
/** @brief Get the current transmission timeout value. /** @brief Get the current transmission timeout value.
* *
* @return The configured transmission timeout. * @return The configured transmission timeout in milliseconds.
*/ */
s32_t bt_mesh_cfg_cli_timeout_get(void); s32_t bt_mesh_cfg_cli_timeout_get(void);

View file

@ -182,7 +182,7 @@ int bt_mesh_health_attention_set(u16_t addr, u16_t app_idx, u8_t attention,
/** @brief Get the current transmission timeout value. /** @brief Get the current transmission timeout value.
* *
* @return The configured transmission timeout. * @return The configured transmission timeout in milliseconds.
*/ */
s32_t bt_mesh_health_cli_timeout_get(void); s32_t bt_mesh_health_cli_timeout_get(void);

View file

@ -57,7 +57,7 @@ void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod)
{ {
int period; s32_t period;
if (!mod->pub) { if (!mod->pub) {
return 0; return 0;
@ -66,19 +66,19 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod)
switch (mod->pub->period >> 6) { switch (mod->pub->period >> 6) {
case 0x00: case 0x00:
/* 1 step is 100 ms */ /* 1 step is 100 ms */
period = K_MSEC((mod->pub->period & BIT_MASK(6)) * 100U); period = (mod->pub->period & BIT_MASK(6)) * 100U;
break; break;
case 0x01: case 0x01:
/* 1 step is 1 second */ /* 1 step is 1 second */
period = K_SECONDS(mod->pub->period & BIT_MASK(6)); period = (mod->pub->period & BIT_MASK(6)) * MSEC_PER_SEC;
break; break;
case 0x02: case 0x02:
/* 1 step is 10 seconds */ /* 1 step is 10 seconds */
period = K_SECONDS((mod->pub->period & BIT_MASK(6)) * 10U); period = (mod->pub->period & BIT_MASK(6)) * 10U * MSEC_PER_SEC;
break; break;
case 0x03: case 0x03:
/* 1 step is 10 minutes */ /* 1 step is 10 minutes */
period = K_MINUTES((mod->pub->period & BIT_MASK(6)) * 10U); period = (mod->pub->period & BIT_MASK(6)) * 600U * MSEC_PER_SEC;
break; break;
default: default:
CODE_UNREACHABLE; CODE_UNREACHABLE;
@ -108,7 +108,7 @@ static s32_t next_period(struct bt_mesh_model *mod)
if (elapsed >= period) { if (elapsed >= period) {
BT_WARN("Publication sending took longer than the period"); BT_WARN("Publication sending took longer than the period");
/* Return smallest positive number since 0 means disabled */ /* Return smallest positive number since 0 means disabled */
return K_MSEC(1); return 1;
} }
return period - elapsed; return period - elapsed;
@ -129,7 +129,7 @@ static void publish_sent(int err, void *user_data)
if (delay) { if (delay) {
BT_DBG("Publishing next time in %dms", delay); BT_DBG("Publishing next time in %dms", delay);
k_delayed_work_submit(&mod->pub->timer, delay); k_delayed_work_submit(&mod->pub->timer, K_MSEC(delay));
} }
} }
@ -217,7 +217,8 @@ static void mod_publish(struct k_work *work)
/* Continue with normal publication */ /* Continue with normal publication */
if (period_ms) { if (period_ms) {
k_delayed_work_submit(&pub->timer, period_ms); k_delayed_work_submit(&pub->timer,
K_MSEC(period_ms));
} }
} }

View file

@ -158,11 +158,11 @@ static void adv_thread(void *p1, void *p2, void *p3)
if (IS_ENABLED(CONFIG_BT_MESH_PROXY)) { if (IS_ENABLED(CONFIG_BT_MESH_PROXY)) {
buf = net_buf_get(&adv_queue, K_NO_WAIT); buf = net_buf_get(&adv_queue, K_NO_WAIT);
while (!buf) { while (!buf) {
s32_t timeout; k_timeout_t timeout;
timeout = bt_mesh_proxy_adv_start(); timeout = bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising up to %d ms", BT_DBG("Proxy Advertising");
timeout);
buf = net_buf_get(&adv_queue, timeout); buf = net_buf_get(&adv_queue, timeout);
bt_mesh_proxy_adv_stop(); bt_mesh_proxy_adv_stop();
} }
@ -197,7 +197,7 @@ void bt_mesh_adv_update(void)
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
bt_mesh_adv_alloc_t get_id, bt_mesh_adv_alloc_t get_id,
enum bt_mesh_adv_type type, enum bt_mesh_adv_type type,
u8_t xmit, s32_t timeout) u8_t xmit, k_timeout_t timeout)
{ {
struct bt_mesh_adv *adv; struct bt_mesh_adv *adv;
struct net_buf *buf; struct net_buf *buf;
@ -224,7 +224,7 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
} }
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit, struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
s32_t timeout) k_timeout_t timeout)
{ {
return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_alloc, type, return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_alloc, type,
xmit, timeout); xmit, timeout);

View file

@ -37,12 +37,12 @@ typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
/* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */ /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit, struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
s32_t timeout); k_timeout_t timeout);
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
bt_mesh_adv_alloc_t get_id, bt_mesh_adv_alloc_t get_id,
enum bt_mesh_adv_type type, enum bt_mesh_adv_type type,
u8_t xmit, s32_t timeout); u8_t xmit, k_timeout_t timeout);
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data); void *cb_data);

View file

@ -105,8 +105,8 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
} }
/* If the interval has passed or is within 5 seconds from now send a beacon */ /* If the interval has passed or is within 5 seconds from now send a beacon */
#define BEACON_THRESHOLD(sub) (K_SECONDS(10 * ((sub)->beacons_last + 1)) - \ #define BEACON_THRESHOLD(sub) \
K_SECONDS(5)) ((10 * ((sub)->beacons_last + 1)) * MSEC_PER_SEC - (5 * MSEC_PER_SEC))
static int secure_beacon_send(void) static int secure_beacon_send(void)
{ {
@ -128,7 +128,7 @@ static int secure_beacon_send(void)
} }
time_diff = now - sub->beacon_sent; time_diff = now - sub->beacon_sent;
if (time_diff < K_SECONDS(600) && if (time_diff < (600 * MSEC_PER_SEC) &&
time_diff < BEACON_THRESHOLD(sub)) { time_diff < BEACON_THRESHOLD(sub)) {
continue; continue;
} }

View file

@ -35,7 +35,7 @@ struct comp_data {
struct net_buf_simple *comp; struct net_buf_simple *comp;
}; };
static s32_t msg_timeout = K_SECONDS(2); static s32_t msg_timeout;
static struct bt_mesh_cfg_cli *cli; static struct bt_mesh_cfg_cli *cli;
@ -709,6 +709,7 @@ static int cfg_cli_init(struct bt_mesh_model *model)
cli = model->user_data; cli = model->user_data;
cli->model = model; cli->model = model;
msg_timeout = 2 * MSEC_PER_SEC;
/* /*
* Configuration Model security is device-key based and both the local * Configuration Model security is device-key based and both the local
@ -753,7 +754,7 @@ static int cli_wait(void)
{ {
int err; int err;
err = k_sem_take(&cli->op_sync, msg_timeout); err = k_sem_take(&cli->op_sync, SYS_TIMEOUT_MS(msg_timeout));
cli_reset(); cli_reset();

View file

@ -247,8 +247,9 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr,
period_ms = bt_mesh_model_pub_period_get(model); period_ms = bt_mesh_model_pub_period_get(model);
BT_DBG("period %u ms", period_ms); BT_DBG("period %u ms", period_ms);
if (period_ms) { if (period_ms > 0) {
k_delayed_work_submit(&model->pub->timer, period_ms); k_delayed_work_submit(&model->pub->timer,
K_MSEC(period_ms));
} else { } else {
k_delayed_work_cancel(&model->pub->timer); k_delayed_work_cancel(&model->pub->timer);
} }
@ -2730,7 +2731,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
BT_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_STATUS, 5); BT_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_STATUS, 5);
struct bt_mesh_friend *frnd; struct bt_mesh_friend *frnd;
u16_t lpn_addr; u16_t lpn_addr;
s32_t timeout; s32_t timeout_ms;
lpn_addr = net_buf_simple_pull_le16(buf); lpn_addr = net_buf_simple_pull_le16(buf);
@ -2746,20 +2747,20 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
net_buf_simple_add_le16(&msg, lpn_addr); net_buf_simple_add_le16(&msg, lpn_addr);
if (!IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (!IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
timeout = 0; timeout_ms = 0;
goto send_rsp; goto send_rsp;
} }
frnd = bt_mesh_friend_find(BT_MESH_KEY_ANY, lpn_addr, true, true); frnd = bt_mesh_friend_find(BT_MESH_KEY_ANY, lpn_addr, true, true);
if (!frnd) { if (!frnd) {
timeout = 0; timeout_ms = 0;
goto send_rsp; goto send_rsp;
} }
timeout = k_delayed_work_remaining_get(&frnd->timer) / 100; timeout_ms = k_delayed_work_remaining_get(&frnd->timer) / 100;
send_rsp: send_rsp:
net_buf_simple_add_le24(&msg, timeout); net_buf_simple_add_le24(&msg, timeout_ms);
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("Unable to send LPN PollTimeout Status"); BT_ERR("Unable to send LPN PollTimeout Status");
@ -3226,7 +3227,7 @@ static void hb_publish(struct k_work *work)
period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000U; period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000U;
if (period_ms && cfg->hb_pub.count > 1) { if (period_ms && cfg->hb_pub.count > 1) {
k_delayed_work_submit(&cfg->hb_pub.timer, period_ms); k_delayed_work_submit(&cfg->hb_pub.timer, K_MSEC(period_ms));
} }
bt_mesh_heartbeat_send(); bt_mesh_heartbeat_send();

View file

@ -563,7 +563,7 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact)
static void friend_recv_delay(struct bt_mesh_friend *frnd) static void friend_recv_delay(struct bt_mesh_friend *frnd)
{ {
frnd->pending_req = 1U; frnd->pending_req = 1U;
k_delayed_work_submit(&frnd->timer, recv_delay(frnd)); k_delayed_work_submit(&frnd->timer, K_MSEC(recv_delay(frnd)));
BT_DBG("Waiting RecvDelay of %d ms", recv_delay(frnd)); BT_DBG("Waiting RecvDelay of %d ms", recv_delay(frnd));
} }
@ -895,11 +895,7 @@ static s32_t offer_delay(struct bt_mesh_friend *frnd, s8_t rssi, u8_t crit)
BT_DBG("Local Delay calculated as %d ms", delay); BT_DBG("Local Delay calculated as %d ms", delay);
if (delay < 100) { return MAX(delay, 100);
return K_MSEC(100);
}
return K_MSEC(delay);
} }
int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
@ -986,8 +982,8 @@ init_friend:
} }
k_delayed_work_submit(&frnd->timer, k_delayed_work_submit(&frnd->timer,
offer_delay(frnd, rx->ctx.recv_rssi, K_MSEC(offer_delay(frnd, rx->ctx.recv_rssi,
msg->criteria)); msg->criteria)));
friend_cred_create(rx->sub, frnd->lpn, frnd->lpn_counter, friend_cred_create(rx->sub, frnd->lpn, frnd->lpn_counter,
frnd->counter); frnd->counter);
@ -1107,7 +1103,7 @@ static void buf_send_end(int err, void *user_data)
} }
if (frnd->established) { if (frnd->established) {
k_delayed_work_submit(&frnd->timer, frnd->poll_to); k_delayed_work_submit(&frnd->timer, K_MSEC(frnd->poll_to));
BT_DBG("Waiting %u ms for next poll", frnd->poll_to); BT_DBG("Waiting %u ms for next poll", frnd->poll_to);
} else { } else {
/* Friend offer timeout is 1 second */ /* Friend offer timeout is 1 second */

View file

@ -25,7 +25,7 @@
#include "net.h" #include "net.h"
#include "foundation.h" #include "foundation.h"
static s32_t msg_timeout = K_SECONDS(2); static s32_t msg_timeout;
static struct bt_mesh_health_cli *health_cli; static struct bt_mesh_health_cli *health_cli;
@ -199,7 +199,7 @@ static int cli_wait(void)
{ {
int err; int err;
err = k_sem_take(&health_cli->op_sync, msg_timeout); err = k_sem_take(&health_cli->op_sync, SYS_TIMEOUT_MS(msg_timeout));
cli_reset(); cli_reset();
@ -497,6 +497,7 @@ int bt_mesh_health_cli_set(struct bt_mesh_model *model)
} }
health_cli = model->user_data; health_cli = model->user_data;
msg_timeout = 2 * MSEC_PER_SEC;
return 0; return 0;
} }

View file

@ -363,7 +363,7 @@ int bt_mesh_fault_update(struct bt_mesh_elem *elem)
/* Let periodic publishing, if enabled, take care of sending the /* Let periodic publishing, if enabled, take care of sending the
* Health Current Status. * Health Current Status.
*/ */
if (bt_mesh_model_pub_period_get(mod)) { if (bt_mesh_model_pub_period_get(mod) > 0) {
return 0; return 0;
} }
@ -435,12 +435,12 @@ void bt_mesh_attention(struct bt_mesh_model *model, u8_t time)
srv = model->user_data; srv = model->user_data;
} }
if (time) { if (time > 0) {
if (srv->cb && srv->cb->attn_on) { if (srv->cb && srv->cb->attn_on) {
srv->cb->attn_on(model); srv->cb->attn_on(model);
} }
k_delayed_work_submit(&srv->attn_timer, time * 1000U); k_delayed_work_submit(&srv->attn_timer, K_SECONDS(time));
} else { } else {
k_delayed_work_cancel(&srv->attn_timer); k_delayed_work_cancel(&srv->attn_timer);

View file

@ -29,9 +29,9 @@
#include "lpn.h" #include "lpn.h"
#if defined(CONFIG_BT_MESH_LPN_AUTO) #if defined(CONFIG_BT_MESH_LPN_AUTO)
#define LPN_AUTO_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_AUTO_TIMEOUT) #define LPN_AUTO_TIMEOUT (CONFIG_BT_MESH_LPN_AUTO_TIMEOUT * MSEC_PER_SEC)
#else #else
#define LPN_AUTO_TIMEOUT 0 #define LPN_AUTO_TIMEOUT 0
#endif #endif
#define LPN_RECV_DELAY CONFIG_BT_MESH_LPN_RECV_DELAY #define LPN_RECV_DELAY CONFIG_BT_MESH_LPN_RECV_DELAY
@ -40,11 +40,11 @@
#define FRIEND_REQ_RETRY_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_RETRY_TIMEOUT) #define FRIEND_REQ_RETRY_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_RETRY_TIMEOUT)
#define FRIEND_REQ_WAIT K_MSEC(100) #define FRIEND_REQ_WAIT 100
#define FRIEND_REQ_SCAN K_SECONDS(1) #define FRIEND_REQ_SCAN (1 * MSEC_PER_SEC)
#define FRIEND_REQ_TIMEOUT (FRIEND_REQ_WAIT + FRIEND_REQ_SCAN) #define FRIEND_REQ_TIMEOUT (FRIEND_REQ_WAIT + FRIEND_REQ_SCAN)
#define POLL_RETRY_TIMEOUT K_MSEC(100) #define POLL_RETRY_TIMEOUT 100
#define REQ_RETRY_DURATION(lpn) (LPN_RECV_DELAY + (lpn)->adv_duration + \ #define REQ_RETRY_DURATION(lpn) (LPN_RECV_DELAY + (lpn)->adv_duration + \
(lpn)->recv_win + POLL_RETRY_TIMEOUT) (lpn)->recv_win + POLL_RETRY_TIMEOUT)
@ -165,7 +165,7 @@ static void friend_clear_sent(int err, void *user_data)
} }
lpn_set_state(BT_MESH_LPN_CLEAR); lpn_set_state(BT_MESH_LPN_CLEAR);
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_TIMEOUT); k_delayed_work_submit(&lpn->timer, K_MSEC(FRIEND_REQ_TIMEOUT));
} }
static const struct bt_mesh_send_cb clear_sent_cb = { static const struct bt_mesh_send_cb clear_sent_cb = {
@ -272,11 +272,11 @@ static void friend_req_sent(u16_t duration, int err, void *user_data)
lpn->adv_duration = duration; lpn->adv_duration = duration;
if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) {
k_delayed_work_submit(&lpn->timer, FRIEND_REQ_WAIT); k_delayed_work_submit(&lpn->timer, K_MSEC(FRIEND_REQ_WAIT));
lpn_set_state(BT_MESH_LPN_REQ_WAIT); lpn_set_state(BT_MESH_LPN_REQ_WAIT);
} else { } else {
k_delayed_work_submit(&lpn->timer, k_delayed_work_submit(&lpn->timer,
duration + FRIEND_REQ_TIMEOUT); K_MSEC(duration + FRIEND_REQ_TIMEOUT));
lpn_set_state(BT_MESH_LPN_WAIT_OFFER); lpn_set_state(BT_MESH_LPN_WAIT_OFFER);
} }
} }
@ -340,11 +340,11 @@ static void req_sent(u16_t duration, int err, void *user_data)
* response data due to HCI and other latencies. * response data due to HCI and other latencies.
*/ */
k_delayed_work_submit(&lpn->timer, k_delayed_work_submit(&lpn->timer,
LPN_RECV_DELAY - SCAN_LATENCY); K_MSEC(LPN_RECV_DELAY - SCAN_LATENCY));
} else { } else {
k_delayed_work_submit(&lpn->timer, k_delayed_work_submit(&lpn->timer,
LPN_RECV_DELAY + duration + K_MSEC(LPN_RECV_DELAY + duration +
lpn->recv_win); lpn->recv_win));
} }
} }
@ -466,7 +466,7 @@ void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx)
if (lpn->state == BT_MESH_LPN_TIMER) { if (lpn->state == BT_MESH_LPN_TIMER) {
BT_DBG("Restarting establishment timer"); BT_DBG("Restarting establishment timer");
k_delayed_work_submit(&lpn->timer, LPN_AUTO_TIMEOUT); k_delayed_work_submit(&lpn->timer, K_MSEC(LPN_AUTO_TIMEOUT));
return; return;
} }
@ -710,7 +710,7 @@ static void update_timeout(struct bt_mesh_lpn *lpn)
BT_WARN("No response from Friend during ReceiveWindow"); BT_WARN("No response from Friend during ReceiveWindow");
bt_mesh_scan_disable(); bt_mesh_scan_disable();
lpn_set_state(BT_MESH_LPN_ESTABLISHED); lpn_set_state(BT_MESH_LPN_ESTABLISHED);
k_delayed_work_submit(&lpn->timer, POLL_RETRY_TIMEOUT); k_delayed_work_submit(&lpn->timer, K_MSEC(POLL_RETRY_TIMEOUT));
} else { } else {
if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) {
bt_mesh_scan_disable(); bt_mesh_scan_disable();
@ -755,8 +755,8 @@ static void lpn_timeout(struct k_work *work)
break; break;
case BT_MESH_LPN_REQ_WAIT: case BT_MESH_LPN_REQ_WAIT:
bt_mesh_scan_enable(); bt_mesh_scan_enable();
k_delayed_work_submit(&lpn->timer, k_delayed_work_submit(&lpn->timer, K_MSEC(lpn->adv_duration +
lpn->adv_duration + FRIEND_REQ_SCAN); FRIEND_REQ_SCAN));
lpn_set_state(BT_MESH_LPN_WAIT_OFFER); lpn_set_state(BT_MESH_LPN_WAIT_OFFER);
break; break;
case BT_MESH_LPN_WAIT_OFFER: case BT_MESH_LPN_WAIT_OFFER:
@ -791,8 +791,8 @@ static void lpn_timeout(struct k_work *work)
break; break;
case BT_MESH_LPN_RECV_DELAY: case BT_MESH_LPN_RECV_DELAY:
k_delayed_work_submit(&lpn->timer, k_delayed_work_submit(&lpn->timer,
lpn->adv_duration + SCAN_LATENCY + K_MSEC(lpn->adv_duration + SCAN_LATENCY +
lpn->recv_win); lpn->recv_win));
bt_mesh_scan_enable(); bt_mesh_scan_enable();
lpn_set_state(BT_MESH_LPN_WAIT_UPDATE); lpn_set_state(BT_MESH_LPN_WAIT_UPDATE);
break; break;
@ -840,7 +840,7 @@ static s32_t poll_timeout(struct bt_mesh_lpn *lpn)
{ {
/* If we're waiting for segment acks keep polling at high freq */ /* If we're waiting for segment acks keep polling at high freq */
if (bt_mesh_tx_in_progress()) { if (bt_mesh_tx_in_progress()) {
return MIN(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); return MIN(POLL_TIMEOUT_MAX(lpn), 1 * MSEC_PER_SEC);
} }
if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) { if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) {
@ -913,7 +913,7 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
} }
if (!lpn->sent_req) { if (!lpn->sent_req) {
k_delayed_work_submit(&lpn->timer, poll_timeout(lpn)); k_delayed_work_submit(&lpn->timer, K_MSEC(poll_timeout(lpn)));
} }
return 0; return 0;
@ -1007,7 +1007,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
} }
if (!lpn->sent_req) { if (!lpn->sent_req) {
k_delayed_work_submit(&lpn->timer, poll_timeout(lpn)); k_delayed_work_submit(&lpn->timer, K_MSEC(poll_timeout(lpn)));
} }
return 0; return 0;
@ -1051,7 +1051,8 @@ int bt_mesh_lpn_init(void)
if (IS_ENABLED(CONFIG_BT_MESH_LPN_AUTO)) { if (IS_ENABLED(CONFIG_BT_MESH_LPN_AUTO)) {
BT_DBG("Waiting %u ms for messages", LPN_AUTO_TIMEOUT); BT_DBG("Waiting %u ms for messages", LPN_AUTO_TIMEOUT);
lpn_set_state(BT_MESH_LPN_TIMER); lpn_set_state(BT_MESH_LPN_TIMER);
k_delayed_work_submit(&lpn->timer, LPN_AUTO_TIMEOUT); k_delayed_work_submit(&lpn->timer,
K_MSEC(LPN_AUTO_TIMEOUT));
} }
} }

View file

@ -263,7 +263,8 @@ static void model_resume(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
s32_t period_ms = bt_mesh_model_pub_period_get(mod); s32_t period_ms = bt_mesh_model_pub_period_get(mod);
if (period_ms) { if (period_ms) {
k_delayed_work_submit(&mod->pub->timer, period_ms); k_delayed_work_submit(&mod->pub->timer,
K_MSEC(period_ms));
} }
} }
} }

View file

@ -47,8 +47,8 @@
#define RETRANSMIT_TIMEOUT K_MSEC(500) #define RETRANSMIT_TIMEOUT K_MSEC(500)
#define BUF_TIMEOUT K_MSEC(400) #define BUF_TIMEOUT K_MSEC(400)
#define CLOSING_TIMEOUT K_SECONDS(3) #define CLOSING_TIMEOUT (3 * MSEC_PER_SEC)
#define TRANSACTION_TIMEOUT K_SECONDS(30) #define TRANSACTION_TIMEOUT (30 * MSEC_PER_SEC)
/* Acked messages, will do retransmissions manually, taking acks into account: /* Acked messages, will do retransmissions manually, taking acks into account:
*/ */
@ -534,7 +534,8 @@ static void send_reliable(void)
static void prov_retransmit(struct k_work *work) static void prov_retransmit(struct k_work *work)
{ {
int i, timeout; s32_t timeout_ms;
int i;
BT_DBG(""); BT_DBG("");
@ -549,12 +550,12 @@ static void prov_retransmit(struct k_work *work)
* message until CLOSING_TIMEOUT has elapsed. * message until CLOSING_TIMEOUT has elapsed.
*/ */
if (atomic_test_bit(link.flags, LINK_CLOSING)) { if (atomic_test_bit(link.flags, LINK_CLOSING)) {
timeout = CLOSING_TIMEOUT; timeout_ms = CLOSING_TIMEOUT;
} else { } else {
timeout = TRANSACTION_TIMEOUT; timeout_ms = TRANSACTION_TIMEOUT;
} }
if (k_uptime_get() - link.tx.start > timeout) { if (k_uptime_get() - link.tx.start > timeout_ms) {
if (atomic_test_bit(link.flags, LINK_CLOSING)) { if (atomic_test_bit(link.flags, LINK_CLOSING)) {
close_link(PROV_BEARER_LINK_STATUS_SUCCESS); close_link(PROV_BEARER_LINK_STATUS_SUCCESS);
} else { } else {
@ -778,7 +779,7 @@ void bt_mesh_pb_adv_recv(struct net_buf_simple *buf)
gen_prov_recv(&rx, buf); gen_prov_recv(&rx, buf);
} }
static int prov_link_open(const u8_t uuid[16], s32_t timeout, static int prov_link_open(const u8_t uuid[16], k_timeout_t timeout,
const struct prov_bearer_cb *cb, void *cb_data) const struct prov_bearer_cb *cb, void *cb_data)
{ {
BT_DBG("uuid %s", bt_hex(uuid, 16)); BT_DBG("uuid %s", bt_hex(uuid, 16));

View file

@ -93,7 +93,7 @@ struct prov_bearer {
* *
* @return Zero on success, or (negative) error code otherwise. * @return Zero on success, or (negative) error code otherwise.
*/ */
int (*link_open)(const u8_t uuid[16], s32_t timeout, int (*link_open)(const u8_t uuid[16], k_timeout_t timeout,
const struct prov_bearer_cb *cb, void *cb_data); const struct prov_bearer_cb *cb, void *cb_data);
/** @brief Close the current link. /** @brief Close the current link.

View file

@ -1010,7 +1010,7 @@ static const struct bt_data prov_ad[] = {
#define NODE_ID_LEN 19 #define NODE_ID_LEN 19
#define NET_ID_LEN 11 #define NET_ID_LEN 11
#define NODE_ID_TIMEOUT K_SECONDS(CONFIG_BT_MESH_NODE_ID_TIMEOUT) #define NODE_ID_TIMEOUT (CONFIG_BT_MESH_NODE_ID_TIMEOUT * MSEC_PER_SEC)
static u8_t proxy_svc_data[NODE_ID_LEN] = { 0x28, 0x18, }; static u8_t proxy_svc_data[NODE_ID_LEN] = { 0x28, 0x18, };
@ -1130,21 +1130,21 @@ static int sub_count(void)
return count; return count;
} }
static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) static k_timeout_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
{ {
s32_t remaining = K_FOREVER; s32_t remaining = SYS_FOREVER_MS;
int subnet_count; int subnet_count;
BT_DBG(""); BT_DBG("");
if (conn_count == CONFIG_BT_MAX_CONN) { if (conn_count == CONFIG_BT_MAX_CONN) {
BT_DBG("Connectable advertising deferred (max connections)"); BT_DBG("Connectable advertising deferred (max connections)");
return remaining; return K_FOREVER;
} }
if (!sub) { if (!sub) {
BT_WARN("No subnets to advertise on"); BT_WARN("No subnets to advertise on");
return remaining; return K_FOREVER;
} }
if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) { if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) {
@ -1176,16 +1176,16 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
* second long (to avoid excessive rotation). * second long (to avoid excessive rotation).
*/ */
max_timeout = NODE_ID_TIMEOUT / MAX(subnet_count, 6); max_timeout = NODE_ID_TIMEOUT / MAX(subnet_count, 6);
max_timeout = MAX(max_timeout, K_SECONDS(1)); max_timeout = MAX(max_timeout, 1 * MSEC_PER_SEC);
if (remaining > max_timeout || remaining < 0) { if (remaining > max_timeout || remaining == SYS_FOREVER_MS) {
remaining = max_timeout; remaining = max_timeout;
} }
} }
BT_DBG("Advertising %d ms for net_idx 0x%04x", remaining, sub->net_idx); BT_DBG("Advertising %d ms for net_idx 0x%04x", remaining, sub->net_idx);
return remaining; return SYS_TIMEOUT_MS(remaining);
} }
#endif /* GATT_PROXY */ #endif /* GATT_PROXY */
@ -1235,7 +1235,7 @@ static size_t gatt_prov_adv_create(struct bt_data prov_sd[2])
} }
#endif /* CONFIG_BT_MESH_PB_GATT */ #endif /* CONFIG_BT_MESH_PB_GATT */
s32_t bt_mesh_proxy_adv_start(void) k_timeout_t bt_mesh_proxy_adv_start(void)
{ {
BT_DBG(""); BT_DBG("");

View file

@ -25,7 +25,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub);
struct net_buf_simple *bt_mesh_proxy_get_buf(void); struct net_buf_simple *bt_mesh_proxy_get_buf(void);
s32_t bt_mesh_proxy_adv_start(void); k_timeout_t bt_mesh_proxy_adv_start(void);
void bt_mesh_proxy_adv_stop(void); void bt_mesh_proxy_adv_stop(void);
void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub); void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub);

View file

@ -1093,9 +1093,10 @@ static void commit_mod(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
if (mod->pub && mod->pub->update && if (mod->pub && mod->pub->update &&
mod->pub->addr != BT_MESH_ADDR_UNASSIGNED) { mod->pub->addr != BT_MESH_ADDR_UNASSIGNED) {
s32_t ms = bt_mesh_model_pub_period_get(mod); s32_t ms = bt_mesh_model_pub_period_get(mod);
if (ms) {
if (ms > 0) {
BT_DBG("Starting publish timer (period %u ms)", ms); BT_DBG("Starting publish timer (period %u ms)", ms);
k_delayed_work_submit(&mod->pub->timer, ms); k_delayed_work_submit(&mod->pub->timer, K_MSEC(ms));
} }
} }
@ -1188,30 +1189,30 @@ SETTINGS_STATIC_HANDLER_DEFINE(bt_mesh, "bt/mesh", NULL, mesh_set, mesh_commit,
static void schedule_store(int flag) static void schedule_store(int flag)
{ {
s32_t timeout, remaining; s32_t timeout_ms, remaining;
atomic_set_bit(bt_mesh.flags, flag); atomic_set_bit(bt_mesh.flags, flag);
if (atomic_get(bt_mesh.flags) & NO_WAIT_PENDING_BITS) { if (atomic_get(bt_mesh.flags) & NO_WAIT_PENDING_BITS) {
timeout = K_NO_WAIT; timeout_ms = 0;
} else if (atomic_test_bit(bt_mesh.flags, BT_MESH_RPL_PENDING) && } else if (atomic_test_bit(bt_mesh.flags, BT_MESH_RPL_PENDING) &&
(!(atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) || (!(atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) ||
(CONFIG_BT_MESH_RPL_STORE_TIMEOUT < (CONFIG_BT_MESH_RPL_STORE_TIMEOUT <
CONFIG_BT_MESH_STORE_TIMEOUT))) { CONFIG_BT_MESH_STORE_TIMEOUT))) {
timeout = K_SECONDS(CONFIG_BT_MESH_RPL_STORE_TIMEOUT); timeout_ms = CONFIG_BT_MESH_RPL_STORE_TIMEOUT * MSEC_PER_SEC;
} else { } else {
timeout = K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT); timeout_ms = CONFIG_BT_MESH_STORE_TIMEOUT * MSEC_PER_SEC;
} }
remaining = k_delayed_work_remaining_get(&pending_store); remaining = k_delayed_work_remaining_get(&pending_store);
if (remaining && remaining < timeout) { if ((remaining > 0) && remaining < timeout_ms) {
BT_DBG("Not rescheduling due to existing earlier deadline"); BT_DBG("Not rescheduling due to existing earlier deadline");
return; return;
} }
BT_DBG("Waiting %d seconds", timeout / MSEC_PER_SEC); BT_DBG("Waiting %d seconds", timeout_ms / MSEC_PER_SEC);
k_delayed_work_submit(&pending_store, timeout); k_delayed_work_submit(&pending_store, K_MSEC(timeout_ms));
} }
static void clear_iv(void) static void clear_iv(void)

View file

@ -1851,33 +1851,27 @@ static int cmd_provision(const struct shell *shell, size_t argc, char *argv[])
int cmd_timeout(const struct shell *shell, size_t argc, char *argv[]) int cmd_timeout(const struct shell *shell, size_t argc, char *argv[])
{ {
s32_t timeout; s32_t timeout_ms;
if (argc < 2) { if (argc == 2) {
timeout = bt_mesh_cfg_cli_timeout_get(); s32_t timeout_s;
if (timeout == K_FOREVER) {
shell_print(shell, "Message timeout: forever"); timeout_s = strtol(argv[1], NULL, 0);
if (timeout_s < 0 || timeout_s > (INT32_MAX / 1000)) {
timeout_ms = SYS_FOREVER_MS;
} else { } else {
shell_print(shell, "Message timeout: %u seconds", timeout_ms = timeout_s * MSEC_PER_SEC;
timeout / 1000);
} }
return 0; bt_mesh_cfg_cli_timeout_set(timeout_ms);
} }
timeout = strtol(argv[1], NULL, 0); timeout_ms = bt_mesh_cfg_cli_timeout_get();
if (timeout < 0 || timeout > (INT32_MAX / 1000)) { if (timeout_ms == SYS_FOREVER_MS) {
timeout = K_FOREVER;
} else {
timeout = timeout * 1000;
}
bt_mesh_cfg_cli_timeout_set(timeout);
if (timeout == K_FOREVER) {
shell_print(shell, "Message timeout: forever"); shell_print(shell, "Message timeout: forever");
} else { } else {
shell_print(shell, "Message timeout: %u seconds", shell_print(shell, "Message timeout: %u seconds",
timeout / 1000); timeout_ms / 1000);
} }
return 0; return 0;

View file

@ -58,12 +58,12 @@
* We use 400 since 300 is a common send duration for standard HCI, and we * We use 400 since 300 is a common send duration for standard HCI, and we
* need to have a timeout that's bigger than that. * need to have a timeout that's bigger than that.
*/ */
#define SEG_RETRANSMIT_TIMEOUT_UNICAST(tx) (K_MSEC(400) + 50 * (tx)->ttl) #define SEG_RETRANSMIT_TIMEOUT_UNICAST(tx) (400 + 50 * (tx)->ttl)
/* When sending to a group, the messages are not acknowledged, and there's no /* When sending to a group, the messages are not acknowledged, and there's no
* reason to delay the repetitions significantly. Delaying by more than 0 ms * reason to delay the repetitions significantly. Delaying by more than 0 ms
* to avoid flooding the network. * to avoid flooding the network.
*/ */
#define SEG_RETRANSMIT_TIMEOUT_GROUP K_MSEC(50) #define SEG_RETRANSMIT_TIMEOUT_GROUP 50
#define SEG_RETRANSMIT_TIMEOUT(tx) \ #define SEG_RETRANSMIT_TIMEOUT(tx) \
(BT_MESH_ADDR_IS_UNICAST(tx->dst) ? \ (BT_MESH_ADDR_IS_UNICAST(tx->dst) ? \
@ -317,8 +317,8 @@ static void schedule_retransmit(struct seg_tx *tx)
*/ */
k_delayed_work_submit(&tx->retransmit, k_delayed_work_submit(&tx->retransmit,
(tx->sending || !tx->seg_o) ? (tx->sending || !tx->seg_o) ?
SEG_RETRANSMIT_TIMEOUT(tx) : K_MSEC(SEG_RETRANSMIT_TIMEOUT(tx)) :
0); K_NO_WAIT);
} }
static void seg_send_start(u16_t duration, int err, void *user_data) static void seg_send_start(u16_t duration, int err, void *user_data)
@ -429,7 +429,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
end: end:
if (!tx->seg_pending) { if (!tx->seg_pending) {
k_delayed_work_submit(&tx->retransmit, k_delayed_work_submit(&tx->retransmit,
SEG_RETRANSMIT_TIMEOUT(tx)); K_MSEC(SEG_RETRANSMIT_TIMEOUT(tx)));
} }
tx->sending = 0U; tx->sending = 0U;
@ -1255,15 +1255,15 @@ static inline s32_t ack_timeout(struct seg_rx *rx)
/* The acknowledgment timer shall be set to a minimum of /* The acknowledgment timer shall be set to a minimum of
* 150 + 50 * TTL milliseconds. * 150 + 50 * TTL milliseconds.
*/ */
to = K_MSEC(150 + (ttl * 50U)); to = 150 + (ttl * 50U);
/* 100 ms for every not yet received segment */ /* 100 ms for every not yet received segment */
to += K_MSEC(((rx->seg_n + 1) - popcount(rx->block)) * 100U); to += ((rx->seg_n + 1) - popcount(rx->block)) * 100U;
/* Make sure we don't send more frequently than the duration for /* Make sure we don't send more frequently than the duration for
* each packet (default is 300ms). * each packet (default is 300ms).
*/ */
return MAX(to, K_MSEC(400)); return MAX(to, 400);
} }
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
@ -1375,7 +1375,7 @@ static void seg_ack(struct k_work *work)
BT_DBG("rx %p", rx); BT_DBG("rx %p", rx);
if (k_uptime_get_32() - rx->last > K_SECONDS(60)) { if (k_uptime_get_32() - rx->last > (60 * MSEC_PER_SEC)) {
BT_WARN("Incomplete timer expired"); BT_WARN("Incomplete timer expired");
seg_rx_reset(rx, false); seg_rx_reset(rx, false);
@ -1389,7 +1389,7 @@ static void seg_ack(struct k_work *work)
send_ack(rx->sub, rx->dst, rx->src, rx->ttl, &rx->seq_auth, send_ack(rx->sub, rx->dst, rx->src, rx->ttl, &rx->seq_auth,
rx->block, rx->obo); rx->block, rx->obo);
k_delayed_work_submit(&rx->ack, ack_timeout(rx)); k_delayed_work_submit(&rx->ack, K_MSEC(ack_timeout(rx)));
} }
static inline bool sdu_len_is_ok(bool ctl, u8_t seg_n) static inline bool sdu_len_is_ok(bool ctl, u8_t seg_n)
@ -1671,7 +1671,7 @@ found_rx:
if (!k_delayed_work_remaining_get(&rx->ack) && if (!k_delayed_work_remaining_get(&rx->ack) &&
!bt_mesh_lpn_established()) { !bt_mesh_lpn_established()) {
k_delayed_work_submit(&rx->ack, ack_timeout(rx)); k_delayed_work_submit(&rx->ack, K_MSEC(ack_timeout(rx)));
} }
/* Allocated segment here */ /* Allocated segment here */