Bluetooth: Controller: Add HAL_TICKER_TICKS_TO_US_64BIT define

Add HAL_TICKER_TICKS_TO_US_64BIT define, to return
microsecond value in 64-bits.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2024-06-10 22:23:14 +02:00 committed by Anas Nashif
commit a947d6f635
6 changed files with 16 additions and 10 deletions

View file

@ -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)

View file

@ -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) \
( \

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -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);