4040
4141#include "ull_internal.h"
4242#include "ull_chan_internal.h"
43+ #include "ull_sched_internal.h"
4344#include "ull_adv_internal.h"
4445
4546#include "ll.h"
@@ -836,6 +837,7 @@ uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable)
836837 struct pdu_adv_sync_info * sync_info ;
837838 uint8_t value [1 + sizeof (sync_info )];
838839 uint32_t ticks_slot_overhead_aux ;
840+ uint32_t ticks_slot_overhead ;
839841 struct lll_adv_aux * lll_aux ;
840842 struct ll_adv_aux_set * aux ;
841843 uint32_t ticks_anchor_sync ;
@@ -860,6 +862,12 @@ uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable)
860862 (void )memcpy (& sync_info , & value [1 ], sizeof (sync_info ));
861863 ull_adv_sync_info_fill (sync , sync_info );
862864
865+ /* Calculate the ticks_slot and return slot overhead */
866+ ticks_slot_overhead = ull_adv_sync_evt_init (adv , sync );
867+
868+ /* If Auxiliary PDU already active, find and schedule Periodic
869+ * advertising follow it.
870+ */
863871 if (lll_aux ) {
864872 /* Auxiliary set already active (due to other fields
865873 * being already present or being started prior).
@@ -868,15 +876,27 @@ uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable)
868876 ticks_anchor_aux = 0U ; /* unused in this path */
869877 ticks_slot_overhead_aux = 0U ; /* unused in this path */
870878
871- /* TODO: Find the anchor after the group of active
872- * auxiliary sets such that Periodic Advertising
873- * events are placed in non-overlapping timeline
874- * when auxiliary and Periodic Advertising have
875- * similar event interval.
879+ /* Find the anchor after the group of active auxiliary
880+ * sets such that Periodic Advertising events are placed
881+ * in non-overlapping timeline when auxiliary and
882+ * Periodic Advertising have similar event interval.
876883 */
877- ticks_anchor_sync =
878- ticker_ticks_now_get () +
884+ ticks_anchor_sync = ticker_ticks_now_get () +
879885 HAL_TICKER_US_TO_TICKS (EVENT_OVERHEAD_START_US );
886+
887+ #if defined(CONFIG_BT_CTLR_SCHED_ADVANCED )
888+ err = ull_sched_adv_aux_sync_free_slot_get (TICKER_USER_ID_THREAD ,
889+ sync -> ull .ticks_slot ,
890+ & ticks_anchor_sync );
891+ if (!err ) {
892+ ticks_anchor_sync += HAL_TICKER_US_TO_TICKS (
893+ MAX (EVENT_MAFS_US ,
894+ EVENT_OVERHEAD_START_US ) -
895+ EVENT_OVERHEAD_START_US +
896+ (EVENT_TICKER_RES_MARGIN_US << 1 ));
897+ }
898+ #endif /* CONFIG_BT_CTLR_SCHED_ADVANCED */
899+
880900 } else {
881901 /* Auxiliary set will be started due to inclusion of
882902 * sync info field.
@@ -897,7 +917,8 @@ uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable)
897917 (EVENT_TICKER_RES_MARGIN_US << 1 ));
898918 }
899919
900- ret = ull_adv_sync_start (adv , sync , ticks_anchor_sync );
920+ ret = ull_adv_sync_start (adv , sync , ticks_anchor_sync ,
921+ ticks_slot_overhead );
901922 if (ret ) {
902923 sync_remove (sync , adv , 1U );
903924
@@ -1053,19 +1074,14 @@ uint32_t ull_adv_sync_time_get(const struct ll_adv_sync_set *sync,
10531074 return time_us ;
10541075}
10551076
1056- uint32_t ull_adv_sync_start (struct ll_adv_set * adv ,
1057- struct ll_adv_sync_set * sync ,
1058- uint32_t ticks_anchor )
1077+ uint32_t ull_adv_sync_evt_init (struct ll_adv_set * adv ,
1078+ struct ll_adv_sync_set * sync )
10591079{
10601080 struct lll_adv_sync * lll_sync ;
10611081 uint32_t ticks_slot_overhead ;
10621082 uint32_t ticks_slot_offset ;
1063- uint32_t volatile ret_cb ;
10641083 struct pdu_adv * ter_pdu ;
1065- uint32_t interval_us ;
1066- uint8_t sync_handle ;
10671084 uint32_t time_us ;
1068- uint32_t ret ;
10691085
10701086 ull_hdr_init (& sync -> ull );
10711087
@@ -1090,6 +1106,19 @@ uint32_t ull_adv_sync_start(struct ll_adv_set *adv,
10901106 ticks_slot_overhead = 0U ;
10911107 }
10921108
1109+ return ticks_slot_overhead ;
1110+ }
1111+
1112+ uint32_t ull_adv_sync_start (struct ll_adv_set * adv ,
1113+ struct ll_adv_sync_set * sync ,
1114+ uint32_t ticks_anchor ,
1115+ uint32_t ticks_slot_overhead )
1116+ {
1117+ uint32_t volatile ret_cb ;
1118+ uint32_t interval_us ;
1119+ uint8_t sync_handle ;
1120+ uint32_t ret ;
1121+
10931122 interval_us = (uint32_t )sync -> interval * PERIODIC_INT_UNIT_US ;
10941123
10951124 sync_handle = sync_handle_get (sync );
0 commit comments