Skip to content

Commit 98161bd

Browse files
mtpr-otcarlescufi
authored andcommitted
Bluetooth: controller: Enable CIS establishment in same ACL instant
If CIS offset in LL_CIS_IND is less than EVENT_OVERHEAD_START_US, the controller is not able to establish the CIS in the ACL connection event specified, but needs to start setup one connection event earlier. With this commit, if offset is larger than EVENT_OVERHEAD_START_US the first CIS event can be prepared in due time immediately. This enables the controller to setup first CIS, even when instant is equal to the ACL event_counter. Signed-off-by: Morten Priess <[email protected]>
1 parent 220170a commit 98161bd

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

subsys/bluetooth/controller/ll_sw/isoal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ isoal_status_t isoal_reset(void)
113113
* @param time_diff Time difference (signed)
114114
* @return Wrapped time after difference
115115
*/
116-
static uint32_t isoal_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
116+
uint32_t isoal_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us)
117117
{
118118
LL_ASSERT(time_now_us <= ISOAL_TIME_WRAPPING_POINT_US);
119119

subsys/bluetooth/controller/ll_sw/isoal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ struct isoal_source {
419419
uint64_t context_active:1;
420420
};
421421

422+
uint32_t isoal_get_wrapped_time_us(uint32_t time_now_us, int32_t time_diff_us);
423+
422424
isoal_status_t isoal_init(void);
423425

424426
isoal_status_t isoal_reset(void);

subsys/bluetooth/controller/ll_sw/ull_conn_iso.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -844,17 +844,25 @@ void ull_conn_iso_start(struct ll_conn *conn, uint32_t ticks_at_expire,
844844
ticks_remainder = EVENT_US_FRAC_TO_REMAINDER(iso_interval_us_frac);
845845

846846
#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START)
847-
if (instant_latency == 0U) {
848-
/* Adjust CIG offset and reference point ahead one
849-
* interval
850-
*/
851-
cig_offset_us += conn->lll.interval * CONN_INT_UNIT_US;
852-
cig->cig_ref_point += conn->lll.interval *
853-
CONN_INT_UNIT_US;
847+
bool early_start = (cis->offset < EVENT_OVERHEAD_START_US);
848+
849+
if (early_start) {
850+
if (instant_latency == 0U) {
851+
/* Adjust CIG offset and reference point ahead one
852+
* interval
853+
*/
854+
cig_offset_us += (conn->lll.interval * CONN_INT_UNIT_US);
855+
cig->cig_ref_point = isoal_get_wrapped_time_us(cig->cig_ref_point,
856+
conn->lll.interval * CONN_INT_UNIT_US);
857+
} else {
858+
LL_ASSERT(instant_latency == 1U);
859+
}
854860
} else {
855-
LL_ASSERT(instant_latency == 1U);
861+
/* FIXME: Handle latency due to skipped ACL events around the
862+
* instant to start CIG
863+
*/
864+
LL_ASSERT(instant_latency == 0U);
856865
}
857-
858866
#else /* CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START */
859867
/* FIXME: Handle latency due to skipped ACL events around the
860868
* instant to start CIG

subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ static void rp_cc_state_wait_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *c
404404
case RP_CC_EVT_CIS_IND:
405405
llcp_pdu_decode_cis_ind(ctx, pdu);
406406
if (!ull_peripheral_iso_setup(&pdu->llctrl.cis_ind, ctx->data.cis_create.cig_id,
407-
ctx->data.cis_create.cis_handle)) {
407+
ctx->data.cis_create.cis_handle,
408+
&ctx->data.cis_create.conn_event_count)) {
408409

409410
/* CIS has been setup, go wait for 'instant' before starting */
410411
ctx->state = RP_CC_STATE_WAIT_INSTANT;
@@ -456,29 +457,14 @@ static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint
456457
void *param)
457458
{
458459
uint16_t start_event_count;
459-
uint16_t instant_latency;
460460
uint16_t event_counter;
461461

462462
event_counter = ull_conn_event_counter(conn);
463463
start_event_count = ctx->data.cis_create.conn_event_count;
464464

465-
#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START)
466-
struct ll_conn_iso_group *cig;
467-
468-
cig = ll_conn_iso_group_get_by_id(ctx->data.cis_create.cig_id);
469-
LL_ASSERT(cig);
470-
471-
if (!cig->started) {
472-
/* Start ISO peripheral one event before the requested instant
473-
* for first CIS. This is done to be able to accept small CIS
474-
* offsets.
475-
*/
476-
start_event_count--;
477-
}
478-
#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START */
465+
if (is_instant_reached_or_passed(start_event_count, event_counter)) {
466+
uint16_t instant_latency = (event_counter - start_event_count) & 0xffff;
479467

480-
instant_latency = (event_counter - start_event_count) & 0xffff;
481-
if (instant_latency <= 0x7fff) {
482468
/* Start CIS */
483469
ull_conn_iso_start(conn, conn->llcp.prep.ticks_at_expire,
484470
ctx->data.cis_create.cis_handle,

subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,12 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl,
286286
}
287287

288288
uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind,
289-
uint8_t cig_id, uint16_t cis_handle)
289+
uint8_t cig_id, uint16_t cis_handle,
290+
uint16_t *conn_event_count)
290291
{
291292
struct ll_conn_iso_stream *cis = NULL;
292293
struct ll_conn_iso_group *cig;
294+
uint32_t cis_offset;
293295

294296
/* Get CIG by id */
295297
cig = ll_conn_iso_group_get_by_id(cig_id);
@@ -305,8 +307,22 @@ uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind,
305307
return BT_HCI_ERR_UNSPECIFIED;
306308
}
307309

310+
cis_offset = sys_get_le24(ind->cis_offset);
311+
312+
#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START)
313+
if (!cig->started) {
314+
/* This is the first CIS. Make sure we can make the anchorpoint, otherwise
315+
* we need to move up the instant up by one connection interval.
316+
*/
317+
if (cis_offset < EVENT_OVERHEAD_START_US) {
318+
/* Start one connection event earlier */
319+
(*conn_event_count)--;
320+
}
321+
}
322+
#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START */
323+
308324
cis->sync_delay = sys_get_le24(ind->cis_sync_delay);
309-
cis->offset = sys_get_le24(ind->cis_offset);
325+
cis->offset = cis_offset;
310326
memcpy(cis->lll.access_addr, ind->aa, sizeof(ind->aa));
311327
cis->lll.event_count = -1;
312328
cis->lll.next_subevent = 0U;

subsys/bluetooth/controller/ll_sw/ull_peripheral_iso_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl,
1414
uint16_t *cis_handle);
1515
uint8_t ull_peripheral_iso_setup(struct pdu_data_llctrl_cis_ind *ind,
1616
uint8_t cig_id,
17-
uint16_t cis_handle);
17+
uint16_t cis_handle,
18+
uint16_t *conn_event_count);
1819
void ull_peripheral_iso_update_peer_sca(struct ll_conn *acl);
1920
void ull_peripheral_iso_update_ticker(struct ll_conn_iso_group *cig,
2021
uint32_t ticks_at_expire,

0 commit comments

Comments
 (0)