Skip to content

Commit

Permalink
bluetooth: samples: Add sample showing basic channel sounding features
Browse files Browse the repository at this point in the history
This sample demonstrates how to use the CS test command.
It can be used to override randomization of certain parameters,
experiment with different CS configurations, and evaluate the RF medium.

A basic distance estimation method using phase rotations of the
unmodulated tones is included.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
  • Loading branch information
olivier-le-sage committed Oct 9, 2024
1 parent 029540a commit e2cf12c
Show file tree
Hide file tree
Showing 6 changed files with 701 additions and 0 deletions.
29 changes: 29 additions & 0 deletions include/zephyr/bluetooth/cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,35 @@ struct bt_le_cs_subevent_step {
const uint8_t *data;
};

/** Sign-extended IQ sample extracted from step data. */
struct bt_le_cs_iq_sample {
int16_t i;
int16_t q;
};

/** @brief Extract IQ sample from HCI-formatted PCT.
*
* Convenience function for processing 24-bit phase correction terms found
* in CS step data. The 12-bit signed real and imaginary components are
* converted to host endianness and sign-extended.
*
* @param pct 24-bit little-endian phase correction term.
*
* @return Real and imaginary terms as int16_t.
*/
static inline struct bt_le_cs_iq_sample bt_le_cs_parse_pct(const uint8_t pct[3])
{
uint32_t sample = sys_get_le24(pct);
int16_t i;
int16_t q;
struct {
int16_t x: 12;
} s;
i = s.x = sample & BT_HCI_LE_CS_PCT_MASK;
q = s.x = (sample >> 12) & BT_HCI_LE_CS_PCT_MASK;
return (struct bt_le_cs_iq_sample){.i = i, .q = q};
}

/** @brief Set all valid channel map bits
*
* This command is used to enable all valid channels in a
Expand Down
7 changes: 7 additions & 0 deletions samples/bluetooth/channel_sounding_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(channel_sounding_test)

target_sources(app PRIVATE src/main.c)
28 changes: 28 additions & 0 deletions samples/bluetooth/channel_sounding_test/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _bluetooth-channel-sounding-test-sample:

Bluetooth: Channel Sounding Testmode
####################################

Overview
********

This sample demonstrates how to use the CS test command.
It can be used to override randomization of certain channel sounding parameters,
experiment with different configurations, or evaluate the RF medium.

A basic distance estimation method using phase rotations of the
unmodulated tones is included.

Requirements
************

* A board with BLE support
* A controller that supports the Channel Sounding feature

Building and Running
********************

This sample can be found under :zephyr_file:`samples/bluetooth/channel_sounding_test` in
the Zephyr tree.

See :zephyr:code-sample-category:`bluetooth` samples for details.
23 changes: 23 additions & 0 deletions samples/bluetooth/channel_sounding_test/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CONFIG_CONSOLE=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_HANDLER=y
CONFIG_CONSOLE_GETCHAR=y

CONFIG_BT=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_CHANNEL_SOUNDING=y
CONFIG_BT_CHANNEL_SOUNDING_TEST=y
CONFIG_LOG=y

CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_L2CAP_TX_MTU=247

CONFIG_MAIN_STACK_SIZE=4096

CONFIG_LOG_BUFFER_SIZE=2048
CONFIG_CBPRINTF_FP_SUPPORT=y
11 changes: 11 additions & 0 deletions samples/bluetooth/channel_sounding_test/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sample:
name: Bluetooth Channel Sounding Test
tests:
sample.bluetooth.channel_sounding_test:
harness: bluetooth
platform_allow:
- qemu_cortex_m3
- qemu_x86
tags: bluetooth
integration_platforms:
- qemu_cortex_m3
Loading

0 comments on commit e2cf12c

Please sign in to comment.