Skip to content

Commit e135588

Browse files
eriksandgrenkartben
authored andcommitted
samples: Bluetooth: Update params in connected CS sample
This change is made to fix the currently broken CS samples, to prevent them from just printing error messages like: `Channel sounding not enough memory to store step data (530 > 512)`. This change updates the CS config and procedure parameters. The intention with the updated parameter selection is to use parameters that result in: - CS procedures with only a single CS subevent per procedure. This is required because the samples are not designed to support > 1 subevent per procedure and the samples will break down if > 1 subevent per procedure is generated. - A limited number of CS steps per procedure. This is achieved by setting `.channel_map_repetition = 1` and only enabling a limited set of channels in the channel map. This is required because the samples are designed to transfer all of the step data from one procedure, from the reflector to the initiator, using a single GATT write operation which is limited to 512 bytes. Signed-off-by: Erik Sandgren <erik.sandgren@nordicsemi.no>
1 parent c6f3134 commit e135588

File tree

1 file changed

+52
-21
lines changed

1 file changed

+52
-21
lines changed

samples/bluetooth/channel_sounding/src/connected_cs_initiator.c

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,47 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
241241
}
242242
}
243243

244+
struct bt_le_cs_create_config_params get_cs_config_params(void)
245+
{
246+
/* Create config parameters that result in a limited number of CS steps per CS procedure.
247+
* This is achieved by setting channel_map_repetition = 1 and only enabling a limited set
248+
* of channels in the channel_map. This is required due to a limitation in the sample:
249+
* The reflector uses a single GATT write operation to transfer all of the step data
250+
* from one CS procedure to the initiator. This limits the amount of CS step data per
251+
* CS procedure that will allow the sample to function to 512 bytes.
252+
* This method for limiting the amount of CS steps per CS procedure is chosen because it
253+
* will result in the same number of CS steps regardless of controller capabilities.
254+
* Other possible methods such as limiting the max_procedure_len in the procedure params
255+
* would yield different number of CS steps per CS procedure depending on the
256+
* timing parameters supported by the local and peer controller.
257+
*/
258+
struct bt_le_cs_create_config_params config_params = {
259+
.id = CS_CONFIG_ID,
260+
.mode = BT_CONN_LE_CS_MAIN_MODE_2_SUB_MODE_1,
261+
.min_main_mode_steps = 2,
262+
.max_main_mode_steps = 10,
263+
.main_mode_repetition = 0,
264+
.mode_0_steps = NUM_MODE_0_STEPS,
265+
.role = BT_CONN_LE_CS_ROLE_INITIATOR,
266+
.rtt_type = BT_CONN_LE_CS_RTT_TYPE_AA_ONLY,
267+
.cs_sync_phy = BT_CONN_LE_CS_SYNC_1M_PHY,
268+
.channel_map_repetition = 1,
269+
.channel_selection_type = BT_CONN_LE_CS_CHSEL_TYPE_3B,
270+
.ch3c_shape = BT_CONN_LE_CS_CH3C_SHAPE_HAT,
271+
.ch3c_jump = 2,
272+
};
273+
274+
memset(config_params.channel_map, 0, 10);
275+
/* Enable 32 consecutive CS channels.
276+
* Start at i = 26 since channels 23, 24 and 25 are disallowed by spec.
277+
*/
278+
for (uint8_t i = 26; i < 62; i++) {
279+
BT_LE_CS_CHANNEL_BIT_SET_VAL(config_params.channel_map, i, 1);
280+
}
281+
282+
return config_params;
283+
}
284+
244285
BT_CONN_CB_DEFINE(conn_cb) = {
245286
.connected = connected_cb,
246287
.disconnected = disconnected_cb,
@@ -307,26 +348,11 @@ int main(void)
307348

308349
k_sem_take(&sem_remote_capabilities_obtained, K_FOREVER);
309350

310-
struct bt_le_cs_create_config_params config_params = {
311-
.id = CS_CONFIG_ID,
312-
.mode = BT_CONN_LE_CS_MAIN_MODE_2_SUB_MODE_1,
313-
.min_main_mode_steps = 2,
314-
.max_main_mode_steps = 10,
315-
.main_mode_repetition = 0,
316-
.mode_0_steps = NUM_MODE_0_STEPS,
317-
.role = BT_CONN_LE_CS_ROLE_INITIATOR,
318-
.rtt_type = BT_CONN_LE_CS_RTT_TYPE_AA_ONLY,
319-
.cs_sync_phy = BT_CONN_LE_CS_SYNC_1M_PHY,
320-
.channel_map_repetition = 1,
321-
.channel_selection_type = BT_CONN_LE_CS_CHSEL_TYPE_3B,
322-
.ch3c_shape = BT_CONN_LE_CS_CH3C_SHAPE_HAT,
323-
.ch3c_jump = 2,
324-
};
325-
326-
bt_le_cs_set_valid_chmap_bits(config_params.channel_map);
351+
struct bt_le_cs_create_config_params config_params = get_cs_config_params();
327352

328353
err = bt_le_cs_create_config(connection, &config_params,
329354
BT_LE_CS_CREATE_CONFIG_CONTEXT_LOCAL_AND_REMOTE);
355+
330356
if (err) {
331357
printk("Failed to create CS config (err %d)\n", err);
332358
return 0;
@@ -341,15 +367,20 @@ int main(void)
341367
}
342368

343369
k_sem_take(&sem_cs_security_enabled, K_FOREVER);
344-
345370
const struct bt_le_cs_set_procedure_parameters_param procedure_params = {
346371
.config_id = CS_CONFIG_ID,
347-
.max_procedure_len = 12,
372+
.max_procedure_len = 0xffff,
348373
.min_procedure_interval = 100,
349374
.max_procedure_interval = 100,
350375
.max_procedure_count = 0,
351-
.min_subevent_len = 6750,
352-
.max_subevent_len = 6750,
376+
/* Use a relatively large subevent_len to make sure the CS procedure
377+
* will terminate due to running out of unused channels in the channel map
378+
* (and channel map repetitions) in the first CS subevent of the CS procedure.
379+
* This will limit the number of CS subevents per CS procedure to 1, which is
380+
* required by the design of the sample.
381+
*/
382+
.min_subevent_len = 50000,
383+
.max_subevent_len = 50000,
353384
.tone_antenna_config_selection = BT_LE_CS_TONE_ANTENNA_CONFIGURATION_A1_B1,
354385
.phy = BT_LE_CS_PROCEDURE_PHY_1M,
355386
.tx_power_delta = 0x80,

0 commit comments

Comments
 (0)