Skip to content

Commit f6a3da9

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Review rework of jitter in aux offset
Review rework of the fix to remove the jitter in aux offset and sync offset values. Force select BT_TICKER_REMAINDER_GET and BT_TICKER_LAZY_GET features when Extended Advertising and Periodic Advertising is supported. Rename ticks and microsecond offset value struct members for primary PDU event offset (to auxiliary PDU event). Converted HAL_TICKER_REMOVE_JITTER and HAL_TICKER_ADD_JITTER macro to functions. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent b6cf8bb commit f6a3da9

File tree

7 files changed

+60
-41
lines changed

7 files changed

+60
-41
lines changed

subsys/bluetooth/controller/Kconfig.ll_sw_split

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ config BT_LLL_VENDOR_NORDIC
4343
select BT_CTLR_TIFS_HW_SUPPORT
4444
select BT_CTLR_ULL_LLL_PRIO_SUPPORT
4545

46+
select BT_TICKER_REMAINDER_GET if BT_BROADCASTER && BT_CTLR_ADV_EXT
47+
select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC
48+
4649
default y
4750
help
4851
Use Nordic Lower Link Layer implementation.
@@ -709,15 +712,13 @@ config BT_TICKER_LOW_LAT
709712

710713
config BT_TICKER_REMAINDER_GET
711714
bool "Ticker Next Slot Get with Remainder"
712-
default y if BT_BROADCASTER && BT_CTLR_ADV_EXT
713715
help
714716
This option enables ticker interface to iterate through active
715717
ticker nodes, returning tick to expire and remainder from a reference
716718
tick.
717719

718720
config BT_TICKER_LAZY_GET
719721
bool "Ticker Next Slot Get with Lazy"
720-
default y if BT_CTLR_ADV_PERIODIC
721722
help
722723
This option enables ticker interface to iterate through active
723724
ticker nodes, returning tick to expire and lazy count from a reference

subsys/bluetooth/controller/ll_sw/lll_adv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ struct lll_adv_aux {
130130
/* Store used by primary channel PDU event to fill the
131131
* auxiliary offset to this auxiliary PDU event.
132132
*/
133-
uint32_t ticks_offset;
134-
uint32_t us_offset;
133+
uint32_t ticks_pri_pdu_offset;
134+
uint32_t us_pri_pdu_offset;
135135

136136
struct lll_adv_pdu data;
137137
#if defined(CONFIG_BT_CTLR_ADV_PDU_LINK)

subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ void radio_tmr_tifs_set(uint32_t tifs)
10501050

10511051
uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder)
10521052
{
1053-
HAL_TICKER_REMOVE_JITTER(ticks_start, remainder);
1053+
hal_ticker_remove_jitter(&ticks_start, &remainder);
10541054

10551055
nrf_timer_task_trigger(EVENT_TIMER, NRF_TIMER_TASK_CLEAR);
10561056
EVENT_TIMER->MODE = 0;

subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.h

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#define HAL_TICKER_CNTR_CLK_FREQ_HZ 32768U
9+
#define HAL_TICKER_CNTR_CLK_UNIT_FS 30517578125UL
910

1011
/* Macro defining the minimum counter compare offset */
1112
#define HAL_TICKER_CNTR_CMP_OFFSET_MIN 3
@@ -24,44 +25,28 @@
2425
*/
2526
#define HAL_TICKER_US_TO_TICKS(x) \
2627
( \
27-
((uint32_t)(((uint64_t) (x) * 1000000000UL) / 30517578125UL)) \
28-
& HAL_TICKER_CNTR_MASK \
28+
((uint32_t)(((uint64_t) (x) * 1000000000UL) / \
29+
HAL_TICKER_CNTR_CLK_UNIT_FS)) & HAL_TICKER_CNTR_MASK \
2930
)
3031

31-
/* Macro returning remainder in picoseconds */
32+
/* Macro to translate tick units to microseconds. */
33+
#define HAL_TICKER_TICKS_TO_US(x) \
34+
( \
35+
((uint32_t)(((uint64_t)(x) * HAL_TICKER_CNTR_CLK_UNIT_FS) / \
36+
1000000000UL)) \
37+
)
38+
39+
/* Macro returning remainder in picoseconds (to fit in 32-bits) */
3240
#define HAL_TICKER_REMAINDER(x) \
3341
( \
3442
( \
3543
((uint64_t) (x) * 1000000000UL) \
36-
- ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * 30517578125UL) \
44+
- ((uint64_t)HAL_TICKER_US_TO_TICKS(x) * \
45+
HAL_TICKER_CNTR_CLK_UNIT_FS) \
3746
) \
3847
/ 1000UL \
3948
)
4049

41-
/* Macro to remove ticks and return positive remainder value in microseconds */
42-
#define HAL_TICKER_REMOVE_JITTER(t, r) \
43-
{ \
44-
if ((!(r / 1000000UL)) || (r & BIT(31))) { \
45-
t--; \
46-
r += 30517578UL; \
47-
} \
48-
r /= 1000000UL; \
49-
}
50-
51-
/* Macro to add ticks and return positive remainder value in microseconds */
52-
#define HAL_TICKER_ADD_JITTER(t, r) \
53-
{ \
54-
if ((!(r / 1000000UL)) || (r & BIT(31))) { \
55-
t++; \
56-
r += 30517578UL; \
57-
} \
58-
r /= 1000000UL; \
59-
}
60-
61-
/* Macro to translate tick units to microseconds. */
62-
#define HAL_TICKER_TICKS_TO_US(x) \
63-
((uint32_t)(((uint64_t)(x) * 30517578125UL) / 1000000000UL))
64-
6550
/* Macro defining the remainder resolution/range
6651
* ~ 1000000 * HAL_TICKER_TICKS_TO_US(1)
6752
*/
@@ -71,3 +56,30 @@
7156
/* Macro defining the margin for positioning re-scheduled nodes */
7257
#define HAL_TICKER_RESCHEDULE_MARGIN \
7358
HAL_TICKER_US_TO_TICKS(150)
59+
60+
/* Remove ticks and return positive remainder value in microseconds */
61+
static inline void hal_ticker_remove_jitter(uint32_t *ticks,
62+
uint32_t *remainder)
63+
{
64+
/* Is remainder less than 1 us */
65+
if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) {
66+
*ticks -= 1U;
67+
*remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL;
68+
}
69+
70+
/* pico seconds to micro seconds unit */
71+
*remainder /= 1000000UL;
72+
}
73+
74+
/* Add ticks and return positive remainder value in microseconds */
75+
static inline void hal_ticker_add_jitter(uint32_t *ticks, uint32_t *remainder)
76+
{
77+
/* Is remainder less than 1 us */
78+
if ((*remainder & BIT(31)) || !(*remainder / 1000000UL)) {
79+
*ticks += 1U;
80+
*remainder += HAL_TICKER_CNTR_CLK_UNIT_FS / 1000UL;
81+
}
82+
83+
/* pico seconds to micro seconds unit */
84+
*remainder /= 1000000UL;
85+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,8 @@ static void isr_done(void *param)
13161316
lll_aux = lll->aux;
13171317
if (lll_aux) {
13181318
(void)ull_adv_aux_lll_offset_fill(pdu,
1319-
lll_aux->ticks_offset,
1320-
lll_aux->us_offset,
1319+
lll_aux->ticks_pri_pdu_offset,
1320+
lll_aux->us_pri_pdu_offset,
13211321
start_us);
13221322
}
13231323
#else /* !CONFIG_BT_CTLR_ADV_EXT */

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,24 +1503,24 @@ static void mfy_aux_offset_get(void *param)
15031503
} while (id != ticker_id);
15041504

15051505
/* Adjust ticks to expire based on remainder value */
1506-
HAL_TICKER_REMOVE_JITTER(ticks_to_expire, remainder);
1506+
hal_ticker_remove_jitter(&ticks_to_expire, &remainder);
15071507

15081508
/* Store the ticks offset for population in other advertising primary
15091509
* channel PDUs.
15101510
*/
1511-
lll_aux->ticks_offset = ticks_to_expire;
1511+
lll_aux->ticks_pri_pdu_offset = ticks_to_expire;
15121512

15131513
/* NOTE: as first primary channel PDU does not use remainder, the packet
15141514
* timer is started one tick in advance to start the radio with
15151515
* microsecond precision, hence compensate for the higher start_us value
15161516
* captured at radio start of the first primary channel PDU.
15171517
*/
1518-
lll_aux->ticks_offset += 1U;
1518+
lll_aux->ticks_pri_pdu_offset += 1U;
15191519

15201520
/* Store the microsecond remainder offset for population in other
15211521
* advertising primary channel PDUs.
15221522
*/
1523-
lll_aux->us_offset = remainder;
1523+
lll_aux->us_pri_pdu_offset = remainder;
15241524

15251525
/* Fill the aux offset in the first Primary channel PDU */
15261526
/* FIXME: we are in ULL_LOW context, fill offset in LLL context? */

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,11 +1831,17 @@ static void mfy_sync_offset_get(void *param)
18311831
LL_ASSERT(id != TICKER_NULL);
18321832
} while (id != ticker_id);
18331833

1834-
HAL_TICKER_REMOVE_JITTER(ticks_to_expire, remainder);
1834+
/* Reduced a tick for negative remainder and return positive remainder
1835+
* value.
1836+
*/
1837+
hal_ticker_remove_jitter(&ticks_to_expire, &remainder);
18351838
sync_remainder_us = remainder;
18361839

1840+
/* Add a tick for negative remainder and return positive remainder
1841+
* value.
1842+
*/
18371843
remainder = sync->aux_remainder;
1838-
HAL_TICKER_ADD_JITTER(ticks_to_expire, remainder);
1844+
hal_ticker_add_jitter(&ticks_to_expire, &remainder);
18391845
aux_remainder_us = remainder;
18401846

18411847
pdu = lll_adv_aux_data_latest_peek(adv->lll.aux);

0 commit comments

Comments
 (0)