Samples: Bluetooth: CAP Initiator broadcast support

Add broadcast support to the CAP initiator sample.

This adds new sample-specific Kconfig options to help
select the right Kconfig options based on whether
unicast, broadcast or both is being used.

This also moves common TX functionality
to cap_initiator_tx to reuse the same TX thread
and functionality.

Finally there is a babblesim implemented for
the broadcast. There is not broadcast support for the
CAP acceptor sample yet, so this test only verifies that we
get the TX complete events from the controller.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-05-06 15:29:46 +02:00 committed by Fabio Baltieri
commit 1b83555d4c
16 changed files with 627 additions and 99 deletions

View file

@ -9,9 +9,12 @@ set(cap_initiator_path ${ZEPHYR_BASE}/samples/bluetooth/cap_initiator)
target_sources(app PRIVATE
${cap_initiator_path}/src/main.c
${cap_initiator_path}/src/cap_initiator_unicast.c
${cap_initiator_path}/src/cap_initiator_tx.c
)
zephyr_sources_ifdef(CONFIG_SAMPLE_UNICAST ${cap_initiator_path}/src/cap_initiator_unicast.c)
zephyr_sources_ifdef(CONFIG_SAMPLE_BROADCAST ${cap_initiator_path}/src/cap_initiator_broadcast.c)
target_sources(app PRIVATE
src/cap_initiator_sample_test.c
src/test_main.c

View file

@ -0,0 +1,4 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
source "${ZEPHYR_BASE}/samples/bluetooth/cap_initiator/Kconfig"

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/util_macro.h>
#include "bs_types.h"
#include "bs_tracing.h"
#include "bs_utils.h"
@ -42,16 +44,37 @@ static void test_cap_initiator_sample_tick(bs_time_t HW_device_time)
* we consider the test failed
*/
extern uint64_t total_rx_iso_packet_count;
if (IS_ENABLED(CONFIG_SAMPLE_UNICAST)) {
extern uint64_t total_rx_iso_packet_count;
extern uint64_t total_unicast_tx_iso_packet_count;
bs_trace_info_time(2, "%" PRIu64 " packets received, expected >= %i\n",
total_rx_iso_packet_count, PASS_THRESHOLD);
bs_trace_info_time(2, "%" PRIu64 " unicast packets received, expected >= %i\n",
total_rx_iso_packet_count, PASS_THRESHOLD);
bs_trace_info_time(2, "%" PRIu64 " unicast packets sent, expected >= %i\n",
total_unicast_tx_iso_packet_count, PASS_THRESHOLD);
if (total_rx_iso_packet_count >= PASS_THRESHOLD) {
PASS("cap_initiator PASSED\n");
} else {
FAIL("cap_initiator FAILED (Did not pass after %i seconds)\n", WAIT_TIME);
if (total_rx_iso_packet_count < PASS_THRESHOLD ||
total_unicast_tx_iso_packet_count < PASS_THRESHOLD) {
FAIL("cap_initiator FAILED with(Did not pass after %d seconds)\n ",
WAIT_TIME);
return;
}
}
if (IS_ENABLED(CONFIG_SAMPLE_BROADCAST)) {
extern uint64_t total_broadcast_tx_iso_packet_count;
bs_trace_info_time(2, "%" PRIu64 " broadcast packets sent, expected >= %i\n",
total_broadcast_tx_iso_packet_count, PASS_THRESHOLD);
if (total_broadcast_tx_iso_packet_count < PASS_THRESHOLD) {
FAIL("cap_initiator FAILED with (Did not pass after %d seconds)\n ",
WAIT_TIME);
return;
}
}
PASS("cap_initiator PASSED\n");
}
static const struct bst_test_instance test_sample[] = {

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# Simple selfchecking test for the CAP samples for broadcast.
# It relies on the bs_tests hooks to register a test timer callback, which after a deadline
# will check how many broadcast audio packets have been tranferred, and if over a threshold
# it considers the test passed
simulation_id="cap_broadcast_test"
verbosity_level=2
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_samples_cap_initiator_broadcast_prj_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 -testid=cap_initiator
# TODO: Add CAP acceptor
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \
-D=1 -sim_length=20e6 $@ -argschannel -at=40
wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails

View file

@ -2,7 +2,7 @@
# Copyright 2023-2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
# Simple selfchecking test for the CAP Acceptor sample.
# Simple selfchecking test for the CAP samples for unicast.
# It relies on the bs_tests hooks to register a test timer callback, which after a deadline
# will check how many audio packets the unicast client has received, and if over a threshold
# it considers the test passed
@ -14,7 +14,7 @@ source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
cd ${BSIM_OUT_PATH}/bin
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_samples_cap_initiator_prj_conf \
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_samples_cap_initiator_unicast_prj_conf \
-v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 -testid=cap_initiator
Execute ./bs_${BOARD_TS}_tests_bsim_bluetooth_audio_samples_cap_acceptor_prj_conf \

View file

@ -24,9 +24,15 @@ if [ "${BOARD_TS}" == "nrf5340bsim_nrf5340_cpuapp" ]; then
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/initiator \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_initiator \
cmake_extra_args="-DCONFIG_SAMPLE_UNICAST=n" \
conf_file=${sample}/prj.conf \
conf_overlay=${sample}/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf \
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
exe_name=bs_${BOARD_TS}_${app}_broadcast_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/initiator \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_initiator \
conf_file=${sample}/prj.conf \
conf_overlay=${sample}/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf \
exe_name=bs_${BOARD_TS}_${app}_unicast_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/acceptor \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_acceptor \
conf_file=${sample}/prj.conf \
@ -48,9 +54,15 @@ else
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/initiator \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_initiator \
cmake_extra_args="-DCONFIG_SAMPLE_UNICAST=n" \
conf_file=${sample}/prj.conf \
conf_overlay=${sample}/overlay-bt_ll_sw_split.conf \
exe_name=bs_${BOARD_TS}_${app}_prj_conf sysbuild=1 compile
exe_name=bs_${BOARD_TS}_${app}_broadcast_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/initiator \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_initiator \
conf_file=${sample}/prj.conf \
conf_overlay=${sample}/overlay-bt_ll_sw_split.conf \
exe_name=bs_${BOARD_TS}_${app}_unicast_prj_conf sysbuild=1 compile
app=tests/bsim/bluetooth/audio_samples/cap/acceptor \
sample=${ZEPHYR_BASE}/samples/bluetooth/cap_acceptor \
conf_file=${sample}/prj.conf \