samples: Bluetooth: Fix broadcast and receive to wait for all channels

Fix the iso_broadcast and iso_receive sample to wait on
semaphore for all channel establishment and all channel
terminate callbacks to be invoked.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
Vinayak Kariappa Chettimada 2022-09-12 06:33:42 +05:30 committed by Carles Cufí
parent 3559abed4d
commit 6843eef4cf
2 changed files with 54 additions and 34 deletions

View file

@ -16,8 +16,8 @@
NET_BUF_POOL_FIXED_DEFINE(bis_tx_pool, BIS_ISO_CHAN_COUNT, NET_BUF_POOL_FIXED_DEFINE(bis_tx_pool, BIS_ISO_CHAN_COUNT,
BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL);
static K_SEM_DEFINE(sem_big_cmplt, 0, 1); static K_SEM_DEFINE(sem_big_cmplt, 0, BIS_ISO_CHAN_COUNT);
static K_SEM_DEFINE(sem_big_term, 0, 1); static K_SEM_DEFINE(sem_big_term, 0, BIS_ISO_CHAN_COUNT);
#define INITIAL_TIMEOUT_COUNTER (BIG_TERMINATE_TIMEOUT_US / BIG_SDU_INTERVAL_US) #define INITIAL_TIMEOUT_COUNTER (BIG_TERMINATE_TIMEOUT_US / BIG_SDU_INTERVAL_US)
@ -128,13 +128,15 @@ void main(void)
return; return;
} }
printk("Waiting for BIG complete..."); for (uint8_t chan = 0U; chan < BIS_ISO_CHAN_COUNT; chan++) {
err = k_sem_take(&sem_big_cmplt, K_FOREVER); printk("Waiting for BIG complete chan %u...\n", chan);
if (err) { err = k_sem_take(&sem_big_cmplt, K_FOREVER);
printk("failed (err %d)\n", err); if (err) {
return; printk("failed (err %d)\n", err);
return;
}
printk("BIG create complete chan %u.\n", chan);
} }
printk("done.\n");
while (true) { while (true) {
int ret; int ret;
@ -184,13 +186,18 @@ void main(void)
} }
printk("done.\n"); printk("done.\n");
printk("Waiting for BIG terminate complete..."); for (uint8_t chan = 0U; chan < BIS_ISO_CHAN_COUNT;
err = k_sem_take(&sem_big_term, K_FOREVER); chan++) {
if (err) { printk("Waiting for BIG terminate complete"
printk("failed (err %d)\n", err); " chan %u...\n", chan);
return; err = k_sem_take(&sem_big_term, K_FOREVER);
if (err) {
printk("failed (err %d)\n", err);
return;
}
printk("BIG terminate complete chan %u.\n",
chan);
} }
printk("done.\n");
printk("Create BIG..."); printk("Create BIG...");
err = bt_iso_big_create(adv, &big_create_param, &big); err = bt_iso_big_create(adv, &big_create_param, &big);
@ -200,13 +207,17 @@ void main(void)
} }
printk("done.\n"); printk("done.\n");
printk("Waiting for BIG complete..."); for (uint8_t chan = 0U; chan < BIS_ISO_CHAN_COUNT;
err = k_sem_take(&sem_big_cmplt, K_FOREVER); chan++) {
if (err) { printk("Waiting for BIG complete chan %u...\n",
printk("failed (err %d)\n", err); chan);
return; err = k_sem_take(&sem_big_cmplt, K_FOREVER);
if (err) {
printk("failed (err %d)\n", err);
return;
}
printk("BIG create complete chan %u.\n", chan);
} }
printk("done.\n");
} }
} }
} }

View file

@ -22,6 +22,8 @@
#define PA_RETRY_COUNT 6 #define PA_RETRY_COUNT 6
#define BIS_ISO_CHAN_COUNT 2
static bool per_adv_found; static bool per_adv_found;
static bool per_adv_lost; static bool per_adv_lost;
static bt_addr_le_t per_addr; static bt_addr_le_t per_addr;
@ -32,8 +34,8 @@ static K_SEM_DEFINE(sem_per_adv, 0, 1);
static K_SEM_DEFINE(sem_per_sync, 0, 1); static K_SEM_DEFINE(sem_per_sync, 0, 1);
static K_SEM_DEFINE(sem_per_sync_lost, 0, 1); static K_SEM_DEFINE(sem_per_sync_lost, 0, 1);
static K_SEM_DEFINE(sem_per_big_info, 0, 1); static K_SEM_DEFINE(sem_per_big_info, 0, 1);
static K_SEM_DEFINE(sem_big_sync, 0, 1); static K_SEM_DEFINE(sem_big_sync, 0, BIS_ISO_CHAN_COUNT);
static K_SEM_DEFINE(sem_big_sync_lost, 0, 1); static K_SEM_DEFINE(sem_big_sync_lost, 0, BIS_ISO_CHAN_COUNT);
/* The devicetree node identifier for the "led0" alias. */ /* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0) #define LED0_NODE DT_ALIAS(led0)
@ -204,8 +206,6 @@ static struct bt_le_per_adv_sync_cb sync_callbacks = {
.biginfo = biginfo_cb, .biginfo = biginfo_cb,
}; };
#define BIS_ISO_CHAN_COUNT 2
static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *info, static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *info,
struct net_buf *buf) struct net_buf *buf)
{ {
@ -247,19 +247,19 @@ static struct bt_iso_chan_ops iso_ops = {
static struct bt_iso_chan_io_qos iso_rx_qos[BIS_ISO_CHAN_COUNT]; static struct bt_iso_chan_io_qos iso_rx_qos[BIS_ISO_CHAN_COUNT];
static struct bt_iso_chan_qos bis_iso_qos[BIS_ISO_CHAN_COUNT] = { static struct bt_iso_chan_qos bis_iso_qos[] = {
{ .rx = &iso_rx_qos[0], }, { .rx = &iso_rx_qos[0], },
{ .rx = &iso_rx_qos[1], }, { .rx = &iso_rx_qos[1], },
}; };
static struct bt_iso_chan bis_iso_chan[BIS_ISO_CHAN_COUNT] = { static struct bt_iso_chan bis_iso_chan[] = {
{ .ops = &iso_ops, { .ops = &iso_ops,
.qos = &bis_iso_qos[0], }, .qos = &bis_iso_qos[0], },
{ .ops = &iso_ops, { .ops = &iso_ops,
.qos = &bis_iso_qos[1], }, .qos = &bis_iso_qos[1], },
}; };
static struct bt_iso_chan *bis[BIS_ISO_CHAN_COUNT] = { static struct bt_iso_chan *bis[] = {
&bis_iso_chan[0], &bis_iso_chan[0],
&bis_iso_chan[1], &bis_iso_chan[1],
}; };
@ -409,8 +409,14 @@ big_sync_create:
} }
printk("success.\n"); printk("success.\n");
printk("Waiting for BIG sync...\n"); for (uint8_t chan = 0U; chan < BIS_ISO_CHAN_COUNT; chan++) {
err = k_sem_take(&sem_big_sync, TIMEOUT_SYNC_CREATE); printk("Waiting for BIG sync chan %u...\n", chan);
err = k_sem_take(&sem_big_sync, TIMEOUT_SYNC_CREATE);
if (err) {
break;
}
printk("BIG sync chan %u successful.\n", chan);
}
if (err) { if (err) {
printk("failed (err %d)\n", err); printk("failed (err %d)\n", err);
@ -439,11 +445,14 @@ big_sync_create:
gpio_pin_set_dt(&led_gpio, (int)led_is_on); gpio_pin_set_dt(&led_gpio, (int)led_is_on);
#endif /* HAS_LED */ #endif /* HAS_LED */
printk("Waiting for BIG sync lost...\n"); for (uint8_t chan = 0U; chan < BIS_ISO_CHAN_COUNT; chan++) {
err = k_sem_take(&sem_big_sync_lost, K_FOREVER); printk("Waiting for BIG sync lost chan %u...\n", chan);
if (err) { err = k_sem_take(&sem_big_sync_lost, K_FOREVER);
printk("failed (err %d)\n", err); if (err) {
return; printk("failed (err %d)\n", err);
return;
}
printk("BIG sync lost chan %u.\n", chan);
} }
printk("BIG sync lost.\n"); printk("BIG sync lost.\n");