From 40dde5b7bdea3f59177a667d106f24de5130e417 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Mon, 8 May 2023 13:57:56 +0200 Subject: [PATCH] Bluetooth: controller: fix time-wrapping of cig_ref_point Time wrapping was omitted at some points. These were corrected or clarified. Signed-off-by: Nirosharn Amarasinghe --- .../bluetooth/controller/ll_sw/ull_central_iso.c | 15 +++++++++++---- subsys/bluetooth/controller/ll_sw/ull_iso.c | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 75880d8bfb9224..e78b5c3955eaa4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -761,11 +761,18 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, /* CIG is started. Use the CIG reference point and latest ticks_at_expire * for associated ACL, to calculate the offset. + * NOTE: The following calculations are done in a 32-bit time + * range with full consideration and expectation that the + * controller clock does not support the full 32-bit range in + * microseconds. However it is valid as the purpose is to + * calculate the difference and the spare higher order bits will + * ensure that no wrapping can occur before the termination + * condition of the while loop is met. Using time wrapping will + * complicate this. */ - time_of_intant = isoal_get_wrapped_time_us( - HAL_TICKER_TICKS_TO_US(conn->llcp.prep.ticks_at_expire), - EVENT_OVERHEAD_START_US + - (instant - event_counter) * conn->lll.interval * CONN_INT_UNIT_US); + time_of_intant = HAL_TICKER_TICKS_TO_US(conn->llcp.prep.ticks_at_expire) + + EVENT_OVERHEAD_START_US + + ((instant - event_counter) * conn->lll.interval * CONN_INT_UNIT_US); cig_ref_point = cig->cig_ref_point; while (cig_ref_point < time_of_intant) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index 9f874b8b809fdb..e04d29cc1ec5f8 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -1410,8 +1410,8 @@ static void iso_rx_cig_ref_point_update(struct ll_conn_iso_group *cig, /* Update the CIG reference point based on the CIS * anchor point */ - cig->cig_ref_point = meta->timestamp + cis_sync_delay - - cig_sync_delay; + cig->cig_ref_point = isoal_get_wrapped_time_us(meta->timestamp, + cis_sync_delay - cig_sync_delay); } } }