Bluetooth: controller: Use conversion macros for duration and period

Use conversion macros to convert Extended Scan duration and
period to radio event counts.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2020-10-17 05:48:31 +05:30 committed by Carles Cufí
parent 0cef1e43c9
commit 1bb4e6caa5
2 changed files with 22 additions and 11 deletions

View file

@ -748,22 +748,18 @@ static uint8_t duration_period_setup(struct ll_scan_set *scan,
lll = &scan->lll;
if (duration) {
lll->duration_reload = ((uint32_t)duration *
EXT_SCAN_DURATION_UNIT_US /
SCAN_INTERVAL_UNIT_US) /
scan->lll.interval;
lll->duration_reload =
ULL_SCAN_DURATION_TO_EVENTS(duration,
scan->lll.interval);
if (period) {
if (IS_ENABLED(CONFIG_BT_CTLR_PARAM_CHECK) &&
(duration >= ((uint32_t)period *
EXT_SCAN_PERIOD_UNIT_US/
EXT_SCAN_DURATION_UNIT_US))) {
(duration >= ULL_SCAN_PERIOD_TO_DURATION(period))) {
return BT_HCI_ERR_INVALID_PARAM;
}
scan->duration_lazy = ((uint32_t)period *
EXT_SCAN_PERIOD_UNIT_US /
SCAN_INTERVAL_UNIT_US) /
scan->lll.interval;
scan->duration_lazy =
ULL_SCAN_PERIOD_TO_EVENTS(period,
scan->lll.interval);
scan->duration_lazy -= lll->duration_reload;
scan->node_rx_scan_term = NULL;
} else {

View file

@ -13,6 +13,21 @@
#define EXT_SCAN_DURATION_UNIT_US 10000U
#define EXT_SCAN_PERIOD_UNIT_US 1280000U
/* Convert period in 1.28 s units to duration of 10 ms units*/
#define ULL_SCAN_PERIOD_TO_DURATION(period) \
((uint32_t)(period) * EXT_SCAN_PERIOD_UNIT_US / \
EXT_SCAN_DURATION_UNIT_US)
/* Convert duration in 10 ms unit to radio events count */
#define ULL_SCAN_DURATION_TO_EVENTS(duration, interval) \
(((uint32_t)(duration) * EXT_SCAN_DURATION_UNIT_US / \
SCAN_INTERVAL_UNIT_US) / (interval))
/* Convert period in 1.28 s unit to radio events count */
#define ULL_SCAN_PERIOD_TO_EVENTS(period, interval) \
(((uint32_t)(period) * EXT_SCAN_PERIOD_UNIT_US / \
SCAN_INTERVAL_UNIT_US) / (interval))
int ull_scan_init(void);
int ull_scan_reset(void);