Skip to content

Commit cadef5a

Browse files
cvinayakfabiobaltieri
authored andcommitted
Bluetooth: Controller: Introduce BT_CTLR_PERIPHERAL_RESERVE_MAX
Introduce BT_CTLR_PERIPHERAL_RESERVE_MAX Kconfig option so that disabling this option will use minimum time reservation and exercise the peripheral connection event continuation using is_abort_cb mechanism. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent c344cca commit cadef5a

File tree

10 files changed

+98
-5
lines changed

10 files changed

+98
-5
lines changed

samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ CONFIG_BT_CTLR_SCAN_AUX_SET=1
7272

7373
CONFIG_BT_CTLR_ADV_RESERVE_MAX=n
7474
CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n
75+
CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX=n
76+
CONFIG_BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX=y
7577
CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE=n
7678
CONFIG_BT_CTLR_SCAN_UNRESERVED=y
7779
CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y

subsys/bluetooth/controller/Kconfig.ll_sw_split

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,19 @@ config BT_CTLR_CENTRAL_RESERVE_MAX
754754
Note, currently this value is only used to space multiple central
755755
connections and not for actual ticker time reservations.
756756

757+
config BT_CTLR_PERIPHERAL_RESERVE_MAX
758+
bool "Use maximum data PDU size time reservation for Peripheral"
759+
depends on BT_PERIPHERAL
760+
default y
761+
help
762+
Use the maximum data PDU size time reservation considering the Data
763+
length could be updated from default 27 bytes to maximum support size.
764+
765+
If maximum time reservation is disabled then time reservation required
766+
for empty PDU transmission is used. Overlapping radio events will use
767+
the is_abort_cb mechanism to decide on continuation of the connection
768+
event.
769+
757770
config BT_CTLR_EVENT_OVERHEAD_RESERVE_MAX
758771
bool "Reserve maximum event overhead in time reservations"
759772
default y

subsys/bluetooth/controller/ll_sw/lll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ struct event_done_extra {
509509
struct {
510510
uint16_t trx_cnt;
511511
uint8_t crc_valid:1;
512+
uint8_t is_aborted:1;
512513
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
513514
uint8_t estab_failed:1;
514515
#endif /* CONFIG_BT_CTLR_SYNC_ISO */

subsys/bluetooth/controller/ll_sw/lll_conn.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ struct lll_conn {
6969
struct {
7070
uint8_t initiated:1;
7171
uint8_t cancelled:1;
72+
uint8_t forced:1;
73+
};
74+
75+
struct {
76+
uint8_t initiated:1;
77+
uint8_t cancelled:1;
78+
uint8_t forced:1;
7279
} central;
80+
7381
#if defined(CONFIG_BT_PERIPHERAL)
7482
struct {
7583
uint8_t initiated:1;
7684
uint8_t cancelled:1;
85+
uint8_t forced:1;
7786
uint8_t latency_enabled:1;
7887

7988
uint32_t window_widening_periodic_us;
@@ -160,6 +169,7 @@ int lll_conn_reset(void);
160169
void lll_conn_flush(uint16_t handle, struct lll_conn *lll);
161170

162171
void lll_conn_prepare_reset(void);
172+
int lll_conn_is_abort_cb(void *next, void *curr, lll_prepare_cb_t *resume_cb);
163173
void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param);
164174
void lll_conn_isr_rx(void *param);
165175
void lll_conn_isr_tx(void *param);

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static struct pdu_data *get_last_tx_pdu(struct lll_conn *lll);
5959

6060
static uint8_t crc_expire;
6161
static uint8_t crc_valid;
62+
static uint8_t is_aborted;
6263
static uint16_t trx_cnt;
6364

6465
#if defined(CONFIG_BT_CTLR_LE_ENC)
@@ -142,12 +143,25 @@ void lll_conn_prepare_reset(void)
142143
trx_cnt = 0U;
143144
crc_valid = 0U;
144145
crc_expire = 0U;
146+
is_aborted = 0U;
145147

146148
#if defined(CONFIG_BT_CTLR_LE_ENC)
147149
mic_state = LLL_CONN_MIC_NONE;
148150
#endif /* CONFIG_BT_CTLR_LE_ENC */
149151
}
150152

153+
int lll_conn_is_abort_cb(void *next, void *curr, lll_prepare_cb_t *resume_cb)
154+
{
155+
struct lll_conn *lll = curr;
156+
157+
/* Do not abort if near supervision timeout */
158+
if (lll->forced) {
159+
return 0;
160+
}
161+
162+
return -ECANCELED;
163+
}
164+
151165
void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param)
152166
{
153167
struct event_done_extra *e;
@@ -156,6 +170,17 @@ void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param)
156170

157171
/* NOTE: This is not a prepare being cancelled */
158172
if (!prepare_param) {
173+
/* Get reference to LLL connection context */
174+
lll = param;
175+
176+
/* For a peripheral role, ensure at least one PDU is tx-ed
177+
* back to central, otherwise let the supervision timeout
178+
* countdown be started.
179+
*/
180+
if ((lll->role == BT_HCI_ROLE_PERIPHERAL) && (trx_cnt <= 1U)) {
181+
is_aborted = 1U;
182+
}
183+
159184
/* Perform event abort here.
160185
* After event has been cleanly aborted, clean up resources
161186
* and dispatch event done.
@@ -171,8 +196,10 @@ void lll_conn_abort_cb(struct lll_prepare_param *prepare_param, void *param)
171196
err = lll_hfclock_off();
172197
LL_ASSERT(err >= 0);
173198

174-
/* Accumulate the latency as event is aborted while being in pipeline */
199+
/* Get reference to LLL connection context */
175200
lll = prepare_param->param;
201+
202+
/* Accumulate the latency as event is aborted while being in pipeline */
176203
lll->latency_prepare += (prepare_param->lazy + 1);
177204

178205
/* Extra done event, to check supervision timeout */
@@ -867,6 +894,7 @@ static void isr_done(void *param)
867894
e->type = EVENT_DONE_EXTRA_TYPE_CONN;
868895
e->trx_cnt = trx_cnt;
869896
e->crc_valid = crc_valid;
897+
e->is_aborted = is_aborted;
870898

871899
#if defined(CONFIG_BT_CTLR_LE_ENC)
872900
e->mic_state = mic_state;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ void lll_periph_prepare(void *param)
8989
}
9090

9191
/* Invoke common pipeline handling of prepare */
92-
err = lll_prepare(lll_is_abort_cb, lll_conn_abort_cb, prepare_cb, 0, p);
92+
err = lll_prepare(lll_conn_is_abort_cb, lll_conn_abort_cb, prepare_cb,
93+
0U, p);
9394
LL_ASSERT(!err || err == -EINPROGRESS);
9495
}
9596

subsys/bluetooth/controller/ll_sw/ull_adv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ uint8_t ll_adv_enable(uint8_t enable)
10721072
conn_lll->role = 1;
10731073
conn_lll->periph.initiated = 0;
10741074
conn_lll->periph.cancelled = 0;
1075+
conn_lll->periph.forced = 0;
10751076
conn_lll->data_chan_sel = 0;
10761077
conn_lll->data_chan_use = 0;
10771078
conn_lll->event_counter = 0;

subsys/bluetooth/controller/ll_sw/ull_central.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window,
253253
conn_lll->role = 0;
254254
conn_lll->central.initiated = 0;
255255
conn_lll->central.cancelled = 0;
256+
conn_lll->central.forced = 0;
256257
/* FIXME: END: Move to ULL? */
257258
#if defined(CONFIG_BT_CTLR_CONN_META)
258259
memset(&conn_lll->conn_meta, 0, sizeof(conn_lll->conn_meta));

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ void ull_conn_done(struct node_rx_event_done *done)
943943
struct lll_conn *lll;
944944
struct ll_conn *conn;
945945
uint8_t reason_final;
946+
uint8_t force_lll;
946947
uint16_t lazy;
947948
uint8_t force;
948949

@@ -1054,7 +1055,7 @@ void ull_conn_done(struct node_rx_event_done *done)
10541055
}
10551056

10561057
/* Reset supervision countdown */
1057-
if (done->extra.crc_valid) {
1058+
if (done->extra.crc_valid && !done->extra.is_aborted) {
10581059
conn->supervision_expire = 0U;
10591060
}
10601061

@@ -1085,6 +1086,7 @@ void ull_conn_done(struct node_rx_event_done *done)
10851086

10861087
/* check supervision timeout */
10871088
force = 0U;
1089+
force_lll = 0U;
10881090
if (conn->supervision_expire) {
10891091
if (conn->supervision_expire > elapsed_event) {
10901092
conn->supervision_expire -= elapsed_event;
@@ -1096,6 +1098,8 @@ void ull_conn_done(struct node_rx_event_done *done)
10961098
* supervision timeout.
10971099
*/
10981100
if (conn->supervision_expire <= 6U) {
1101+
force_lll = 1U;
1102+
10991103
force = 1U;
11001104
}
11011105
#if defined(CONFIG_BT_CTLR_CONN_RANDOM_FORCE)
@@ -1123,6 +1127,8 @@ void ull_conn_done(struct node_rx_event_done *done)
11231127
}
11241128
}
11251129

1130+
lll->forced = force_lll;
1131+
11261132
/* check procedure timeout */
11271133
uint8_t error_code;
11281134

@@ -1233,26 +1239,41 @@ void ull_conn_done(struct node_rx_event_done *done)
12331239
uint32_t ready_delay, rx_time, tx_time, ticks_slot, slot_us;
12341240

12351241
lll->evt_len_upd = 0;
1242+
12361243
#if defined(CONFIG_BT_CTLR_PHY)
12371244
ready_delay = (lll->role) ?
12381245
lll_radio_rx_ready_delay_get(lll->phy_rx, PHY_FLAGS_S8) :
12391246
lll_radio_tx_ready_delay_get(lll->phy_tx, lll->phy_flags);
1247+
1248+
#if defined(CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX)
12401249
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
12411250
tx_time = lll->dle.eff.max_tx_time;
12421251
rx_time = lll->dle.eff.max_rx_time;
1243-
#else /* CONFIG_BT_CTLR_DATA_LENGTH */
12441252

1253+
#else /* CONFIG_BT_CTLR_DATA_LENGTH */
12451254
tx_time = MAX(PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, 0),
12461255
PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy_tx));
12471256
rx_time = MAX(PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, 0),
12481257
PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy_rx));
12491258
#endif /* CONFIG_BT_CTLR_DATA_LENGTH */
1259+
1260+
#else /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
1261+
tx_time = PDU_MAX_US(0U, 0U, lll->phy_tx);
1262+
rx_time = PDU_MAX_US(0U, 0U, lll->phy_rx);
1263+
#endif /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
1264+
12501265
#else /* CONFIG_BT_CTLR_PHY */
12511266
ready_delay = (lll->role) ?
12521267
lll_radio_rx_ready_delay_get(0, 0) :
12531268
lll_radio_tx_ready_delay_get(0, 0);
1269+
#if defined(CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX)
12541270
tx_time = PDU_DC_MAX_US(lll->dle.eff.max_tx_octets, 0);
12551271
rx_time = PDU_DC_MAX_US(lll->dle.eff.max_rx_octets, 0);
1272+
1273+
#else /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
1274+
tx_time = PDU_MAX_US(0U, 0U, PHY_1M);
1275+
rx_time = PDU_MAX_US(0U, 0U, PHY_1M);
1276+
#endif /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
12561277
#endif /* CONFIG_BT_CTLR_PHY */
12571278

12581279
/* Calculate event time reservation */

subsys/bluetooth/controller/ll_sw/ull_peripheral.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,25 +341,40 @@ void ull_periph_setup(struct node_rx_pdu *rx, struct node_rx_ftr *ftr,
341341

342342
ll_rx_put_sched(link, rx);
343343

344+
#if defined(CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX)
344345
#if defined(CONFIG_BT_CTLR_DATA_LENGTH)
345346
#if defined(CONFIG_BT_CTLR_PHY)
346347
max_tx_time = lll->dle.eff.max_tx_time;
347348
max_rx_time = lll->dle.eff.max_rx_time;
349+
348350
#else /* !CONFIG_BT_CTLR_PHY */
349351
max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M);
350352
max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M);
351353
#endif /* !CONFIG_BT_CTLR_PHY */
354+
352355
#else /* !CONFIG_BT_CTLR_DATA_LENGTH */
353356
max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M);
354357
max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M);
358+
355359
#if defined(CONFIG_BT_CTLR_PHY)
356360
max_tx_time = MAX(max_tx_time,
357361
PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy_tx));
358362
max_rx_time = MAX(max_rx_time,
359363
PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy_rx));
360-
#endif /* !CONFIG_BT_CTLR_PHY */
364+
#endif /* CONFIG_BT_CTLR_PHY */
361365
#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */
362366

367+
#else /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
368+
#if defined(CONFIG_BT_CTLR_PHY)
369+
max_tx_time = PDU_MAX_US(0U, 0U, lll->phy_tx);
370+
max_rx_time = PDU_MAX_US(0U, 0U, lll->phy_rx);
371+
372+
#else /* !CONFIG_BT_CTLR_PHY */
373+
max_tx_time = PDU_MAX_US(0U, 0U, PHY_1M);
374+
max_rx_time = PDU_MAX_US(0U, 0U, PHY_1M);
375+
#endif /* !CONFIG_BT_CTLR_PHY */
376+
#endif /* !CONFIG_BT_CTLR_PERIPHERAL_RESERVE_MAX */
377+
363378
#if defined(CONFIG_BT_CTLR_PHY)
364379
ready_delay_us = lll_radio_rx_ready_delay_get(lll->phy_rx, PHY_FLAGS_S8);
365380
#else /* CONFIG_BT_CTLR_PHY */

0 commit comments

Comments
 (0)