Commit 4d60f0a5 authored by Emil Gydesen's avatar Emil Gydesen Committed by Benjamin Cabé
Browse files

samples: Bluetooth: Handle shutdown of iso broadcast benchmark

The sample did not properly handle ending the broadcast and setting
it up for a new broadcast, due to missing wait for sem_big_term and
a bad check in iso_disconnected.

Furthermore if any did not work when setting up the BIG,
the error handling did not properly clean up for a retry.

Signed-off-by: default avatarEmil Gydesen <emil.gydesen@nordicsemi.no>
parent f25a8aaf
Loading
Loading
Loading
Loading
+20 −2
Changes for samples/bluetooth/iso_broadcast_benchmark/src/broadcaster.c: 20 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <zephyr/console/console.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/byteorder.h>

#include <zephyr/logging/log.h>
@@ -86,7 +87,7 @@ static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason)
	       chan, reason);

	connected_bis--;
	if (connected_bis == big_create_param.num_bis) {
	if (connected_bis == 0) {
		k_sem_give(&sem_big_term);
	}
}
@@ -681,7 +682,7 @@ static int create_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big)
	err = bt_le_ext_adv_set_data(*adv, ad, ARRAY_SIZE(ad), NULL, 0);
	if (err) {
		LOG_ERR("Failed to set advertising data (err %d)", err);
		return 0;
		return err;
	}

	LOG_INF("Setting Periodic Advertising parameters");
@@ -739,13 +740,21 @@ static int delete_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big)
{
	int err;

	if (*big != NULL) {
		err = bt_iso_big_terminate(*big);
		if (err != 0) {
			LOG_ERR("Failed to terminate BIG (err %d)", err);
			return err;
		}
		err = k_sem_take(&sem_big_term, K_FOREVER);
		if (err != 0) {
			LOG_ERR("failed to take sem_big_term (err %d)", err);
			return err;
		}
		*big = NULL;
	}

	if (*adv != NULL) {
		err = bt_le_per_adv_stop(*adv);
		if (err != 0) {
			LOG_ERR("Failed to stop periodic advertising (err %d)", err);
@@ -765,6 +774,7 @@ static int delete_big(struct bt_le_ext_adv **adv, struct bt_iso_big **big)
		}

		*adv = NULL;
	}

	return 0;
}
@@ -810,7 +820,15 @@ int test_run_broadcaster(void)

	err = create_big(&adv, &big);
	if (err) {
		int del_err;

		LOG_ERR("Could not create BIG: %d", err);

		del_err = delete_big(&adv, &big);
		if (del_err) {
			LOG_ERR("Could not delete BIG: %d", del_err);
		}

		return err;
	}