Skip to content

Commit 541b516

Browse files
mtpr-otaescolar
authored andcommitted
Bluetooth: controller: Make ISO Pause/Resume common
Share pause/resume functionality by moving resume ticker handling to ull_iso. Rename interface function to ull_conn_iso_resume_ticker_start, and provide handles instead of instance pointer. Signed-off-by: Morten Priess <[email protected]>
1 parent 848907c commit 541b516

File tree

6 files changed

+146
-115
lines changed

6 files changed

+146
-115
lines changed

subsys/bluetooth/controller/ll_sw/lll.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ enum {
103103
TICKER_ID_SCAN_SYNC_ISO_BASE,
104104
TICKER_ID_SCAN_SYNC_ISO_LAST = ((TICKER_ID_SCAN_SYNC_ISO_BASE) +
105105
(CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) - 1),
106+
TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE,
107+
TICKER_ID_SCAN_SYNC_ISO_RESUME_LAST = ((TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE) +
108+
(CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) - 1),
106109
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
107110
#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
108111
#endif /* CONFIG_BT_CTLR_ADV_EXT */

subsys/bluetooth/controller/ll_sw/ull.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@
127127
(TICKER_ID_SCAN_SYNC_BASE) + 1)
128128
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
129129
#define BT_SCAN_SYNC_ISO_TICKER_NODES ((TICKER_ID_SCAN_SYNC_ISO_LAST) - \
130-
(TICKER_ID_SCAN_SYNC_ISO_BASE) + 1)
130+
(TICKER_ID_SCAN_SYNC_ISO_BASE) + 1 + \
131+
(TICKER_ID_SCAN_SYNC_ISO_RESUME_LAST) - \
132+
(TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE) + 1)
131133
#else /* !CONFIG_BT_CTLR_SYNC_ISO */
132134
#define BT_SCAN_SYNC_ISO_TICKER_NODES 0
133135
#endif /* !CONFIG_BT_CTLR_SYNC_ISO */

subsys/bluetooth/controller/ll_sw/ull_conn_iso.c

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ static void ticker_next_slot_get_op_cb(uint32_t status, void *param);
7373
#endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */
7474
static void ticker_start_op_cb(uint32_t status, void *param);
7575
static void ticker_update_cig_op_cb(uint32_t status, void *param);
76-
static void ticker_resume_op_cb(uint32_t status, void *param);
77-
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
78-
uint32_t remainder, uint16_t lazy, uint8_t force,
79-
void *param);
8076
static void cis_disabled_cb(void *param);
8177
static void ticker_stop_op_cb(uint32_t status, void *param);
8278
static void cig_disable(void *param);
@@ -616,72 +612,6 @@ void ull_conn_iso_cis_stop(struct ll_conn_iso_stream *cis,
616612
}
617613
}
618614

619-
void ull_conn_iso_resume_ticker_start(struct lll_event *resume_event,
620-
uint16_t cis_handle,
621-
uint32_t ticks_anchor,
622-
uint32_t resume_timeout)
623-
{
624-
struct lll_conn_iso_group *cig;
625-
uint32_t resume_delay_us;
626-
int32_t resume_offset_us;
627-
uint8_t ticker_id;
628-
uint32_t ret;
629-
630-
cig = resume_event->prepare_param.param;
631-
ticker_id = TICKER_ID_CONN_ISO_RESUME_BASE + cig->handle;
632-
633-
if (cig->resume_cis != LLL_HANDLE_INVALID) {
634-
/* Restarting resume ticker - must be stopped first */
635-
(void)ticker_stop(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_LLL,
636-
ticker_id, NULL, NULL);
637-
}
638-
cig->resume_cis = cis_handle;
639-
640-
resume_delay_us = EVENT_OVERHEAD_START_US;
641-
resume_delay_us += EVENT_TICKER_RES_MARGIN_US;
642-
643-
if (cig->role == BT_HCI_ROLE_PERIPHERAL) {
644-
/* Add peripheral specific delay */
645-
resume_delay_us += EVENT_JITTER_US;
646-
if (0) {
647-
#if defined(CONFIG_BT_CTLR_PHY)
648-
} else {
649-
struct ll_conn_iso_stream *cis;
650-
struct ll_conn *conn;
651-
652-
cis = ll_conn_iso_stream_get(cis_handle);
653-
conn = ll_conn_get(cis->lll.acl_handle);
654-
655-
resume_delay_us +=
656-
lll_radio_rx_ready_delay_get(conn->lll.phy_rx,
657-
PHY_FLAGS_S8);
658-
#else
659-
} else {
660-
resume_delay_us += lll_radio_rx_ready_delay_get(0, 0);
661-
#endif /* CONFIG_BT_CTLR_PHY */
662-
}
663-
}
664-
665-
resume_offset_us = (int32_t)(resume_timeout - resume_delay_us);
666-
LL_ASSERT(resume_offset_us >= 0);
667-
668-
/* Setup resume timeout as single-shot */
669-
ret = ticker_start(TICKER_INSTANCE_ID_CTLR,
670-
TICKER_USER_ID_LLL,
671-
ticker_id,
672-
ticks_anchor,
673-
HAL_TICKER_US_TO_TICKS(resume_offset_us),
674-
TICKER_NULL_PERIOD,
675-
TICKER_NULL_REMAINDER,
676-
TICKER_NULL_LAZY,
677-
TICKER_NULL_SLOT,
678-
ticker_resume_cb, resume_event,
679-
ticker_resume_op_cb, NULL);
680-
681-
LL_ASSERT((ret == TICKER_STATUS_SUCCESS) ||
682-
(ret == TICKER_STATUS_BUSY));
683-
}
684-
685615
int ull_conn_iso_init(void)
686616
{
687617
return init_reset();
@@ -1268,46 +1198,6 @@ static void ticker_update_cig_op_cb(uint32_t status, void *param)
12681198
param == ull_disable_mark_get());
12691199
}
12701200

1271-
static void ticker_resume_op_cb(uint32_t status, void *param)
1272-
{
1273-
ARG_UNUSED(param);
1274-
1275-
LL_ASSERT(status == TICKER_STATUS_SUCCESS);
1276-
}
1277-
1278-
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
1279-
uint32_t remainder, uint16_t lazy, uint8_t force,
1280-
void *param)
1281-
{
1282-
static memq_link_t link;
1283-
static struct mayfly mfy = {0, 0, &link, NULL, lll_resume};
1284-
struct lll_conn_iso_group *cig;
1285-
struct lll_event *resume_event;
1286-
uint32_t ret;
1287-
1288-
ARG_UNUSED(ticks_drift);
1289-
LL_ASSERT(lazy == 0);
1290-
1291-
resume_event = param;
1292-
1293-
/* Append timing parameters */
1294-
resume_event->prepare_param.ticks_at_expire = ticks_at_expire;
1295-
resume_event->prepare_param.remainder = remainder;
1296-
resume_event->prepare_param.lazy = 0;
1297-
resume_event->prepare_param.force = force;
1298-
mfy.param = resume_event;
1299-
1300-
/* Mark resume as done */
1301-
cig = resume_event->prepare_param.param;
1302-
cig->resume_cis = LLL_HANDLE_INVALID;
1303-
1304-
/* Kick LLL resume */
1305-
ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL,
1306-
0, &mfy);
1307-
1308-
LL_ASSERT(!ret);
1309-
}
1310-
13111201
static void cis_disabled_cb(void *param)
13121202
{
13131203
struct ll_conn_iso_group *cig;

subsys/bluetooth/controller/ll_sw/ull_conn_iso_internal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ void ull_conn_iso_cis_stop(struct ll_conn_iso_stream *cis,
4444
ll_iso_stream_released_cb_t cis_released_cb,
4545
uint8_t reason);
4646

47-
void ull_conn_iso_resume_ticker_start(struct lll_event *resume_event,
48-
uint16_t cis_handle,
49-
uint32_t ticks_anchor,
50-
uint32_t resume_timeout);
5147
void ull_conn_iso_transmit_test_cig_interval(uint16_t handle,
5248
uint32_t ticks_at_expire);
5349

subsys/bluetooth/controller/ll_sw/ull_iso.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "util/mayfly.h"
2222
#include "util/dbuf.h"
2323

24+
#include "ticker/ticker.h"
25+
2426
#include "pdu_df.h"
2527
#include "lll/pdu_vendor.h"
2628
#include "pdu.h"
@@ -36,6 +38,7 @@
3638
#include "lll_conn.h"
3739
#include "lll_conn_iso.h"
3840
#include "lll_iso_tx.h"
41+
#include "lll/lll_vendor.h"
3942

4043
#include "ll_sw/ull_tx_queue.h"
4144

@@ -107,6 +110,11 @@ static struct ll_iso_datapath datapath_pool[BT_CTLR_ISO_STREAMS];
107110
static void *datapath_free;
108111

109112
#if defined(CONFIG_BT_CTLR_SYNC_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
113+
static void ticker_resume_op_cb(uint32_t status, void *param);
114+
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
115+
uint32_t remainder, uint16_t lazy, uint8_t force,
116+
void *param);
117+
110118
#define NODE_RX_HEADER_SIZE (offsetof(struct node_rx_pdu, pdu))
111119
/* ISO LL conformance tests require a PDU size of maximum 251 bytes + header */
112120
#define ISO_RX_BUFFER_SIZE (2 + 251)
@@ -1973,3 +1981,128 @@ static int init_reset(void)
19731981

19741982
return 0;
19751983
}
1984+
1985+
#if defined(CONFIG_BT_CTLR_CONN_ISO) || defined(CONFIG_BT_CTLR_SYNC_ISO)
1986+
void ull_iso_resume_ticker_start(struct lll_event *resume_event,
1987+
uint16_t group_handle,
1988+
uint16_t stream_handle,
1989+
uint8_t role,
1990+
uint32_t ticks_anchor,
1991+
uint32_t resume_timeout)
1992+
{
1993+
uint32_t resume_delay_us;
1994+
int32_t resume_offset_us;
1995+
uint8_t ticker_id = 0;
1996+
uint32_t ret;
1997+
1998+
resume_delay_us = EVENT_OVERHEAD_START_US;
1999+
resume_delay_us += EVENT_TICKER_RES_MARGIN_US;
2000+
2001+
if (0) {
2002+
#if defined(CONFIG_BT_CTLR_CONN_ISO)
2003+
} else if (IS_CIS_HANDLE(stream_handle)) {
2004+
ticker_id = TICKER_ID_CONN_ISO_RESUME_BASE + group_handle;
2005+
#endif /* CONFIG_BT_CTLR_CONN_ISO */
2006+
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
2007+
} else if (IS_SYNC_ISO_HANDLE(stream_handle)) {
2008+
ticker_id = TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE + group_handle;
2009+
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
2010+
} else {
2011+
LL_ASSERT(0);
2012+
}
2013+
2014+
if (role == BT_HCI_ROLE_PERIPHERAL) {
2015+
/* Add peripheral specific delay */
2016+
resume_delay_us += EVENT_JITTER_US;
2017+
if (0) {
2018+
#if defined(CONFIG_BT_CTLR_PHY)
2019+
} else {
2020+
uint8_t phy = 0;
2021+
2022+
if (0) {
2023+
#if defined(CONFIG_BT_CTLR_CONN_ISO)
2024+
} else if (IS_CIS_HANDLE(stream_handle)) {
2025+
struct ll_conn_iso_stream *cis;
2026+
struct ll_conn *conn;
2027+
2028+
cis = ll_conn_iso_stream_get(stream_handle);
2029+
conn = ll_conn_get(cis->lll.acl_handle);
2030+
phy = conn->lll.phy_rx;
2031+
#endif /* CONFIG_BT_CTLR_CONN_ISO */
2032+
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
2033+
} else if (IS_SYNC_ISO_HANDLE(stream_handle)) {
2034+
struct ll_sync_iso_set *sync_iso;
2035+
uint16_t stream_idx;
2036+
2037+
stream_idx = LL_BIS_SYNC_IDX_FROM_HANDLE(stream_handle);
2038+
sync_iso = ull_sync_iso_by_stream_get(stream_idx);
2039+
phy = sync_iso->lll.phy;
2040+
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
2041+
} else {
2042+
LL_ASSERT(0);
2043+
}
2044+
2045+
resume_delay_us +=
2046+
lll_radio_rx_ready_delay_get(phy, PHY_FLAGS_S8);
2047+
#else
2048+
} else {
2049+
resume_delay_us += lll_radio_rx_ready_delay_get(0, 0);
2050+
#endif /* CONFIG_BT_CTLR_PHY */
2051+
}
2052+
}
2053+
2054+
resume_offset_us = (int32_t)(resume_timeout - resume_delay_us);
2055+
LL_ASSERT(resume_offset_us >= 0);
2056+
2057+
/* Setup resume timeout as single-shot */
2058+
ret = ticker_start(TICKER_INSTANCE_ID_CTLR,
2059+
TICKER_USER_ID_LLL,
2060+
ticker_id,
2061+
ticks_anchor,
2062+
HAL_TICKER_US_TO_TICKS(resume_offset_us),
2063+
TICKER_NULL_PERIOD,
2064+
TICKER_NULL_REMAINDER,
2065+
TICKER_NULL_LAZY,
2066+
TICKER_NULL_SLOT,
2067+
ticker_resume_cb, resume_event,
2068+
ticker_resume_op_cb, NULL);
2069+
2070+
LL_ASSERT((ret == TICKER_STATUS_SUCCESS) ||
2071+
(ret == TICKER_STATUS_BUSY));
2072+
}
2073+
2074+
static void ticker_resume_op_cb(uint32_t status, void *param)
2075+
{
2076+
ARG_UNUSED(param);
2077+
2078+
LL_ASSERT(status == TICKER_STATUS_SUCCESS);
2079+
}
2080+
2081+
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
2082+
uint32_t remainder, uint16_t lazy, uint8_t force,
2083+
void *param)
2084+
{
2085+
static memq_link_t link;
2086+
static struct mayfly mfy = {0, 0, &link, NULL, lll_resume};
2087+
struct lll_event *resume_event;
2088+
uint32_t ret;
2089+
2090+
ARG_UNUSED(ticks_drift);
2091+
LL_ASSERT(lazy == 0);
2092+
2093+
resume_event = param;
2094+
2095+
/* Append timing parameters */
2096+
resume_event->prepare_param.ticks_at_expire = ticks_at_expire;
2097+
resume_event->prepare_param.remainder = remainder;
2098+
resume_event->prepare_param.lazy = 0;
2099+
resume_event->prepare_param.force = force;
2100+
mfy.param = resume_event;
2101+
2102+
/* Kick LLL resume */
2103+
ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL,
2104+
0, &mfy);
2105+
2106+
LL_ASSERT(!ret);
2107+
}
2108+
#endif /* CONFIG_BT_CTLR_CONN_ISO || CONFIG_BT_CTLR_SYNC_ISO */

subsys/bluetooth/controller/ll_sw/ull_iso_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ bool ll_data_path_source_create(uint16_t handle,
5050

5151
/* Must be implemented by vendor if vendor-specific data path is supported */
5252
void ll_data_path_tx_pdu_release(uint16_t handle, struct node_tx_iso *node_tx);
53+
54+
void ull_iso_resume_ticker_start(struct lll_event *resume_event,
55+
uint16_t group_handle,
56+
uint16_t stream_handle,
57+
uint8_t role,
58+
uint32_t ticks_anchor,
59+
uint32_t resume_timeout);

0 commit comments

Comments
 (0)