Bluetooth: Audio: Increase PA sync timeouts

Increase the timeouts to be 60 instead of 6.
The reason for this is that some controllers (like the Zephyr
controller) will reserve some of these to ensure stability,
and in fact with skip = 5 and retry = 6, it would still
send the PA reports at every interval.

To accomodate a higher timeout value, the functions used to
convert PA intervals to PA timeouts have been updated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-03-12 16:12:07 +01:00 committed by Carles Cufí
commit 0dcf3c197e
15 changed files with 55 additions and 78 deletions

View file

@ -652,15 +652,15 @@ static uint16_t interval_to_sync_timeout(uint16_t pa_interval)
/* Use maximum value to maximize chance of success */
pa_timeout = BT_GAP_PER_ADV_MAX_TIMEOUT;
} else {
/* Ensure that the following calculation does not overflow silently */
__ASSERT(SYNC_RETRY_COUNT < 10, "SYNC_RETRY_COUNT shall be less than 10");
uint32_t interval_ms;
uint32_t timeout;
/* Add retries and convert to unit in 10's of ms */
pa_timeout = ((uint32_t)pa_interval * SYNC_RETRY_COUNT) / 10;
interval_ms = BT_GAP_PER_ADV_INTERVAL_TO_MS(pa_interval);
timeout = (interval_ms * PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO) / 10;
/* Enforce restraints */
pa_timeout =
CLAMP(pa_timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
pa_timeout = CLAMP(timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
}
return pa_timeout;

View file

@ -14,7 +14,7 @@
extern enum bst_result_t bst_result;
#define SYNC_RETRY_COUNT 6 /* similar to retries for connections */
#define PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO 20 /* Set the timeout relative to interval */
#define PA_SYNC_SKIP 5
CREATE_FLAG(flag_pa_synced);
@ -99,16 +99,15 @@ static uint16_t interval_to_sync_timeout(uint16_t pa_interval)
/* Use maximum value to maximize chance of success */
pa_timeout = BT_GAP_PER_ADV_MAX_TIMEOUT;
} else {
/* Ensure that the following calculation does not overflow silently */
__ASSERT(SYNC_RETRY_COUNT < 10,
"SYNC_RETRY_COUNT shall be less than 10");
uint32_t interval_ms;
uint32_t timeout;
/* Add retries and convert to unit in 10's of ms */
pa_timeout = ((uint32_t)pa_interval * SYNC_RETRY_COUNT) / 10;
interval_ms = BT_GAP_PER_ADV_INTERVAL_TO_MS(pa_interval);
timeout = (interval_ms * PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO) / 10;
/* Enforce restraints */
pa_timeout = CLAMP(pa_timeout, BT_GAP_PER_ADV_MIN_TIMEOUT,
BT_GAP_PER_ADV_MAX_TIMEOUT);
pa_timeout = CLAMP(timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
}
return pa_timeout;

View file

@ -758,15 +758,15 @@ static uint16_t interval_to_sync_timeout(uint16_t pa_interval)
/* Use maximum value to maximize chance of success */
pa_timeout = BT_GAP_PER_ADV_MAX_TIMEOUT;
} else {
/* Ensure that the following calculation does not overflow silently */
__ASSERT(SYNC_RETRY_COUNT < 10, "SYNC_RETRY_COUNT shall be less than 10");
uint32_t interval_ms;
uint32_t timeout;
/* Add retries and convert to unit in 10's of ms */
pa_timeout = ((uint32_t)pa_interval * SYNC_RETRY_COUNT) / 10;
interval_ms = BT_GAP_PER_ADV_INTERVAL_TO_MS(pa_interval);
timeout = (interval_ms * PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO) / 10;
/* Enforce restraints */
pa_timeout =
CLAMP(pa_timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
pa_timeout = CLAMP(timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
}
return pa_timeout;

View file

@ -102,7 +102,7 @@ static const uint8_t mock_iso_data[] = {
#define AD_SIZE 1
#define INVALID_BROADCAST_ID (BT_AUDIO_BROADCAST_ID_MAX + 1)
#define SYNC_RETRY_COUNT 6 /* similar to retries for connections */
#define PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO 20 /* Set the timeout relative to interval */
#define PA_SYNC_SKIP 5
#define PBP_STREAMS_TO_SEND 2

View file

@ -19,8 +19,6 @@
#include "common.h"
#define SEM_TIMEOUT K_SECONDS(1.5)
#define PA_SYNC_SKIP 5
#define SYNC_RETRY_COUNT 6 /* similar to retries for connections */
extern enum bst_result_t bst_result;
@ -105,20 +103,16 @@ static void recv_cb(struct bt_bap_stream *stream,
static uint16_t interval_to_sync_timeout(uint16_t interval)
{
uint32_t interval_ms;
uint16_t timeout;
/* Ensure that the following calculation does not overflow silently */
__ASSERT(SYNC_RETRY_COUNT < 10, "SYNC_RETRY_COUNT shall be less than 10");
uint32_t timeout;
/* Add retries and convert to unit in 10's of ms */
interval_ms = BT_GAP_PER_ADV_INTERVAL_TO_MS(interval);
timeout = (interval_ms * SYNC_RETRY_COUNT) / 10;
timeout = (interval_ms * PA_SYNC_INTERVAL_TO_TIMEOUT_RATIO) / 10;
/* Enforce restraints */
timeout = CLAMP(timeout, BT_GAP_PER_ADV_MIN_TIMEOUT,
BT_GAP_PER_ADV_MAX_TIMEOUT);
timeout = CLAMP(timeout, BT_GAP_PER_ADV_MIN_TIMEOUT, BT_GAP_PER_ADV_MAX_TIMEOUT);
return timeout;
return (uint16_t)timeout;
}
static bool pa_decode_base(struct bt_data *data, void *user_data)

View file

@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0
VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=20
EXECUTE_TIMEOUT=50
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

View file

@ -6,7 +6,7 @@
SIMULATION_ID="bap_broadcast_audio_assistant"
VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=20
EXECUTE_TIMEOUT=50
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source

View file

@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0
VERBOSITY_LEVEL=2
EXECUTE_TIMEOUT=20
EXECUTE_TIMEOUT=50
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source