Bluetooth: Mesh: remove redundant 32-bit wrap-around code
The separate checking for "now < reftime" is unnecessary, since the integer over/under-flow for unsigned 32-bit values resulting from subtraction will give the right delta even if 'now' is less than the reference. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
5633ec0413
commit
7c53d31ed2
3 changed files with 5 additions and 22 deletions
|
@ -99,19 +99,15 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod)
|
|||
|
||||
static s32_t next_period(struct bt_mesh_model *mod)
|
||||
{
|
||||
u32_t elapsed, period, now = k_uptime_get_32();
|
||||
struct bt_mesh_model_pub *pub = mod->pub;
|
||||
u32_t elapsed, period;
|
||||
|
||||
period = bt_mesh_model_pub_period_get(mod);
|
||||
if (!period) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (now < pub->period_start) {
|
||||
elapsed = now + (UINT32_MAX - pub->period_start);
|
||||
} else {
|
||||
elapsed = now - pub->period_start;
|
||||
}
|
||||
elapsed = k_uptime_get_32() - pub->period_start;
|
||||
|
||||
BT_DBG("Publishing took %ums", elapsed);
|
||||
|
||||
|
|
|
@ -135,13 +135,7 @@ static int secure_beacon_send(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* Handle time wrap due to 32-bit storage */
|
||||
if (sub->beacon_sent > now) {
|
||||
time_diff = (UINT32_MAX - sub->beacon_sent) + now;
|
||||
} else {
|
||||
time_diff = now - sub->beacon_sent;
|
||||
}
|
||||
|
||||
time_diff = now - sub->beacon_sent;
|
||||
if (time_diff < BEACON_THRESHOLD(sub)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -646,18 +646,11 @@ static void clear_timeout(struct k_work *work)
|
|||
{
|
||||
struct bt_mesh_friend *frnd = CONTAINER_OF(work, struct bt_mesh_friend,
|
||||
clear.timer.work);
|
||||
u32_t now, duration;
|
||||
u32_t duration;
|
||||
|
||||
BT_DBG("LPN 0x%04x (old) Friend 0x%04x", frnd->lpn, frnd->clear.frnd);
|
||||
|
||||
now = k_uptime_get_32();
|
||||
/* Handle time wrap-around due to 32-bit limit */
|
||||
if (now < frnd->clear.start) {
|
||||
duration = (UINT32_MAX - frnd->clear.start) + now;
|
||||
} else {
|
||||
duration = now - frnd->clear.start;
|
||||
}
|
||||
|
||||
duration = k_uptime_get_32() - frnd->clear.start;
|
||||
if (duration > 2 * frnd->poll_to) {
|
||||
BT_DBG("Clear Procedure timer expired");
|
||||
frnd->clear.frnd = BT_MESH_ADDR_UNASSIGNED;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue