Commit 541b516a authored by Morten Priess's avatar Morten Priess Committed by Alberto Escolar
Browse files

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: default avatarMorten Priess <mtpr@oticon.com>
parent 848907c0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@ enum {
	TICKER_ID_SCAN_SYNC_ISO_BASE,
	TICKER_ID_SCAN_SYNC_ISO_LAST = ((TICKER_ID_SCAN_SYNC_ISO_BASE) +
					(CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) - 1),
	TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE,
	TICKER_ID_SCAN_SYNC_ISO_RESUME_LAST = ((TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE) +
					       (CONFIG_BT_CTLR_SCAN_SYNC_ISO_SET) - 1),
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */
#endif /* CONFIG_BT_CTLR_ADV_EXT */
+3 −1
Original line number Diff line number Diff line
@@ -127,7 +127,9 @@
				   (TICKER_ID_SCAN_SYNC_BASE) + 1)
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
#define BT_SCAN_SYNC_ISO_TICKER_NODES ((TICKER_ID_SCAN_SYNC_ISO_LAST) - \
				       (TICKER_ID_SCAN_SYNC_ISO_BASE) + 1)
				       (TICKER_ID_SCAN_SYNC_ISO_BASE) + 1 + \
				       (TICKER_ID_SCAN_SYNC_ISO_RESUME_LAST) - \
				       (TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE) + 1)
#else /* !CONFIG_BT_CTLR_SYNC_ISO */
#define BT_SCAN_SYNC_ISO_TICKER_NODES 0
#endif /* !CONFIG_BT_CTLR_SYNC_ISO */
+0 −110
Original line number Diff line number Diff line
@@ -73,10 +73,6 @@ static void ticker_next_slot_get_op_cb(uint32_t status, void *param);
#endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */
static void ticker_start_op_cb(uint32_t status, void *param);
static void ticker_update_cig_op_cb(uint32_t status, void *param);
static void ticker_resume_op_cb(uint32_t status, void *param);
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
			     uint32_t remainder, uint16_t lazy, uint8_t force,
			     void *param);
static void cis_disabled_cb(void *param);
static void ticker_stop_op_cb(uint32_t status, void *param);
static void cig_disable(void *param);
@@ -616,72 +612,6 @@ void ull_conn_iso_cis_stop(struct ll_conn_iso_stream *cis,
	}
}

void ull_conn_iso_resume_ticker_start(struct lll_event *resume_event,
				      uint16_t cis_handle,
				      uint32_t ticks_anchor,
				      uint32_t resume_timeout)
{
	struct lll_conn_iso_group *cig;
	uint32_t resume_delay_us;
	int32_t resume_offset_us;
	uint8_t ticker_id;
	uint32_t ret;

	cig = resume_event->prepare_param.param;
	ticker_id = TICKER_ID_CONN_ISO_RESUME_BASE + cig->handle;

	if (cig->resume_cis != LLL_HANDLE_INVALID) {
		/* Restarting resume ticker - must be stopped first */
		(void)ticker_stop(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_LLL,
				  ticker_id, NULL, NULL);
	}
	cig->resume_cis = cis_handle;

	resume_delay_us  = EVENT_OVERHEAD_START_US;
	resume_delay_us += EVENT_TICKER_RES_MARGIN_US;

	if (cig->role == BT_HCI_ROLE_PERIPHERAL) {
		/* Add peripheral specific delay */
		resume_delay_us += EVENT_JITTER_US;
		if (0) {
#if defined(CONFIG_BT_CTLR_PHY)
		} else {
			struct ll_conn_iso_stream *cis;
			struct ll_conn *conn;

			cis = ll_conn_iso_stream_get(cis_handle);
			conn = ll_conn_get(cis->lll.acl_handle);

			resume_delay_us +=
				lll_radio_rx_ready_delay_get(conn->lll.phy_rx,
							     PHY_FLAGS_S8);
#else
		} else {
			resume_delay_us += lll_radio_rx_ready_delay_get(0, 0);
#endif /* CONFIG_BT_CTLR_PHY */
		}
	}

	resume_offset_us = (int32_t)(resume_timeout - resume_delay_us);
	LL_ASSERT(resume_offset_us >= 0);

	/* Setup resume timeout as single-shot */
	ret = ticker_start(TICKER_INSTANCE_ID_CTLR,
			   TICKER_USER_ID_LLL,
			   ticker_id,
			   ticks_anchor,
			   HAL_TICKER_US_TO_TICKS(resume_offset_us),
			   TICKER_NULL_PERIOD,
			   TICKER_NULL_REMAINDER,
			   TICKER_NULL_LAZY,
			   TICKER_NULL_SLOT,
			   ticker_resume_cb, resume_event,
			   ticker_resume_op_cb, NULL);

	LL_ASSERT((ret == TICKER_STATUS_SUCCESS) ||
		  (ret == TICKER_STATUS_BUSY));
}

int ull_conn_iso_init(void)
{
	return init_reset();
@@ -1268,46 +1198,6 @@ static void ticker_update_cig_op_cb(uint32_t status, void *param)
		  param == ull_disable_mark_get());
}

static void ticker_resume_op_cb(uint32_t status, void *param)
{
	ARG_UNUSED(param);

	LL_ASSERT(status == TICKER_STATUS_SUCCESS);
}

static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
			     uint32_t remainder, uint16_t lazy, uint8_t force,
			     void *param)
{
	static memq_link_t link;
	static struct mayfly mfy = {0, 0, &link, NULL, lll_resume};
	struct lll_conn_iso_group *cig;
	struct lll_event *resume_event;
	uint32_t ret;

	ARG_UNUSED(ticks_drift);
	LL_ASSERT(lazy == 0);

	resume_event = param;

	/* Append timing parameters */
	resume_event->prepare_param.ticks_at_expire = ticks_at_expire;
	resume_event->prepare_param.remainder = remainder;
	resume_event->prepare_param.lazy = 0;
	resume_event->prepare_param.force = force;
	mfy.param = resume_event;

	/* Mark resume as done */
	cig = resume_event->prepare_param.param;
	cig->resume_cis = LLL_HANDLE_INVALID;

	/* Kick LLL resume */
	ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL,
			     0, &mfy);

	LL_ASSERT(!ret);
}

static void cis_disabled_cb(void *param)
{
	struct ll_conn_iso_group *cig;
+0 −4
Original line number Diff line number Diff line
@@ -44,10 +44,6 @@ void ull_conn_iso_cis_stop(struct ll_conn_iso_stream *cis,
			   ll_iso_stream_released_cb_t cis_released_cb,
			   uint8_t reason);

void ull_conn_iso_resume_ticker_start(struct lll_event *resume_event,
				      uint16_t cis_handle,
				      uint32_t ticks_anchor,
				      uint32_t resume_timeout);
void ull_conn_iso_transmit_test_cig_interval(uint16_t handle,
					     uint32_t ticks_at_expire);

+133 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "util/mayfly.h"
#include "util/dbuf.h"

#include "ticker/ticker.h"

#include "pdu_df.h"
#include "lll/pdu_vendor.h"
#include "pdu.h"
@@ -36,6 +38,7 @@
#include "lll_conn.h"
#include "lll_conn_iso.h"
#include "lll_iso_tx.h"
#include "lll/lll_vendor.h"

#include "ll_sw/ull_tx_queue.h"

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

#if defined(CONFIG_BT_CTLR_SYNC_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
static void ticker_resume_op_cb(uint32_t status, void *param);
static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
			     uint32_t remainder, uint16_t lazy, uint8_t force,
			     void *param);

#define NODE_RX_HEADER_SIZE (offsetof(struct node_rx_pdu, pdu))
/* ISO LL conformance tests require a PDU size of maximum 251 bytes + header */
#define ISO_RX_BUFFER_SIZE (2 + 251)
@@ -1973,3 +1981,128 @@ static int init_reset(void)

	return 0;
}

#if defined(CONFIG_BT_CTLR_CONN_ISO) || defined(CONFIG_BT_CTLR_SYNC_ISO)
void ull_iso_resume_ticker_start(struct lll_event *resume_event,
				 uint16_t group_handle,
				 uint16_t stream_handle,
				 uint8_t  role,
				 uint32_t ticks_anchor,
				 uint32_t resume_timeout)
{
	uint32_t resume_delay_us;
	int32_t resume_offset_us;
	uint8_t ticker_id = 0;
	uint32_t ret;

	resume_delay_us  = EVENT_OVERHEAD_START_US;
	resume_delay_us += EVENT_TICKER_RES_MARGIN_US;

	if (0) {
#if defined(CONFIG_BT_CTLR_CONN_ISO)
	} else if (IS_CIS_HANDLE(stream_handle)) {
		ticker_id = TICKER_ID_CONN_ISO_RESUME_BASE + group_handle;
#endif /* CONFIG_BT_CTLR_CONN_ISO */
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
	} else if (IS_SYNC_ISO_HANDLE(stream_handle)) {
		ticker_id = TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE + group_handle;
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
	} else {
		LL_ASSERT(0);
	}

	if (role == BT_HCI_ROLE_PERIPHERAL) {
		/* Add peripheral specific delay */
		resume_delay_us += EVENT_JITTER_US;
		if (0) {
#if defined(CONFIG_BT_CTLR_PHY)
		} else {
			uint8_t phy = 0;

			if (0) {
#if defined(CONFIG_BT_CTLR_CONN_ISO)
			} else if (IS_CIS_HANDLE(stream_handle)) {
				struct ll_conn_iso_stream *cis;
				struct ll_conn *conn;

				cis = ll_conn_iso_stream_get(stream_handle);
				conn = ll_conn_get(cis->lll.acl_handle);
				phy = conn->lll.phy_rx;
#endif /* CONFIG_BT_CTLR_CONN_ISO */
#if defined(CONFIG_BT_CTLR_SYNC_ISO)
			} else if (IS_SYNC_ISO_HANDLE(stream_handle)) {
				struct ll_sync_iso_set *sync_iso;
				uint16_t stream_idx;

				stream_idx = LL_BIS_SYNC_IDX_FROM_HANDLE(stream_handle);
				sync_iso = ull_sync_iso_by_stream_get(stream_idx);
				phy = sync_iso->lll.phy;
#endif /* CONFIG_BT_CTLR_SYNC_ISO */
			} else {
				LL_ASSERT(0);
			}

			resume_delay_us +=
				lll_radio_rx_ready_delay_get(phy, PHY_FLAGS_S8);
#else
		} else {
			resume_delay_us += lll_radio_rx_ready_delay_get(0, 0);
#endif /* CONFIG_BT_CTLR_PHY */
		}
	}

	resume_offset_us = (int32_t)(resume_timeout - resume_delay_us);
	LL_ASSERT(resume_offset_us >= 0);

	/* Setup resume timeout as single-shot */
	ret = ticker_start(TICKER_INSTANCE_ID_CTLR,
			   TICKER_USER_ID_LLL,
			   ticker_id,
			   ticks_anchor,
			   HAL_TICKER_US_TO_TICKS(resume_offset_us),
			   TICKER_NULL_PERIOD,
			   TICKER_NULL_REMAINDER,
			   TICKER_NULL_LAZY,
			   TICKER_NULL_SLOT,
			   ticker_resume_cb, resume_event,
			   ticker_resume_op_cb, NULL);

	LL_ASSERT((ret == TICKER_STATUS_SUCCESS) ||
		  (ret == TICKER_STATUS_BUSY));
}

static void ticker_resume_op_cb(uint32_t status, void *param)
{
	ARG_UNUSED(param);

	LL_ASSERT(status == TICKER_STATUS_SUCCESS);
}

static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift,
			     uint32_t remainder, uint16_t lazy, uint8_t force,
			     void *param)
{
	static memq_link_t link;
	static struct mayfly mfy = {0, 0, &link, NULL, lll_resume};
	struct lll_event *resume_event;
	uint32_t ret;

	ARG_UNUSED(ticks_drift);
	LL_ASSERT(lazy == 0);

	resume_event = param;

	/* Append timing parameters */
	resume_event->prepare_param.ticks_at_expire = ticks_at_expire;
	resume_event->prepare_param.remainder = remainder;
	resume_event->prepare_param.lazy = 0;
	resume_event->prepare_param.force = force;
	mfy.param = resume_event;

	/* Kick LLL resume */
	ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL,
			     0, &mfy);

	LL_ASSERT(!ret);
}
#endif /* CONFIG_BT_CTLR_CONN_ISO || CONFIG_BT_CTLR_SYNC_ISO */
Loading