Skip to content

Commit

Permalink
Bluetooth: Controller: Fix Connected ISO for aborted prepare
Browse files Browse the repository at this point in the history
Fix Connected ISO implementation to correctly handle SN,
NESN and payload_count when prepare callback is aborted due
to CPU overhead related latencies.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
  • Loading branch information
cvinayak committed Jun 28, 2023
1 parent 36e6b1b commit 0810824
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
26 changes: 24 additions & 2 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static int prepare_cb(struct lll_prepare_param *p)
uint16_t lazy;
uint32_t ret;
uint8_t phy;
int err = 0;

DEBUG_RADIO_START_M(1);

Expand Down Expand Up @@ -384,10 +385,11 @@ static int prepare_cb(struct lll_prepare_param *p)
if (overhead) {
LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u",
__func__, HAL_TICKER_TICKS_TO_US(overhead));
radio_isr_set(lll_isr_abort, cig_lll);

radio_isr_set(isr_done, cis_lll);
radio_disable();

return -ECANCELED;
err = -ECANCELED;
}
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */

Expand All @@ -408,10 +410,30 @@ static int prepare_cb(struct lll_prepare_param *p)
/* sn and nesn are 1-bit, only Least Significant bit is needed */
cis_lll->sn += cis_lll->tx.bn * cis_lazy;
cis_lll->nesn += cis_lll->rx.bn * cis_lazy;

/* Adjust sn and nesn for canceled events */
if (err) {
/* Adjust sn when flushing Tx */
/* FIXME: When Flush Timeout is implemented */
if (cis_lll->tx.bn_curr <= cis_lll->tx.bn) {
lll_flush_tx(cis_lll);
}

/* Adjust nesn when flushing Rx */
/* FIXME: When Flush Timeout is implemented */
if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) {
lll_flush_rx(cis_lll);
}
}
}
}
} while (cis_lll);

/* Return if prepare callback cancelled */
if (err) {
return err;
}

/* Prepare is done */
ret = lll_prepare_done(cig_lll);
LL_ASSERT(!ret);
Expand Down
20 changes: 18 additions & 2 deletions subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ static int prepare_cb(struct lll_prepare_param *p)
uint16_t lazy;
uint32_t ret;
uint8_t phy;
int err = 0;

DEBUG_RADIO_START_S(1);

Expand Down Expand Up @@ -361,10 +362,11 @@ static int prepare_cb(struct lll_prepare_param *p)
if (overhead) {
LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u",
__func__, HAL_TICKER_TICKS_TO_US(overhead));
radio_isr_set(lll_isr_abort, cig_lll);

radio_isr_set(isr_done, cis_lll);
radio_disable();

return -ECANCELED;
err = -ECANCELED;
}
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */

Expand Down Expand Up @@ -400,9 +402,23 @@ static int prepare_cb(struct lll_prepare_param *p)
/* sn and nesn are 1-bit, only Least Significant bit is needed */
cis_lll->sn += cis_lll->tx.bn * lazy;
cis_lll->nesn += cis_lll->rx.bn * lazy;

/* Adjust sn and nesn for canceled events */
if (err) {
/* Adjust nesn when flushing Rx */
/* FIXME: When Flush Timeout is implemented */
if (cis_lll->rx.bn_curr <= cis_lll->rx.bn) {
lll_flush_rx(cis_lll);
}
}
}
};

/* Return if prepare callback cancelled */
if (err) {
return err;
}

/* Prepare is done */
ret = lll_prepare_done(cig_lll);
LL_ASSERT(!ret);
Expand Down

0 comments on commit 0810824

Please sign in to comment.