Skip to content

Commit dd56a8e

Browse files
committed
Bluetooth: Controller: Updates to win_offset_calc
Fix the advanced scheduling implementation of win_offset_calc() function to consider both active central and active peripheral roles as occupied timespace when determining the free timespace available to fill the offsets in the connection parameter request PDU. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 5f93f33 commit dd56a8e

File tree

1 file changed

+96
-97
lines changed

1 file changed

+96
-97
lines changed

subsys/bluetooth/controller/ll_sw/ull_sched.c

Lines changed: 96 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select,
428428
uint32_t ticks_slot_abs = 0U;
429429
uint32_t ticks_anchor_prev;
430430
uint32_t ticks_to_expire;
431-
uint8_t ticker_id_other;
432431
uint8_t ticker_id_prev;
433432
uint32_t ticks_anchor;
434433
uint8_t offset_index;
@@ -457,18 +456,26 @@ static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select,
457456
#endif
458457

459458
ticks_slot_abs += conn_curr->ull.ticks_slot;
460-
461459
if (conn_curr->lll.role) {
462460
ticks_slot_abs += HAL_TICKER_US_TO_TICKS(EVENT_TIES_US);
463461
}
464462

465-
ticker_id = ticker_id_prev = ticker_id_other = TICKER_NULL;
463+
if (ticks_slot_abs < HAL_TICKER_US_TO_TICKS(CONFIG_BT_CTLR_CENTRAL_SPACING)) {
464+
ticks_slot_abs =
465+
HAL_TICKER_US_TO_TICKS(CONFIG_BT_CTLR_CENTRAL_SPACING);
466+
}
467+
468+
ticker_id = ticker_id_prev = TICKER_NULL;
466469
ticks_to_expire = ticks_to_expire_prev = ticks_anchor =
467470
ticks_anchor_prev = offset_index = offset = 0U;
468471
ticks_slot_abs_prev = 0U;
469472
do {
473+
uint32_t ticks_slot_abs_curr = 0U;
474+
uint32_t ticks_slot_margin = 0U;
475+
uint32_t ticks_to_expire_normal;
470476
uint32_t volatile ret_cb;
471-
struct ll_conn *conn;
477+
struct ull_hdr *hdr;
478+
uint32_t ticks_slot;
472479
uint32_t ret;
473480
bool success;
474481

@@ -504,121 +511,108 @@ static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select,
504511
LL_ASSERT(0);
505512
}
506513

507-
/* consider advertiser time as available. Any other time used by
508-
* tickers declared outside the controller is also available.
514+
/* Save the reference anchor and ticker id to check updated
515+
* ticker list.
509516
*/
510-
#if defined(CONFIG_BT_BROADCASTER)
511-
if ((ticker_id < TICKER_ID_ADV_BASE) ||
512-
(ticker_id > TICKER_ID_CONN_LAST))
513-
#else /* !CONFIG_BT_BROADCASTER */
514-
if ((ticker_id < TICKER_ID_SCAN_BASE) ||
515-
(ticker_id > TICKER_ID_CONN_LAST))
516-
#endif /* !CONFIG_BT_BROADCASTER */
517-
{
518-
continue;
519-
}
517+
ticks_anchor_prev = ticks_anchor;
518+
ticker_id_prev = ticker_id;
519+
520+
/* Get ULL header and time reservation for non-overlapping
521+
* tickers.
522+
*/
523+
hdr = ull_hdr_get_cb(ticker_id, &ticks_slot);
524+
if (!hdr) {
525+
/* TODO: check overlapping scanner */
526+
LL_ASSERT(!is_select);
520527

521-
if (ticker_id < TICKER_ID_CONN_BASE) {
522-
/* non conn role found which could have preempted a
523-
* conn role, hence do not consider this free space
524-
* and any further as free slot for offset,
525-
*/
526-
ticker_id_other = ticker_id;
527528
continue;
528529
}
529530

530-
/* TODO: handle scanner; for now we exit with as much we
531-
* where able to fill (offsets).
532-
*/
533-
if (ticker_id_other != TICKER_NULL) {
534-
break;
535-
}
531+
ticks_to_expire_normal = ticks_to_expire +
532+
ticks_prepare_reduced;
536533

537-
conn = ll_conn_get(ticker_id - TICKER_ID_CONN_BASE);
538-
if ((conn != conn_curr) && (is_select || !conn->lll.role)) {
539-
uint32_t ticks_to_expire_normal =
540-
ticks_to_expire + ticks_prepare_reduced;
541-
uint32_t ticks_slot_margin = 0U;
542-
uint32_t ticks_slot_abs_curr = 0U;
543534
#if defined(CONFIG_BT_CTLR_LOW_LAT)
544535
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
545-
if (conn->ull.ticks_prepare_to_start & XON_BITMASK) {
546-
uint32_t ticks_prepare_to_start =
547-
MAX(conn->ull.ticks_active_to_start,
548-
conn->ull.ticks_preempt_to_start);
549-
550-
ticks_slot_abs_curr =
551-
conn->ull.ticks_prepare_to_start &
552-
~XON_BITMASK;
553-
ticks_to_expire_normal -=
554-
ticks_slot_abs_curr -
555-
ticks_prepare_to_start;
556-
} else
536+
if (hdr->ticks_prepare_to_start & XON_BITMASK) {
537+
const uint32_t ticks_prepare_to_start =
538+
MAX(hdr->ticks_active_to_start,
539+
hdr->ticks_preempt_to_start);
540+
541+
ticks_slot_abs_curr = hdr->ticks_prepare_to_start &
542+
~XON_BITMASK;
543+
ticks_to_expire_normal -= ticks_slot_abs_curr -
544+
ticks_prepare_to_start;
545+
} else
557546
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
558-
{
559-
uint32_t ticks_prepare_to_start =
560-
MAX(conn->ull.ticks_active_to_start,
561-
conn->ull.ticks_prepare_to_start);
547+
{
548+
const uint32_t ticks_prepare_to_start =
549+
MAX(hdr->ticks_active_to_start,
550+
hdr->ticks_prepare_to_start);
562551

563-
ticks_slot_abs_curr = ticks_prepare_to_start;
564-
}
552+
ticks_slot_abs_curr = ticks_prepare_to_start;
553+
}
565554
#endif
566555

567-
ticks_slot_abs_curr += conn->ull.ticks_slot +
568-
HAL_TICKER_US_TO_TICKS(CONN_INT_UNIT_US);
556+
if (ticker_id >= TICKER_ID_CONN_BASE) {
557+
struct ll_conn *conn;
558+
559+
conn = ll_conn_get(ticker_id - TICKER_ID_CONN_BASE);
560+
if (!is_select && conn->lll.role) {
561+
continue;
562+
}
563+
564+
if (is_select &&
565+
(conn->lll.interval != conn_interval)) {
566+
ticks_slot_abs_curr += ticks_slot_abs;
567+
}
569568

570569
if (conn->lll.role) {
571570
ticks_slot_margin =
572571
HAL_TICKER_US_TO_TICKS(EVENT_TIES_US);
573572
ticks_slot_abs_curr += ticks_slot_margin;
574573
}
574+
}
575575

576-
if (*ticks_to_offset_next < ticks_to_expire_normal) {
577-
if (ticks_to_expire_prev <
578-
*ticks_to_offset_next) {
579-
ticks_to_expire_prev =
580-
*ticks_to_offset_next;
581-
}
582-
583-
while ((offset_index < *offset_max) &&
584-
(ticker_ticks_diff_get(
585-
ticks_to_expire_normal,
586-
ticks_to_expire_prev) >=
587-
(ticks_slot_abs_prev + ticks_slot_abs +
588-
ticks_slot_margin))) {
589-
offset = (ticks_to_expire_prev +
590-
ticks_slot_abs_prev) /
591-
HAL_TICKER_US_TO_TICKS(
592-
CONN_INT_UNIT_US);
593-
if (offset >= conn_interval) {
594-
ticks_to_expire_prev = 0U;
595-
596-
break;
597-
}
598-
599-
sys_put_le16(offset,
600-
(win_offset +
601-
(sizeof(uint16_t) *
602-
offset_index)));
603-
offset_index++;
576+
if (*ticks_to_offset_next < ticks_to_expire_normal) {
577+
if (ticks_to_expire_prev <
578+
*ticks_to_offset_next) {
579+
ticks_to_expire_prev =
580+
*ticks_to_offset_next;
581+
}
604582

605-
ticks_to_expire_prev +=
606-
HAL_TICKER_US_TO_TICKS(
607-
CONN_INT_UNIT_US);
583+
while ((offset_index < *offset_max) &&
584+
(ticker_ticks_diff_get(
585+
ticks_to_expire_normal,
586+
ticks_to_expire_prev) >=
587+
(ticks_slot_abs_prev + ticks_slot_abs +
588+
ticks_slot_margin))) {
589+
offset = DIV_ROUND_UP(
590+
(ticks_to_expire_prev +
591+
ticks_slot_abs_prev),
592+
HAL_TICKER_US_TO_TICKS(
593+
CONN_INT_UNIT_US));
594+
while (offset >= conn_interval) {
595+
offset -= conn_interval;
608596
}
609597

610-
*ticks_to_offset_next = ticks_to_expire_prev;
598+
sys_put_le16(offset,
599+
(win_offset +
600+
(sizeof(uint16_t) *
601+
offset_index)));
602+
offset_index++;
611603

612-
if (offset >= conn_interval) {
613-
break;
614-
}
604+
ticks_to_expire_prev +=
605+
HAL_TICKER_US_TO_TICKS(
606+
CONN_INT_UNIT_US);
615607
}
616608

617-
ticks_anchor_prev = ticks_anchor;
618-
ticker_id_prev = ticker_id;
619-
ticks_to_expire_prev = ticks_to_expire_normal;
620-
ticks_slot_abs_prev = ticks_slot_abs_curr;
609+
*ticks_to_offset_next = ticks_to_expire_prev;
621610
}
611+
612+
ticks_slot_abs_curr += ticks_slot;
613+
614+
ticks_to_expire_prev = ticks_to_expire_normal;
615+
ticks_slot_abs_prev = ticks_slot_abs_curr;
622616
} while (offset_index < *offset_max);
623617

624618
if (ticker_id == TICKER_NULL) {
@@ -627,12 +621,17 @@ static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select,
627621
}
628622

629623
while (offset_index < *offset_max) {
630-
offset = (ticks_to_expire_prev + ticks_slot_abs_prev) /
631-
HAL_TICKER_US_TO_TICKS(CONN_INT_UNIT_US);
624+
offset = DIV_ROUND_UP(
625+
(ticks_to_expire_prev + ticks_slot_abs_prev),
626+
HAL_TICKER_US_TO_TICKS(CONN_INT_UNIT_US));
632627
if (offset >= conn_interval) {
633-
ticks_to_expire_prev = 0U;
628+
if (!is_select) {
629+
break;
630+
}
634631

635-
break;
632+
while (offset >= conn_interval) {
633+
offset -= conn_interval;
634+
}
636635
}
637636

638637
sys_put_le16(offset, (win_offset + (sizeof(uint16_t) *

0 commit comments

Comments
 (0)