Skip to content

Commit 1ed9bda

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Schedule BIG event after Periodic Advertising
Add implementation to schedule BIG events after Periodic Advertising when Periodic Advertising is enabled after Extended Advertising has already been enabled. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 2ae86f4 commit 1ed9bda

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

subsys/bluetooth/controller/ll_sw/ull_adv.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,9 @@ uint8_t ll_adv_enable(uint8_t enable)
14761476
* started.
14771477
*/
14781478
if (sync) {
1479+
uint32_t ticks_slot_overhead;
14791480
uint32_t ticks_slot_aux;
1481+
14801482
#if defined(CONFIG_BT_CTLR_ADV_RESERVE_MAX)
14811483
uint32_t us_slot;
14821484

@@ -1509,8 +1511,10 @@ uint8_t ll_adv_enable(uint8_t enable)
15091511
EVENT_OVERHEAD_START_US +
15101512
(EVENT_TICKER_RES_MARGIN_US << 1));
15111513

1514+
ticks_slot_overhead = ull_adv_sync_evt_init(adv, sync);
15121515
ret = ull_adv_sync_start(adv, sync,
1513-
ticks_anchor_sync);
1516+
ticks_anchor_sync,
1517+
ticks_slot_overhead);
15141518
if (ret) {
15151519
goto failure_cleanup;
15161520
}

subsys/bluetooth/controller/ll_sw/ull_adv_internal.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,15 @@ void ull_adv_sync_release(struct ll_adv_sync_set *sync);
229229
uint32_t ull_adv_sync_time_get(const struct ll_adv_sync_set *sync,
230230
uint8_t pdu_len);
231231

232+
/* helper function to calculate ticks_slot and return slot overhead */
233+
uint32_t ull_adv_sync_evt_init(struct ll_adv_set *adv,
234+
struct ll_adv_sync_set *sync);
235+
232236
/* helper function to start periodic advertising */
233237
uint32_t ull_adv_sync_start(struct ll_adv_set *adv,
234238
struct ll_adv_sync_set *sync,
235-
uint32_t ticks_anchor);
239+
uint32_t ticks_anchor,
240+
uint32_t ticks_slot_overhead);
236241

237242
/* helper function to update periodic advertising event time reservation */
238243
uint8_t ull_adv_sync_time_update(struct ll_adv_sync_set *sync,

subsys/bluetooth/controller/ll_sw/ull_adv_iso.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso,
939939
ticks_slot = adv_iso->ull.ticks_slot + ticks_slot_overhead;
940940

941941
/* Find the slot after Periodic Advertisings events */
942+
ticks_anchor = ticker_ticks_now_get() +
943+
HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US);
942944
err = ull_sched_adv_aux_sync_free_slot_get(TICKER_USER_ID_THREAD,
943945
ticks_slot, &ticks_anchor);
944946
if (!err) {
@@ -947,9 +949,6 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso,
947949
EVENT_OVERHEAD_START_US) -
948950
EVENT_OVERHEAD_START_US +
949951
(EVENT_TICKER_RES_MARGIN_US << 1));
950-
} else {
951-
ticks_anchor = ticker_ticks_now_get() +
952-
HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US);
953952
}
954953

955954
/* setup to use ISO create prepare function for first radio event */

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
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);

subsys/bluetooth/controller/ll_sw/ull_sched.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,28 @@ int ull_sched_adv_aux_sync_free_slot_get(uint8_t user_id,
9595

9696
} else if (IN_RANGE(ticker_id, TICKER_ID_ADV_AUX_BASE,
9797
TICKER_ID_ADV_AUX_LAST)) {
98+
const struct ll_adv_aux_set *aux;
99+
98100
*ticks_anchor += ticks_to_expire;
99101
*ticks_anchor += ticks_slot;
100102

101-
if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) {
102-
const struct ll_adv_aux_set *aux;
103+
aux = ull_adv_aux_get(ticker_id -
104+
TICKER_ID_ADV_AUX_BASE);
105+
106+
#if defined(CONFIG_BT_CTLR_ADV_PERIODIC)
107+
if (aux->lll.adv->sync) {
108+
const struct ll_adv_sync_set *sync;
103109

104-
aux = ull_adv_aux_get(ticker_id -
105-
TICKER_ID_ADV_AUX_BASE);
110+
sync = HDR_LLL2ULL(aux->lll.adv->sync);
111+
if (sync->is_started) {
112+
*ticks_anchor += sync->ull.ticks_slot;
113+
*ticks_anchor += HAL_TICKER_US_TO_TICKS(
114+
EVENT_TICKER_RES_MARGIN_US << 1);
115+
}
116+
}
117+
#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
118+
119+
if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) {
106120
*ticks_anchor +=
107121
MAX(aux->ull.ticks_active_to_start,
108122
aux->ull.ticks_prepare_to_start);

0 commit comments

Comments
 (0)