@@ -407,10 +407,17 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan)
407
407
HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_XTAL_US );
408
408
scan -> ull .ticks_preempt_to_start =
409
409
HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_PREEMPT_MIN_US );
410
+
411
+ if (IS_ENABLED (CONFIG_BT_CTLR_LOW_LAT )) {
412
+ ticks_slot_overhead = MAX (scan -> ull .ticks_active_to_start ,
413
+ scan -> ull .ticks_prepare_to_start );
414
+ } else {
415
+ ticks_slot_overhead = 0U ;
416
+ }
417
+
410
418
if ((lll -> ticks_window +
411
419
HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_START_US )) <
412
- (ticks_interval -
413
- HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_XTAL_US ))) {
420
+ (ticks_interval - ticks_slot_overhead )) {
414
421
scan -> ull .ticks_slot =
415
422
(lll -> ticks_window +
416
423
HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_START_US ));
@@ -419,17 +426,119 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan)
419
426
scan -> ull .ticks_slot = 0U ;
420
427
} else {
421
428
scan -> ull .ticks_slot = ticks_interval -
422
- HAL_TICKER_US_TO_TICKS ( EVENT_OVERHEAD_XTAL_US ) ;
429
+ ticks_slot_overhead ;
423
430
}
424
431
425
432
lll -> ticks_window = 0U ;
426
433
}
427
434
428
- if (IS_ENABLED (CONFIG_BT_CTLR_LOW_LAT )) {
429
- ticks_slot_overhead = MAX (scan -> ull .ticks_active_to_start ,
430
- scan -> ull .ticks_prepare_to_start );
435
+ handle = ull_scan_handle_get (scan );
436
+
437
+ if (false) {
438
+
439
+ #if defined(CONFIG_BT_CTLR_ADV_EXT ) && defined(CONFIG_BT_CTLR_PHY_CODED )
440
+ } else if (handle == SCAN_HANDLE_1M ) {
441
+ const struct ll_scan_set * scan_coded ;
442
+
443
+ scan_coded = ull_scan_set_get (SCAN_HANDLE_PHY_CODED );
444
+ if (IS_PHY_ENABLED (scan_coded , PHY_CODED ) &&
445
+ (lll -> ticks_window != 0U )) {
446
+ const struct lll_scan * lll_coded ;
447
+ uint32_t ticks_interval_coded ;
448
+
449
+ lll_coded = & scan_coded -> lll ;
450
+ ticks_interval_coded = HAL_TICKER_US_TO_TICKS (
451
+ (uint64_t )lll_coded -> interval *
452
+ SCAN_INT_UNIT_US );
453
+ /* Check if 1M and Coded PHY scanning use same interval
454
+ * and the sum of the scan window duration equals their
455
+ * interval then use continuous scanning and avoid time
456
+ * reservation from overlapping.
457
+ */
458
+ if ((ticks_interval == ticks_interval_coded ) &&
459
+ (ticks_interval == (lll -> ticks_window +
460
+ lll_coded -> ticks_window ))) {
461
+ if (IS_ENABLED (CONFIG_BT_CTLR_SCAN_UNRESERVED )) {
462
+ scan -> ull .ticks_slot = 0U ;
463
+ } else {
464
+ scan -> ull .ticks_slot =
465
+ lll -> ticks_window -
466
+ ticks_slot_overhead -
467
+ HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_START_US ) -
468
+ HAL_TICKER_US_TO_TICKS (EVENT_TICKER_RES_MARGIN_US );
469
+ }
470
+
471
+ /* Continuous scanning, no scan window stop
472
+ * ticker to be started but we will zero the
473
+ * ticks_window value when coded PHY scan is
474
+ * enabled (the next following else clause).
475
+ * Due to this the first scan window will have
476
+ * the stop ticker started but consecutive
477
+ * scan window will not have the stop ticker
478
+ * started once coded PHY scan window has been
479
+ * enabled.
480
+ */
481
+ }
482
+ }
483
+
484
+ /* 1M scan window starts without any offset */
485
+ ticks_offset = 0U ;
486
+
487
+ } else if (handle == SCAN_HANDLE_PHY_CODED ) {
488
+ struct ll_scan_set * scan_1m ;
489
+
490
+ scan_1m = ull_scan_set_get (SCAN_HANDLE_1M );
491
+ if (IS_PHY_ENABLED (scan_1m , PHY_1M ) &&
492
+ (lll -> ticks_window != 0U )) {
493
+ uint32_t ticks_interval_1m ;
494
+ struct lll_scan * lll_1m ;
495
+
496
+ lll_1m = & scan_1m -> lll ;
497
+ ticks_interval_1m = HAL_TICKER_US_TO_TICKS (
498
+ (uint64_t )lll_1m -> interval *
499
+ SCAN_INT_UNIT_US );
500
+ /* Check if 1M and Coded PHY scanning use same interval
501
+ * and the sum of the scan window duration equals their
502
+ * interval then use continuous scanning and avoid time
503
+ * reservation from overlapping.
504
+ */
505
+ if ((ticks_interval == ticks_interval_1m ) &&
506
+ (ticks_interval == (lll -> ticks_window +
507
+ lll_1m -> ticks_window ))) {
508
+ if (IS_ENABLED (CONFIG_BT_CTLR_SCAN_UNRESERVED )) {
509
+ scan -> ull .ticks_slot = 0U ;
510
+ } else {
511
+ scan -> ull .ticks_slot =
512
+ lll -> ticks_window -
513
+ ticks_slot_overhead -
514
+ HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_START_US ) -
515
+ HAL_TICKER_US_TO_TICKS (EVENT_TICKER_RES_MARGIN_US );
516
+ }
517
+ /* Offset the coded PHY scan window, place
518
+ * after 1M scan window.
519
+ * Have some margin for jitter due to ticker
520
+ * resolution.
521
+ */
522
+ ticks_offset = lll_1m -> ticks_window ;
523
+ ticks_offset += HAL_TICKER_US_TO_TICKS (
524
+ EVENT_TICKER_RES_MARGIN_US << 1 );
525
+
526
+ /* Continuous scanning, no scan window stop
527
+ * ticker started for both 1M and coded PHY.
528
+ */
529
+ lll -> ticks_window = 0U ;
530
+ lll_1m -> ticks_window = 0U ;
531
+
532
+ } else {
533
+ ticks_offset = 0U ;
534
+ }
535
+ } else {
536
+ ticks_offset = 0U ;
537
+ }
538
+ #endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */
539
+
431
540
} else {
432
- ticks_slot_overhead = 0U ;
541
+ ticks_offset = 0U ;
433
542
}
434
543
435
544
ticks_anchor = ticker_ticks_now_get ();
@@ -456,27 +565,6 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan)
456
565
}
457
566
#endif /* CONFIG_BT_CENTRAL && CONFIG_BT_CTLR_SCHED_ADVANCED */
458
567
459
- handle = ull_scan_handle_get (scan );
460
-
461
- if (false) {
462
-
463
- #if defined(CONFIG_BT_CTLR_ADV_EXT ) && defined(CONFIG_BT_CTLR_PHY_CODED )
464
- } else if (handle == SCAN_HANDLE_PHY_CODED ) {
465
- const struct ll_scan_set * scan_1m ;
466
-
467
- scan_1m = ull_scan_set_get (SCAN_HANDLE_1M );
468
- if (IS_PHY_ENABLED (scan_1m , PHY_1M )) {
469
- ticks_offset = scan_1m -> lll .ticks_window +
470
- (EVENT_TICKER_RES_MARGIN_US << 1 );
471
- } else {
472
- ticks_offset = 0U ;
473
- }
474
- #endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */
475
-
476
- } else {
477
- ticks_offset = 0U ;
478
- }
479
-
480
568
ret_cb = TICKER_STATUS_BUSY ;
481
569
ret = ticker_start (TICKER_INSTANCE_ID_CTLR ,
482
570
TICKER_USER_ID_THREAD , TICKER_ID_SCAN_BASE + handle ,
0 commit comments