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

Revert "Bluetooth: Audio: Use generic count_bits to count bits"

This reverts commit ee335399.

Signed-off-by: default avatarEmil Gydesen <emil.gydesen@nordicsemi.no>
parent fadaae42
Loading
Loading
Loading
Loading
+2 −3
Changes for samples/bluetooth/cap_acceptor/src/cap_acceptor_broadcast.c: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
/** @file
 *  @brief Bluetooth Common Audio Profile (CAP) Acceptor broadcast.
 *
 *  Copyright (c) 2024-2025 Nordic Semiconductor ASA
 *  Copyright (c) 2024 Nordic Semiconductor ASA
 *
 *  SPDX-License-Identifier: Apache-2.0
 */
@@ -459,8 +459,7 @@ static int bis_sync_req_cb(struct bt_conn *conn,

	LOG_INF("BIS sync request received for %p: 0x%08x", recv_state, bis_sync_req[0]);

	if (new_bis_sync_req != BT_BAP_BIS_SYNC_NO_PREF &&
	    count_bits(&new_bis_sync_req, sizeof(new_bis_sync_req)) > 1U) {
	if (new_bis_sync_req != BT_BAP_BIS_SYNC_NO_PREF && POPCOUNT(new_bis_sync_req) > 1U) {
		LOG_WRN("Rejecting BIS sync request for 0x%08X as we do not support that",
			new_bis_sync_req);

+12 −3
Changes for subsys/bluetooth/audio/audio.c: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

/*
 * Copyright (c) 2022 Codecoup
 * Copyright (c) 2025 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */
@@ -24,7 +23,6 @@
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/check.h>
#include <zephyr/sys/util.h>
#include <zephyr/toolchain.h>

#include "audio_internal.h"
@@ -148,7 +146,18 @@ uint8_t bt_audio_get_chan_count(enum bt_audio_location chan_allocation)
		return 1;
	}

	return count_bits(&chan_allocation, sizeof(chan_allocation));
#ifdef POPCOUNT
	return POPCOUNT(chan_allocation);
#else
	uint8_t cnt = 0U;

	while (chan_allocation != 0U) {
		cnt += chan_allocation & 1U;
		chan_allocation >>= 1U;
	}

	return cnt;
#endif
}

static bool valid_ltv_cb(struct bt_data *data, void *user_data)
+17 −1
Changes for subsys/bluetooth/audio/bap_broadcast_sink.c: 17 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1071,6 +1071,22 @@ int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t br
	return 0;
}

static uint8_t bit_count(uint32_t bitfield)
{
#ifdef POPCOUNT
	return POPCOUNT(bitfield);
#else
	uint8_t cnt = 0U;

	while (bitfield != 0U) {
		cnt += bitfield & 1U;
		bitfield >>= 1U;
	}

	return cnt;
#endif
}

struct sync_base_info_data {
	struct bt_audio_codec_cfg codec_cfgs[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
	struct bt_audio_codec_cfg *subgroup_codec_cfg;
@@ -1255,7 +1271,7 @@ int bt_bap_broadcast_sink_sync(struct bt_bap_broadcast_sink *sink, uint32_t inde
	}

	/* Validate that number of bits set is within supported range */
	bis_count = count_bits(&indexes_bitfield, sizeof(indexes_bitfield));
	bis_count = bit_count(indexes_bitfield);
	if (bis_count > CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT) {
		LOG_DBG("Cannot sync to more than %d streams (%u was requested)",
			CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT, bis_count);
+1 −1
Changes for tests/bsim/bluetooth/audio/src/bap_broadcast_sink_test.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -801,7 +801,7 @@ static void test_broadcast_sync(const uint8_t broadcast_code[BT_ISO_BROADCAST_CO
		return;
	}

	stream_sync_cnt = count_bits(&bis_index_bitfield, sizeof(bis_index_bitfield));
	stream_sync_cnt = POPCOUNT(bis_index_bitfield);
}

static void test_broadcast_sync_inval(void)