Skip to content

Commit

Permalink
Bluetooth: controller: fix time-wrapping of cig_ref_point
Browse files Browse the repository at this point in the history
Time wrapping was omitted at some points. These were corrected or
clarified.

Signed-off-by: Nirosharn Amarasinghe <[email protected]>
  • Loading branch information
niag-Oticon authored and carlescufi committed Jun 6, 2023
1 parent f043425 commit 40dde5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions subsys/bluetooth/controller/ll_sw/ull_central_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/controller/ll_sw/ull_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 40dde5b

Please sign in to comment.