Bluetooth: Controller: Fix PAST sync_offset_us calculation

Fix the missing use of remainder value in the sync_offset_us
calculations. Also, Periodic Sync reception is relative to
Peripheral event hence ticks_anchor does not require the
ticker margin and event jitter to be subtracted.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada
2025-11-19 23:25:50 +01:00
committed by Fabio Baltieri
parent 40d79b1f64
commit 0b1b099196
5 changed files with 24 additions and 24 deletions

View File

@@ -2849,7 +2849,7 @@ static void ticker_get_offset_op_cb(uint32_t status, void *param)
*((uint32_t volatile *)param) = status;
}
static uint32_t get_ticker_offset(uint8_t ticker_id, uint16_t *lazy)
static uint32_t get_ticker_offset(const struct ll_conn *conn, uint8_t ticker_id, uint16_t *lazy)
{
uint32_t volatile ret_cb;
uint32_t ticks_to_expire;
@@ -2888,6 +2888,7 @@ static uint32_t get_ticker_offset(uint8_t ticker_id, uint16_t *lazy)
/* Add a tick for negative remainder and return positive remainder
* value.
*/
remainder = conn->llcp.prep.remainder;
hal_ticker_add_jitter(&ticks_to_expire, &remainder);
start_us = remainder;
@@ -2921,7 +2922,8 @@ static void mfy_past_sender_offset_get(void *param)
LL_ASSERT_DBG(adv_sync);
ticker_offset_us = get_ticker_offset(TICKER_ID_ADV_SYNC_BASE + adv_sync_handle,
ticker_offset_us = get_ticker_offset(conn,
(TICKER_ID_ADV_SYNC_BASE + adv_sync_handle),
&lazy);
pa_event_counter = adv_sync->lll.event_counter;
@@ -2933,7 +2935,8 @@ static void mfy_past_sender_offset_get(void *param)
LL_ASSERT_DBG(sync);
ticker_offset_us = get_ticker_offset(TICKER_ID_SCAN_SYNC_BASE + sync_handle,
ticker_offset_us = get_ticker_offset(conn,
(TICKER_ID_SCAN_SYNC_BASE + sync_handle),
&lazy);
if (lazy && ticker_offset_us > interval_us) {

View File

@@ -1552,20 +1552,19 @@ void ull_lp_past_offset_calc_reply(struct ll_conn *conn, uint32_t offset_us,
/* Update offset_us */
offset_us = offset_us - (conn_event_offset * conn_interval_us);
ctx->data.periodic_sync.conn_event_count = ull_conn_event_counter(conn) +
conn_event_offset;
}
llcp_pdu_fill_sync_info_offset(&ctx->data.periodic_sync.sync_info, offset_us);
#if defined(CONFIG_BT_PERIPHERAL)
/* Save the result for later use */
ctx->data.periodic_sync.offset_us = offset_us;
#endif /* CONFIG_BT_PERIPHERAL */
ctx->data.periodic_sync.sync_conn_event_count = ull_conn_event_counter(conn);
ctx->data.periodic_sync.conn_event_count = ull_conn_event_counter(conn) +
conn_event_offset;
ctx->data.periodic_sync.sync_conn_event_count =
ull_conn_event_counter_at_prepare(conn) - 1U;
ctx->data.periodic_sync.conn_event_count =
ull_conn_event_counter_at_prepare(conn) + conn_event_offset - 1U;
ctx->data.periodic_sync.sync_info.evt_cntr = pa_event_counter;

View File

@@ -274,6 +274,8 @@ void ull_sync_setup_from_sync_transfer(struct ll_conn *conn, uint16_t service_da
if (sync->skip > skip_max) {
sync->skip = skip_max;
}
} else {
sync->skip = 0U;
}
sync->sync_expire = CONN_ESTAB_COUNTDOWN;
@@ -321,14 +323,9 @@ void ull_sync_setup_from_sync_transfer(struct ll_conn *conn, uint16_t service_da
conn_interval_us = conn->lll.interval * CONN_INT_UNIT_US;
/* Calculate offset and schedule sync radio events */
ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy, PHY_FLAGS_S8);
sync_offset_us = PDU_ADV_SYNC_INFO_OFFSET_GET(si) * lll->window_size_event_us;
/* offs_adjust may be 1 only if sync setup by LL_PERIODIC_SYNC_IND */
sync_offset_us += (PDU_ADV_SYNC_INFO_OFFS_ADJUST_GET(si) ? OFFS_ADJUST_US : 0U);
sync_offset_us -= EVENT_TICKER_RES_MARGIN_US;
sync_offset_us -= EVENT_JITTER_US;
sync_offset_us -= ready_delay_us;
if (conn_evt_offset) {
int64_t conn_offset_us = (int64_t)conn_evt_offset * conn_interval_us;
@@ -386,6 +383,7 @@ void ull_sync_setup_from_sync_transfer(struct ll_conn *conn, uint16_t service_da
/* Calculate event time reservation */
slot_us = PDU_AC_MAX_US(PDU_AC_EXT_PAYLOAD_RX_SIZE, lll->phy);
ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy, PHY_FLAGS_S8);
slot_us += ready_delay_us;
/* Add implementation defined radio event overheads */
@@ -410,7 +408,7 @@ void ull_sync_setup_from_sync_transfer(struct ll_conn *conn, uint16_t service_da
#if defined(CONFIG_BT_PERIPHERAL)
if (conn->lll.role == BT_HCI_ROLE_PERIPHERAL) {
/* Compensate for window widening */
ticks_anchor += HAL_TICKER_US_TO_TICKS(conn->lll.periph.window_widening_event_us);
sync_offset_us += conn->lll.periph.window_widening_event_us;
}
#endif /* CONFIG_BT_PERIPHERAL */

View File

@@ -147,14 +147,14 @@ ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_loc)
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x00,
.conn_event_count = 0xFFFFU,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
.sync_conn_event_count = 0xFFFFU,
};
/* Reset and setup mayfly_enqueue_custom_fake */
@@ -346,26 +346,26 @@ ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_rem_2)
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x01,
.conn_event_count = 0x0000U,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0x01
.sync_conn_event_count = 0x0000U,
};
struct pdu_data_llctrl_periodic_sync_ind remote_periodic_sync_ind = {
.id = 0x01,
.conn_event_count = 0x00,
.conn_event_count = 0x0000U,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x01,
.sca = 0x00,
.phy = 0x01,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
.sync_conn_event_count = 0x0000U,
};
/* Reset and setup fake functions */
@@ -481,14 +481,14 @@ ZTEST(periodic_sync_transfer, test_periodic_sync_transfer_loc_twice)
struct pdu_data_llctrl_periodic_sync_ind local_periodic_sync_ind = {
.id = 0x00,
.conn_event_count = 0x00,
.conn_event_count = 0xFFFFU,
.last_pa_event_counter = 0x00,
.sid = 0x00,
.addr_type = 0x00,
.sca = 0x00,
.phy = 0x00,
.adv_addr = { 0, 0, 0, 0, 0, 0},
.sync_conn_event_count = 0
.sync_conn_event_count = 0xFFFFU,
};
/* Reset and setup mayfly_enqueue_custom_fake */

View File

@@ -25,7 +25,7 @@ Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_prj_conf \
-v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=bass_broadcaster \
-RealEncryption=1 -rs=79 -D=3 -start_offset=6e3
-RealEncryption=1 -rs=69 -D=3
# Simulation time should be larger than the WAIT_TIME in common.h
Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -D=3 \