diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index e5859959697..d0c5b1a75d3 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -71,7 +71,7 @@ LOG_MODULE_REGISTER(bt_ctlr_isoal, CONFIG_BT_CTLR_ISOAL_LOG_LEVEL); /* Defined the wrapping point and mid point in the range of time input values, * which depend on range of the controller's clock in microseconds. */ -#define ISOAL_TIME_WRAPPING_POINT_US (HAL_TICKER_TICKS_TO_US(HAL_TICKER_CNTR_MASK)) +#define ISOAL_TIME_WRAPPING_POINT_US (HAL_TICKER_TICKS_TO_US_64BIT(HAL_TICKER_CNTR_MASK)) #define ISOAL_TIME_MID_POINT_US (ISOAL_TIME_WRAPPING_POINT_US / 2) #define ISOAL_TIME_SPAN_FULL_US (ISOAL_TIME_WRAPPING_POINT_US + 1) #define ISOAL_TIME_SPAN_HALF_US (ISOAL_TIME_SPAN_FULL_US / 2) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h index 1a5c1a3f8a7..0def788727b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h @@ -44,12 +44,14 @@ ) /* Macro to translate tick units to microseconds. */ -#define HAL_TICKER_TICKS_TO_US(x) \ +#define HAL_TICKER_TICKS_TO_US_64BIT(x) \ ( \ - ((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ - HAL_TICKER_FSEC_PER_USEC)) \ + (((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FSEC) / \ + HAL_TICKER_FSEC_PER_USEC) \ ) +#define HAL_TICKER_TICKS_TO_US(x) ((uint32_t)HAL_TICKER_TICKS_TO_US_64BIT(x)) + /* Macro returning remainder in picoseconds (to fit in 32-bits) */ #define HAL_TICKER_REMAINDER(x) \ ( \ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 1a4d09c47c6..9d8b517cb55 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -775,7 +775,7 @@ static void isr_rx(void *param) (cis_lll->rx.payload_count / cis_lll->rx.bn)) * cig_lll->iso_interval_us; iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + HAL_TICKER_TICKS_TO_US_64BIT(BIT64(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; ull_iso_pdu_rx_alloc(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 07b6c5aae09..4c57de3e065 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -606,7 +606,7 @@ static void isr_rx(void *param) (cis_lll->rx.payload_count / cis_lll->rx.bn)) * cig_lll->iso_interval_us; iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + HAL_TICKER_TICKS_TO_US_64BIT(BIT64(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; ull_iso_pdu_rx_alloc(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 14de5add323..42c57790516 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -1366,7 +1366,7 @@ static void isr_rx_iso_data_valid(const struct lll_sync_iso *const lll, lll->sub_interval * ((lll->irc * lll->bn) + lll->ptc)); iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + HAL_TICKER_TICKS_TO_US_64BIT(BIT64(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; } @@ -1390,7 +1390,7 @@ static void isr_rx_iso_data_invalid(const struct lll_sync_iso *const lll, lll->sub_interval * ((lll->irc * lll->bn) + lll->ptc)); iso_meta->timestamp %= - HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); + HAL_TICKER_TICKS_TO_US_64BIT(BIT64(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 1U; } diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index b7beb40f38a..1422d56ee3a 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -925,14 +925,18 @@ ZTEST(test_rx_unframed, test_rx_time_wrapping) /* Maximum negative difference from 0 */ time_now = 0; - time_diff = (time_wrapping_point == UINT32_MAX ? INT32_MIN : -ISOAL_TIME_WRAPPING_POINT_US); + time_diff = (time_wrapping_point == UINT32_MAX) ? + INT32_MIN : + -((int64_t)ISOAL_TIME_WRAPPING_POINT_US); expected_result = ISOAL_TIME_WRAPPING_POINT_US + time_diff + 1; result = isoal_get_wrapped_time_test(time_now, time_diff); zassert_equal(result, expected_result, "%lu != %lu", result, expected_result); /* Maximum negative difference from maximum time */ time_now = ISOAL_TIME_WRAPPING_POINT_US; - time_diff = (time_wrapping_point == UINT32_MAX ? INT32_MIN : -ISOAL_TIME_WRAPPING_POINT_US); + time_diff = (time_wrapping_point == UINT32_MAX) ? + INT32_MIN : + -((int64_t)ISOAL_TIME_WRAPPING_POINT_US); expected_result = ISOAL_TIME_WRAPPING_POINT_US + time_diff; result = isoal_get_wrapped_time_test(time_now, time_diff); zassert_equal(result, expected_result, "%lu != %lu", result, expected_result);