From e7a90f9df1301b19027094c468c5425cff01771f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 22 Jun 2023 22:36:05 +0530 Subject: [PATCH] Bluetooth: Controller: Fix ISO Data timestamp when FT > 1 Fix ISO data timestamp to reflect the SDU reference point and not the ISO event anchor point when PDUs received after retransmissions. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/lll_conn_iso.h | 3 +++ .../controller/ll_sw/nordic/lll/lll_central_iso.c | 7 ++++++- .../controller/ll_sw/nordic/lll/lll_peripheral_iso.c | 5 +++++ subsys/bluetooth/controller/ll_sw/ull_central_iso.c | 1 + subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h index 1372cfee9b96aff..cebf79a3a4454b5 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn_iso.h @@ -71,6 +71,9 @@ struct lll_conn_iso_group { uint8_t role:1; /* 0: CENTRAL, 1: PERIPHERAL*/ uint8_t paused:1; /* 1: CIG is paused */ + /* ISO interval to calculate timestamp under FT > 1 */ + uint32_t iso_interval_us; + /* Accumulates LLL prepare callback latencies */ uint16_t latency_prepare; uint16_t latency_event; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 324225773a7aae2..11161f903b92834 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -733,6 +733,7 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { + struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -770,6 +771,10 @@ static void isr_rx(void *param) iso_meta->timestamp = HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_ready_restore(); + cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); + iso_meta->timestamp -= (cis_lll->event_count - + (cis_lll->rx.payload_count / cis_lll->rx.bn)) * + cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; @@ -827,8 +832,8 @@ static void isr_rx(void *param) isr_rx_next_subevent: if (cie || (se_curr == cis_lll->nse)) { - struct lll_conn_iso_stream *old_cis_lll; struct lll_conn_iso_stream *next_cis_lll; + struct lll_conn_iso_stream *old_cis_lll; struct lll_conn_iso_group *cig_lll; struct lll_conn *next_conn_lll; uint8_t phy; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index fc00fb32fedd1d4..b69f10e93bc05dc 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -550,6 +550,7 @@ static void isr_rx(void *param) (cis_lll->rx.bn_curr <= cis_lll->rx.bn) && (pdu_rx->sn == cis_lll->nesn) && ull_iso_pdu_rx_alloc_peek(2U)) { + struct lll_conn_iso_group *cig_lll; struct node_rx_iso_meta *iso_meta; cis_lll->nesn++; @@ -589,6 +590,10 @@ static void isr_rx(void *param) HAL_TICKER_TICKS_TO_US(radio_tmr_start_get()) + radio_tmr_aa_restore() - addr_us_get(cis_lll->rx.phy); + cig_lll = ull_conn_iso_lll_group_get_by_stream(cis_lll); + iso_meta->timestamp -= (cis_lll->event_count - + (cis_lll->rx.payload_count / cis_lll->rx.bn)) * + cig_lll->iso_interval_us; iso_meta->timestamp %= HAL_TICKER_TICKS_TO_US(BIT(HAL_TICKER_CNTR_MSBIT + 1U)); iso_meta->status = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 58a05923e074885..48a1486e390a9b6 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -221,6 +221,7 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id, uint16_t *handles) } iso_interval_us = cig->iso_interval * ISO_INT_UNIT_US; + cig->lll.iso_interval_us = iso_interval_us; lll_hdr_init(&cig->lll, cig); max_se_length = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index c7fc3a691b3f33f..72bbf23578e10a9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -188,6 +188,7 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cig->iso_interval = sys_le16_to_cpu(req->iso_interval); iso_interval_us = cig->iso_interval * CONN_INT_UNIT_US; + cig->lll.iso_interval_us = iso_interval_us; cig->cig_id = req->cig_id; cig->lll.handle = LLL_HANDLE_INVALID;