Skip to content

Commit b6cf8bb

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Use remainder in Ext and Periodic PDU offset
Use remainder value in scheduling the periodic auxiliary PDUs and use the ticker next slot get interface with remainder value to fill the auxiliary offsets with microsecond precision in the primary channel PDUs. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent aa73661 commit b6cf8bb

File tree

6 files changed

+51
-29
lines changed

6 files changed

+51
-29
lines changed

subsys/bluetooth/controller/ll_sw/lll_adv.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ struct lll_adv_sync {
9898
uint8_t chm_last;
9999
uint16_t chm_instant;
100100

101-
uint32_t ticks_offset;
102-
103101
struct lll_adv_pdu data;
104102

105103
#if defined(CONFIG_BT_CTLR_ADV_PDU_LINK)
@@ -129,10 +127,11 @@ struct lll_adv_aux {
129127
*/
130128
uint16_t data_chan_counter;
131129

132-
/* Temporary stored use by primary channel PDU event to fill the
130+
/* Store used by primary channel PDU event to fill the
133131
* auxiliary offset to this auxiliary PDU event.
134132
*/
135133
uint32_t ticks_offset;
134+
uint32_t us_offset;
136135

137136
struct lll_adv_pdu data;
138137
#if defined(CONFIG_BT_CTLR_ADV_PDU_LINK)

subsys/bluetooth/controller/ll_sw/lll_adv_aux.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ void lll_adv_aux_prepare(void *param);
1010

1111
extern uint8_t ull_adv_aux_lll_handle_get(struct lll_adv_aux *lll);
1212
extern struct pdu_adv_aux_ptr *
13-
ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu,
14-
uint32_t ticks_offset,
15-
uint32_t start_us);
13+
ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu, uint32_t ticks_offset,
14+
uint32_t remainder_us, uint32_t start_us);

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ static void isr_done(void *param)
13171317
if (lll_aux) {
13181318
(void)ull_adv_aux_lll_offset_fill(pdu,
13191319
lll_aux->ticks_offset,
1320+
lll_aux->us_offset,
13201321
start_us);
13211322
}
13221323
#else /* !CONFIG_BT_CTLR_ADV_EXT */

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor,
11181118
(TICKER_ID_ADV_AUX_BASE + aux_handle),
11191119
ticks_anchor, 0U,
11201120
HAL_TICKER_US_TO_TICKS(interval_us),
1121-
TICKER_NULL_REMAINDER, TICKER_NULL_LAZY,
1121+
HAL_TICKER_REMAINDER(interval_us), TICKER_NULL_LAZY,
11221122
(aux->ull.ticks_slot + ticks_slot_overhead),
11231123
ticker_cb, aux,
11241124
ull_ticker_status_give, (void *)&ret_cb);
@@ -1272,6 +1272,7 @@ void ull_adv_aux_offset_get(struct ll_adv_set *adv)
12721272

12731273
struct pdu_adv_aux_ptr *ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu,
12741274
uint32_t ticks_offset,
1275+
uint32_t remainder_us,
12751276
uint32_t start_us)
12761277
{
12771278
struct pdu_adv_com_ext_adv *pri_com_hdr;
@@ -1302,7 +1303,7 @@ struct pdu_adv_aux_ptr *ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu,
13021303
}
13031304

13041305
aux_ptr = (void *)ptr;
1305-
offs = HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us;
1306+
offs = HAL_TICKER_TICKS_TO_US(ticks_offset) + remainder_us - start_us;
13061307
offs = offs / OFFS_UNIT_30_US;
13071308
if (!!(offs >> OFFS_UNIT_BITS)) {
13081309
aux_ptr->offs = offs / (OFFS_UNIT_300_US / OFFS_UNIT_30_US);
@@ -1457,6 +1458,7 @@ static void mfy_aux_offset_get(void *param)
14571458
uint32_t ticks_current;
14581459
struct ll_adv_set *adv;
14591460
struct pdu_adv *pdu;
1461+
uint32_t remainder;
14601462
uint8_t ticker_id;
14611463
uint8_t retry;
14621464
uint8_t id;
@@ -1479,11 +1481,12 @@ static void mfy_aux_offset_get(void *param)
14791481
ticks_previous = ticks_current;
14801482

14811483
ret_cb = TICKER_STATUS_BUSY;
1482-
ret = ticker_next_slot_get(TICKER_INSTANCE_ID_CTLR,
1483-
TICKER_USER_ID_ULL_LOW,
1484-
&id,
1485-
&ticks_current, &ticks_to_expire,
1486-
ticker_op_cb, (void *)&ret_cb);
1484+
ret = ticker_next_slot_get_ext(TICKER_INSTANCE_ID_CTLR,
1485+
TICKER_USER_ID_ULL_LOW,
1486+
&id, &ticks_current,
1487+
&ticks_to_expire, &remainder,
1488+
NULL, NULL, NULL,
1489+
ticker_op_cb, (void *)&ret_cb);
14871490
if (ret == TICKER_STATUS_BUSY) {
14881491
while (ret_cb == TICKER_STATUS_BUSY) {
14891492
ticker_job_sched(TICKER_INSTANCE_ID_CTLR,
@@ -1499,22 +1502,31 @@ static void mfy_aux_offset_get(void *param)
14991502
LL_ASSERT(id != TICKER_NULL);
15001503
} while (id != ticker_id);
15011504

1505+
/* Adjust ticks to expire based on remainder value */
1506+
HAL_TICKER_REMOVE_JITTER(ticks_to_expire, remainder);
1507+
15021508
/* Store the ticks offset for population in other advertising primary
15031509
* channel PDUs.
15041510
*/
1505-
lll_aux->ticks_offset = ticks_to_expire;
1511+
lll_aux->ticks_offset = ticks_to_expire;
1512+
1513+
/* NOTE: as first primary channel PDU does not use remainder, the packet
1514+
* timer is started one tick in advance to start the radio with
1515+
* microsecond precision, hence compensate for the higher start_us value
1516+
* captured at radio start of the first primary channel PDU.
1517+
*/
1518+
lll_aux->ticks_offset += 1U;
15061519

1507-
/* NOTE: as remainder used in scheduling primary PDU not available,
1508-
* compensate with a probable jitter of one ticker resolution unit that
1509-
* would be included in the packet timer capture when scheduling next
1510-
* advertising primary channel PDU.
1520+
/* Store the microsecond remainder offset for population in other
1521+
* advertising primary channel PDUs.
15111522
*/
1512-
lll_aux->ticks_offset +=
1513-
HAL_TICKER_US_TO_TICKS(EVENT_TICKER_RES_MARGIN_US);
1523+
lll_aux->us_offset = remainder;
15141524

1525+
/* Fill the aux offset in the first Primary channel PDU */
15151526
/* FIXME: we are in ULL_LOW context, fill offset in LLL context? */
15161527
pdu = lll_adv_data_latest_peek(&adv->lll);
1517-
aux_ptr = ull_adv_aux_lll_offset_fill(pdu, ticks_to_expire, 0);
1528+
aux_ptr = ull_adv_aux_lll_offset_fill(pdu, ticks_to_expire, remainder,
1529+
0U);
15181530

15191531
/* Process channel map update, if any */
15201532
if (aux->chm_first != aux->chm_last) {
@@ -1572,6 +1584,7 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
15721584

15731585
sync = HDR_LLL2ULL(adv->lll.sync);
15741586
if (sync->is_started) {
1587+
sync->aux_remainder = remainder;
15751588
ull_adv_sync_offset_get(adv);
15761589
}
15771590
}

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static void mfy_sync_offset_get(void *param);
6060
static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu);
6161
static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si,
6262
uint32_t ticks_offset,
63+
uint32_t remainder_us,
6364
uint32_t start_us);
6465
static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
6566
uint32_t remainder, uint16_t lazy, uint8_t force,
@@ -1780,9 +1781,12 @@ static void mfy_sync_offset_get(void *param)
17801781
struct lll_adv_sync *lll_sync;
17811782
struct ll_adv_sync_set *sync;
17821783
struct pdu_adv_sync_info *si;
1784+
uint32_t sync_remainder_us;
1785+
uint32_t aux_remainder_us;
17831786
uint32_t ticks_to_expire;
17841787
uint32_t ticks_current;
17851788
struct pdu_adv *pdu;
1789+
uint32_t remainder;
17861790
uint8_t chm_first;
17871791
uint8_t ticker_id;
17881792
uint16_t lazy;
@@ -1809,8 +1813,8 @@ static void mfy_sync_offset_get(void *param)
18091813
ret = ticker_next_slot_get_ext(TICKER_INSTANCE_ID_CTLR,
18101814
TICKER_USER_ID_ULL_LOW,
18111815
&id, &ticks_current,
1812-
&ticks_to_expire, NULL, &lazy,
1813-
NULL, NULL,
1816+
&ticks_to_expire, &remainder,
1817+
&lazy, NULL, NULL,
18141818
ticker_op_cb, (void *)&ret_cb);
18151819
if (ret == TICKER_STATUS_BUSY) {
18161820
while (ret_cb == TICKER_STATUS_BUSY) {
@@ -1827,14 +1831,17 @@ static void mfy_sync_offset_get(void *param)
18271831
LL_ASSERT(id != TICKER_NULL);
18281832
} while (id != ticker_id);
18291833

1830-
/* NOTE: as remainder not used in scheduling primary PDU
1831-
* packet timer starts transmission after 1 tick hence the +1.
1832-
*/
1833-
lll_sync->ticks_offset = ticks_to_expire + 1;
1834+
HAL_TICKER_REMOVE_JITTER(ticks_to_expire, remainder);
1835+
sync_remainder_us = remainder;
1836+
1837+
remainder = sync->aux_remainder;
1838+
HAL_TICKER_ADD_JITTER(ticks_to_expire, remainder);
1839+
aux_remainder_us = remainder;
18341840

18351841
pdu = lll_adv_aux_data_latest_peek(adv->lll.aux);
18361842
si = sync_info_get(pdu);
1837-
sync_info_offset_fill(si, ticks_to_expire, 0);
1843+
sync_info_offset_fill(si, ticks_to_expire, sync_remainder_us,
1844+
aux_remainder_us);
18381845
si->evt_cntr = lll_sync->event_counter + lll_sync->latency_prepare +
18391846
lazy;
18401847

@@ -1900,11 +1907,12 @@ static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu)
19001907

19011908
static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si,
19021909
uint32_t ticks_offset,
1910+
uint32_t remainder_us,
19031911
uint32_t start_us)
19041912
{
19051913
uint32_t offs;
19061914

1907-
offs = HAL_TICKER_TICKS_TO_US(ticks_offset) - start_us;
1915+
offs = HAL_TICKER_TICKS_TO_US(ticks_offset) + remainder_us - start_us;
19081916

19091917
if (offs >= OFFS_ADJUST_US) {
19101918
offs -= OFFS_ADJUST_US;

subsys/bluetooth/controller/ll_sw/ull_adv_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ struct ll_adv_sync_set {
9090
uint8_t is_enabled:1;
9191
uint8_t is_started:1;
9292
uint8_t is_data_cmplt:1;
93+
94+
uint32_t aux_remainder;
9395
};
9496

9597
struct ll_adv_iso_set {

0 commit comments

Comments
 (0)