From fb95936bd64b22509189038e6429105702f688ae Mon Sep 17 00:00:00 2001 From: Florian Grandel Date: Fri, 10 May 2024 16:36:50 +0200 Subject: [PATCH] samples: bluetooth: central_iso: remove latency Zephyr's OSS bluetooth controller implementation has distinct timing approaches for SDUs that are scheduled from within the controller stack (with well-known phase information) and SDUs scheduled via HCI (with unknown phase information). The former will be scheduled for the next ISO event, the latter one ISO interval in the future, to avoid race conditions. The change caters for this detail by incrementing the sequence number once after the first SDU has been sent out to avoid unnecessary latency in subsequent package scheduling. This should not lead to a race condition as we start our timer from the connection callback which provides a sufficiently repeatable anchor point for timing. Signed-off-by: Florian Grandel --- samples/bluetooth/central_iso/src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/bluetooth/central_iso/src/main.c b/samples/bluetooth/central_iso/src/main.c index e4e862cda7654ef..11b51bce7cf8aa7 100644 --- a/samples/bluetooth/central_iso/src/main.c +++ b/samples/bluetooth/central_iso/src/main.c @@ -97,6 +97,14 @@ static void iso_timer_timeout(struct k_timer *timer) seq_num++; + /* The first packet will be delivered while not active in an ISO event, + * therefore the controller stack adds an extra CIS interval to allow for + * ISO-AL processing, see @ref hci_iso_handle(). + */ + if (unlikely(seq_num == 2)) { + seq_num++; + } + /* iso_send_sdu_work will access seq_num, so be sure to update it * before submitting the work. */